Aztec 백서

Aztec

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 68쪽

nce(contract_address); assert_contract_was_initialized_by( block_header, contract_address, + instance.initialization_hash, ); ``` ### Two separate init nullifiers for private and public[​](#two-separate-init-nullifiers-for-private-and-public "Direct link to Two separate init nullifiers for private and public") Contract initialization now emits two separate nullifiers instead of one: a **private init nullifier** and a **public init nullifier**. Each nullifier gates its respective execution domain: * Private external functions check the private init nullifier. * Public external functions check the public init nullifier. **How initializers work:** * **Private initializers** emit the private init nullifier. If the contract has any external public functions, the protocol auto-enqueues a public call to emit the public init nullifier. * **Public initializers** emit both nullifiers directly. * Contracts with no public functions only emit the private init nullifier. **`only_self` functions no longer have init checks.** They behave as if marked `noinitcheck`. **External functions called during private initialization must be `#[only_self]`.** Init nullifiers are emitted at the end of the initializer, so any external functions called on the initializing contract (e.g. via `enqueue_self` or `call_self`) during initialization will fail the init check unless they skip it. **Breaking change for deployment:** If your contract has external public functions and a private initializer, the class must be registered onchain before initialization. You can no longer pass `skipClassPublication: true`, because the auto-enqueued public call requires the class to be available. ``` const deployed = await MyContract.deploy(wallet, ...args).send({ - skipClassPublication: true, }).deployed(); ``` ### \[Aztec.nr] Made `compute_note_hash_for_nullification` unconstrained[​](#aztecnr-made-compute_note_hash_for_nullification-unconstrained "Direct link to aztecnr-made-compute_note_hash_for_nullification-unconstrained") This function shouldn't have been constrained in the first place, as constrained computation of `HintedNote` nullifiers is dangerous (constrained computation of nullifiers can be performed only on the `ConfirmedNote` type). If you were calling this from a constrained function, consider using `compute_confirmed_note_hash_for_nullification` instead. Unconstrained usage is safe. ### \[Aztec.nr] Changes to standard note hash computation[​](#aztecnr-changes-to-standard-note-hash-computation "Direct link to \[Aztec.nr] Changes to standard note hash computation") Note hashes used to be computed with the storage slot being the last value of the preimage, it is now the first. This is to make it easier to ensure all note hashes have proper domain separation. This change requires no input from your side unless you were testing or relying on hardcoded note hashes. ## 4.1.3[​](#413 "Direct link to 4.1.3") ### \[Aztec.js] `TxReceipt` now includes `epochNumber`[​](#aztecjs-txreceipt-now-includes-epochnumber "Direct link to aztecjs-txreceipt-now-includes-epochnumber") `TxReceipt` now includes an `epochNumber` field that indicates which epoch the transaction was included in. ### \[Aztec.js] Use `getL2ToL1MembershipWitness` for L2-to-L1 message witnesses[​](#aztecjs-use-getl2tol1membershipwitness-for-l2-to-l1-message-witnesses "Direct link to aztecjs-use-getl2tol1membershipwitness-for-l2-to-l1-message-witnesses") The node now computes L2-to-L1 membership witnesses directly, resolving the epoch and Outbox root internally from the transaction hash. Use `getL2ToL1MembershipWitness` instead of fetching raw epoch messages and computing the witness client-side. **Migration:** ``` - const messages = await aztecNode.getL2ToL1Messages(epochNumber); - // compute the witness client-side from the epoch messages + const witness = await aztecNode.getL2ToL1MembershipWitness(txHash, messageHash); + const epoch = witness.epochNumber; ``` The return type `L2ToL1MembershipWitness` includes `epochNumber`. An optional `messageIndexInTx` parameter can be passed as the third argument to disambiguate when a transaction emits multiple identical L2-to-L1 messages. **Impact**: Call sites that compute L2-to-L1 membership witnesses should use the node method and extract `epochNumber` from the result. ### \[Aztec.js] `getPublicEvents` now returns an object instead of an array[​](#aztecjs-getpublicevents-now-returns-an-object-instead-of-an-array "Direct link to aztecjs-getpublicevents-now-returns-an-object-instead-of-an-array") `getPublicEvents` now returns a `GetPublicEventsResult<T>` object with `events` and `maxLogsHit` fields instead of a plain array. This enables pagination through large result sets using the new `afterLog` filter option. ``` - const events = await getPublicEvents<MyEvent>(node, MyContract.events.MyEvent, filter); + const { events } = await getPublicEvents<MyEvent>(node, MyContract.events.MyEvent, filter); ``` The `maxLogsHit` flag indicates whether the log limit was reached, meaning more results may be available. You can use `afterLog` in the filter to fetch the next page. ### \[Aztec.nr] Removed `get_random_bytes`[​](#aztecnr-removed-get_random_bytes "Direct link to aztecnr-removed-get_random_bytes") The `get_random_bytes` unconstrained function has been removed from `aztec::utils::random`. If you were using it, you can replace it with direct calls to the `random` oracle from `aztec::oracle::random` and convert to bytes yourself. ## 4.1.0-rc.2[​](#410-rc2 "Direct link to 4.1.0-rc.2") ### \[Aztec.js] `simulate()`, `send()`, and deploy return types changed to always return objects[​](#aztecjs-simulate-send-and-deploy-return-types-changed-to-always-return-objects "Direct link to aztecjs-simulate-send-and-deploy-return-types-changed-to-always-return-objects") All SDK interaction methods now return structured objects that include offchain output alongside the primary result. This affects `.simulate()`, `.send()`, deploy `.send()`, and `Wallet.sendTx()`. **Impact**: Every call site that uses `.simulate()`, `.send()`, or deploy must destructure the result. This is a mechanical transformation. Custom wallet implementations must update `sendTx()` to return the new object shapes, using `extractOffchainOutput` to decode offchain messages from raw effects. The offchain output includes two fields: * `offchainEffects` — raw offchain effects emitted during execution, other than `offchainMessages` * `offchainMessages` — decoded messages intended for specific recipients We are making this change now so in the future we can add more fields to the responses of this APIs without breaking backwards compatibility, so this won't ever happen again. **`simulate()` — always returns `{ result, offchainEffects, offchainMessages }` object:** ``` - const value = await contract.methods.foo(args).simulate({ from: sender }); + const { result: value } = await contract.methods.foo(args).simulate({ from: sender }); ``` When using `includeMetadata` or `fee.estimateGas`, `stats` and `estimatedGas` are also available as optional fields on the same object: ``` - const { stats, estimatedGas } = await contract.methods.foo(args).simulate({ + const sim = await contract.methods.foo(args).simulate({ from: sender, includeMetadata: true, }); + const stats = sim.stats!; + const estimatedGas = sim.estimatedGas!; ``` `SimulationReturn` is no longer a generic conditional type — it's a single flat type with optional `stats` and `estimatedGas` fields. **`send()` — returns `{ receipt, offchainEffects, offchainMessages }` object:** ``` - const receipt = await contract.methods.foo(args).send({ from: sender }); + const { receipt } = await contract.methods.foo(args).send({ from: sender }); ``` When using `NO_WAIT`, returns `{ txHash, offchainEffects, offchainMessages }` instead of a bare `TxHash`: ``` - const txHash = await contract.methods.foo(args).send({ from: sender, wait: NO_WAIT }); + const { txHash } = await contract.methods.foo(args).send({ from: sender, wait: NO_WAIT }); ``` Offchain messages emitted by the transaction are available on the result: ``` const { receipt, offchainMessages } = await contract.methods .foo(args) .send({ from: sender }); for (const msg of offchainMessages) { console.log( `Message for ${msg.recipient} from contract ${msg.contractAddress}:`, msg.payload, ); } ``` **Deploy — returns `{ contract, receipt, offchainEffects, offchainMessages }` object:** ``` - const myContract = await MyContract.deploy(wallet, ...args).send({ from: sender }); + const { contract: myContract } = await MyContract.deploy(wallet, ...args).send({ from: sender }); ``` The deploy receipt is also available via `receipt` if needed (e.g. for `receipt.txHash` or `receipt.transactionFee`). **Custom wallet implementations — `sendTx()` must return objects:** If you implement the `Wallet` interface (or extend `BaseWallet`), the `sendTx()` method must now return objects that include offchain output. Use `extractOffchainOutput` to split raw effects into decoded messages and remaining effects: ``` + import { extractOffchainOutput } from '@aztec/aztec.js/contracts'; async sendTx(executionPayload, opts) { const provenTx = await this.pxe.proveTx(...); + const offchainOutput = extractOffchainOutput(provenTx.getOffchainEffects()); const tx = await provenTx.toTx(); const txHash = tx.getTxHash(); await this.aztecNode.sendTx(tx); if (opts.wait === NO_WAIT) { - return txHash; + return { txHash, ...offchainOutput }; } const receipt = await waitForTx(this.aztecNode, txHash, opts.wait); - return receipt; + return { receipt, ...offchainOutput }; } ``` ### Scope enforcement for private state access (TXE and PXE)[​](#scope-enforcement-for-private-state-access-txe-and-pxe "Direct link to Scope enforcement for private state access (TXE and PXE)") Scope enforcement is now active across both TXE (test environment) and PXE (client). Previously, private execution could implicitly access any account's keys and notes. Now, only the caller (`from`) address is in scope by default, and accessing another address's private state requires explicitly granting scope. #### Noir developers (TXE)[​](#noir-developers-txe "Direct link to Noir developers (TXE)") TXE now enforces scope isolation, matching PXE behavior. During private execution, only the caller's keys and notes are accessible. If a Noir test accesses private state of an address other than `from`, it will fail. When `from` is the zero address, scopes are empty (deny-all). If your TXE tests fail with key or note access errors, ensure the test is calling from the correct address, or restructure the test to match the expected access pattern. #### Aztec.js developers (PXE/Wallet)[​](#aztecjs-developers-pxewallet "Direct link to Aztec.js developers (PXE/Wallet)") The wallet now passes scopes to PXE, and only the `from` address is in scope by default. Auto-expansion of scopes for nested calls to registered accounts has been removed. A new `additionalScopes` option is available on `send()`, `simulate()`, and `deploy()` for cases where private execution needs access to another address's keys or notes. **When do you need `additionalScopes`?** 1. **Deploying contracts whose constructor initializes private storage** (e.g., account contracts, or any contract using `SinglePrivateImmutable`/`SinglePrivateMutable` in the constructor). The contract's own address must be in scope so its nullifier key is accessible during initialization. 2. **Operations that access another contract's private state** (e.g., withdrawing from an escrow contract that nullifies the contract's own token notes). ```` **Example: deploying a contract with private storage (e.g., `PrivateToken`)** ```diff const tokenDeployment = PrivateTokenContract.deployWithPublicKeys( tokenPublicKeys, wallet, initialBalance, sender, ); const tokenInstance = await tokenDeployment.getInstance(); await wallet.registerContract(tokenInstance, PrivateTokenContract.artifact, tokenSecretKey); const token = await tokenDeployment.send({ from: sender, + additionalScopes: [tokenInstance.address], }); ```` **Example: withdrawing from an escrow contract** ``` await escrowContract.methods .withdraw(token.address, amount, recipient) - .send({ from: owner }); + .send({ from: owner, additionalScopes: [escrowContract.address] }); ``` ### `simulateUtility` renamed to `executeUtility`[​](#simulateutility-renamed-to-executeutility "Direct link to simulateutility-renamed-to-executeutility") The `simulateUtility` method and related types have been renamed to `executeUtility` across the entire stack to better reflect that utility functions are executed, not simulated. **TypeScript:** ``` - import { SimulateUtilityOptions, UtilitySimulationResult } from '@aztec/aztec.js'; + import { ExecuteUtilityOptions, UtilityExecutionResult } from '@aztec/aztec.js'; - const result: UtilitySimulationResult = await wallet.simulateUtility(functionCall, opts); + const result: UtilityExecutionResult = await wallet.executeUtility(functionCall, opts); ``` **Noir (test environment):** ``` - let result = env.simulate_utility(my_contract_address, selector); + let result = env.execute_utility(my_contract_address, selector); ``` ## 4.0.0-devnet.2-patch.0[​](#400-devnet2-patch0 "Direct link to 4.0.0-devnet.2-patch.0") ### \[Protocol] `include_by_timestamp` renamed to `expiration_timestamp`[​](#protocol-include_by_timestamp-renamed-to-expiration_timestamp "Direct link to protocol-include_by_timestamp-renamed-to-expiration_timestamp") The `include_by_timestamp` field has been renamed to `expiration_timestamp` across the protocol to better convey its meaning. **Noir:** ``` - context.set_tx_include_by_timestamp(123456789); + context.set_expiration_timestamp(123456789); ``` ### \[CLI] Dockerless CLI Installation[​](#cli-dockerless-cli-installation "Direct link to \[CLI] Dockerless CLI Installation") The Aztec CLI is now installed without Docker. The installation command has changed: **Old installation (deprecated):** ``` bash -i <(curl -sL https://install.aztec.network) aztec-up <version> ``` **New installation:** ``` VERSION=<version> bash -i <(curl -sL https://install.aztec.network/<version>) ``` For example, to install version `6.0.0-rc.1`: ``` VERSION=6.0.0-rc.1 bash -i <(curl -sL https://install.aztec.network/6.0.0-rc.1) ``` **Key changes:** * Docker is no longer required to run the Aztec CLI tools * The `VERSION` environment variable must be set in the installation command * The version must also be included in the URL path **aztec-up is now a version manager:** After installation, `aztec-up` functions as a version manager with the following commands: | Command | Description | | ---------------------------- | ------------------------------------------- | | `aztec-up install <version>` | Install a specific version and switch to it | | `aztec-up use <version>` | Switch to an already installed version | | `aztec-up list` | List all installed versions | | `aztec-up self-update` | Update aztec-up itself | ### `@aztec/test-wallet` replaced by `@aztec/wallets`[​](#aztectest-wallet-replaced-by-aztecwallets "Direct link to aztectest-wallet-replaced-by-aztecwallets") The `@aztec/test-wallet` package has been removed. Use `@aztec/wallets` instead, which provides `EmbeddedWallet` with a `static create()` factory: ``` - import { TestWallet, registerInitialLocalNetworkAccountsInWallet } from '@aztec/test-wallet/server'; + import { EmbeddedWallet } from '@aztec/wallets/embedded'; + import { registerInitialLocalNetworkAccountsInWallet } from '@aztec/wallets/testing'; - const wallet = await TestWallet.create(node); + const wallet = await EmbeddedWallet.create(node); ``` For browser environments, the same import resolves to a browser-specific implementation automatically via conditional exports<!-- -->:X The `EmbeddedWallet.create()` factory accepts an optional second argument for logger injection and ephemeral storage: ``` const wallet = await EmbeddedWallet.create(node, { logger: myLogger, // custom logger; child loggers derived via createChild() ephemeral: true, // use in-memory stores (no persistence) }); ``` ### \[Aztec.nr] `debug_log` module renamed to `logging`[​](#aztecnr-debug_log-module-renamed-to-logging "Direct link to aztecnr-debug_log-module-renamed-to-logging") The `debug_log` module has been renamed to `logging` to avoid naming collisions with per-level logging functions that were introduced in this PR (`warn_log`, `info_log`, `debug_log`... and the "format" versions `warn_log_format`, `debug_log_format`). Update all import paths accordingly: ``` - use aztec::oracle::debug_log::debug_log; - use aztec::oracle::debug_log::debug_log_format; + use aztec::oracle::logging::debug_log; + use aztec::oracle::logging::debug_log_format; ``` For inline paths: ``` - aztec::oracle::debug_log::debug_log_format("msg: {}", [value]); + aztec::oracle::logging::debug_log_format("msg: {}", [value]); ``` The function names themselves (`debug_log`, `debug_log_format`, `debug_log_with_level`, `debug_log_format_with_level`) are unchanged. Additionally, `debug_log_format_slice` has been removed. Use `debug_log_format` instead, which accepts a fixed-size array of fields: ``` - debug_log_format_slice("values: {}", &[value1, value2]); + debug_log_format("values: {}", [value1, value2]); ``` This has been done as usage of Noir slices is discouraged and the function was unused in the aztec codebase. ### \[AztecNode] Sentinel validator status values renamed[​](#aztecnode-sentinel-validator-status-values-renamed "Direct link to \[AztecNode] Sentinel validator status values renamed") The `ValidatorStatusInSlot` values returned by `getValidatorsStats` and `getValidatorStats` have been updated to reflect the multi-block-per-slot model, where blocks and checkpoints are distinct concepts: ``` - 'block-mined' + 'checkpoint-mined' - 'block-proposed' + 'checkpoint-proposed' - 'block-missed' + 'checkpoint-missed' // blocks were proposed but checkpoint was not attested + 'blocks-missed' // no block proposals were sent at all ``` The `attestation-sent` and `attestation-missed` values are unchanged but now explicitly refer to checkpoint attestations. The `ValidatorStatusType` used for categorizing statuses has also changed from `'block' | 'attestation'` to `'proposer' | 'attestation'`. ### \[aztec.js] `getDecodedPublicEvents` renamed to `getPublicEvents` with new signature[​](#aztecjs-getdecodedpublicevents-renamed-to-getpublicevents-with-new-signature "Direct link to aztecjs-getdecodedpublicevents-renamed-to-getpublicevents-with-new-signature") The `getDecodedPublicEvents` function has been renamed to `getPublicEvents` and now uses a filter object instead of positional parameters: ``` - import { getDecodedPublicEvents } from '@aztec/aztec.js/events'; + import { getPublicEvents } from '@aztec/aztec.js/events'; - const events = await getDecodedPublicEvents(node, eventMetadata, fromBlock, limit); + const events = await getPublicEvents(node, eventMetadata, { + fromBlock, + toBlock, + contractAddress, // optional + txHash, // optional + }); ``` The new function returns richer metadata including `contractAddress`, `txHash`, `l2BlockNumber`, and `l2BlockHash` for each event: ``` import { getPublicEvents } from "@aztec/aztec.js/events"; import { MyContract } from "./artifacts/MyContract.js"; // Query events from a contract const events = await getPublicEvents<{ amount: bigint; sender: AztecAddress }>( aztecNode, MyContract.events.Transfer, { contractAddress: myContractAddress, fromBlock: BlockNumber(1) }, ); // Each event includes decoded data and metadata for (const { event, metadata } of events) { console.log(`Transfer of ${event.amount} from ${event.sender}`); console.log(` Block: ${metadata.l2BlockNumber}, Tx
프로젝트로 돌아가기