Aztec 백서

Aztec

원문

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

opics/transactions.md) - How private kernel fits into transaction execution * [Public Execution](/developers/testnet/docs/foundational-topics/advanced/circuits/public_execution.md) - How public functions are executed by the AVM * [Profiling Transactions](/developers/testnet/docs/aztec-nr/framework-description/advanced/how_to_profile_transactions.md) - Measuring gate counts and identifying bottlenecks * [Writing Efficient Contracts](/developers/testnet/docs/aztec-nr/framework-description/advanced/writing_efficient_contracts.md) - Optimization strategies --- # Public Execution (AVM) Public function execution in Aztec is handled by the **Aztec Virtual Machine (AVM)**. Unlike private execution (which runs on user devices), public execution runs on the sequencer's infrastructure where access to current state is required. note Unlike the private kernel which runs recursively for each private call, **there is no "public kernel" circuit**. The AVM executes all public functions for a transaction in a single proof. The term "public kernel" is sometimes used colloquially to refer to the AVM's role in public execution. ## Overview[​](#overview "Direct link to Overview") The AVM processes public call requests that were queued during private execution. It operates on the current state of the public data tree, note hash tree, and nullifier tree—state that only the sequencer knows at execution time. For transactions containing public functions, the execution flow is: 1. **Private Kernel** - Processes private functions, queues public call requests 2. **Hiding Kernel** - Bridges private output to public phase 3. **AVM** - Executes all public functions, produces accumulated data 4. **Rollup Circuits** - Validates proofs and includes in block ## Supported Cryptographic Operations[​](#supported-cryptographic-operations "Direct link to Supported Cryptographic Operations") The AVM supports Poseidon2, Pedersen, SHA-256, Keccak, and Grumpkin curve operations (embedded curve add, multi-scalar multiplication). ECDSA signature verification, AES-128, Blake2s, and Blake3 are not available in public functions. warning If your contract uses unsupported Noir blackbox functions in a public function, transpilation will fail at compile time. See [AVM Cryptographic Compatibility](/developers/testnet/docs/foundational-topics/advanced/circuits/avm_compatibility.md) for the full compatibility table and workarounds. ## Execution Phases[​](#execution-phases "Direct link to Execution Phases") The AVM executes public functions in three distinct phases: | Phase | Revertible | Purpose | | ------------- | ---------- | ----------------------------------------------- | | **Setup** | No | Non-revertible initialization (fee preparation) | | **App Logic** | Yes | Main application logic | | **Teardown** | Yes | Fee payment finalization | This phased approach enables atomic fee payment even if the main transaction logic reverts. The setup phase cannot be reverted, ensuring the sequencer receives payment. ## Inputs and Outputs[​](#inputs-and-outputs "Direct link to Inputs and Outputs") ### Inputs from Private Execution[​](#inputs-from-private-execution "Direct link to Inputs from Private Execution") The AVM receives from the private phase: * **Public call requests**: Setup, app logic, and teardown function calls * **Non-revertible accumulated data**: Note hashes, nullifiers, L2-L1 messages from setup phase * **Revertible accumulated data**: Note hashes, nullifiers, L2-L1 messages that can be reverted * **Gas settings**: Limits for execution and teardown * **Fee payer**: Address responsible for transaction fees ### Outputs[​](#outputs "Direct link to Outputs") After execution, the AVM produces: | Output | Description | | ------------------ | ------------------------------------------ | | Note hashes | Combined private + public note commitments | | Nullifiers | Combined private + public nullifiers | | L2-L1 messages | Cross-chain messages to Ethereum | | Public logs | Event data from public execution | | Public data writes | State updates to the public data tree | | End tree snapshots | Final state of all trees after execution | | Transaction fee | Computed fee based on gas consumed | | Reverted flag | Whether app logic phase reverted | ## State Transitions[​](#state-transitions "Direct link to State Transitions") The AVM validates state transitions by tracking tree snapshots: * **Start snapshots**: Tree roots before public execution * **End snapshots**: Tree roots after all public functions complete These snapshots are validated in the rollup circuits to ensure continuity across transactions in a block. ## Related Pages[​](#related-pages "Direct link to Related Pages") * [AVM Cryptographic Compatibility](/developers/testnet/docs/foundational-topics/advanced/circuits/avm_compatibility.md) – Which Noir primitives work in public functions * [Private Kernel](/developers/testnet/docs/foundational-topics/advanced/circuits/private_kernel.md) – How private functions are processed * [Call Types](/developers/testnet/docs/foundational-topics/call_types.md) – How private and public functions interact * [State Management](/developers/testnet/docs/foundational-topics/state_management.md) – How public and private state works --- # Rollup Circuits The rollup circuits compress thousands of transactions into a single SNARK proof for verification on Ethereum. They aggregate proofs from private kernel and AVM execution, validate state transitions, and produce the final epoch proof submitted to L1. note The rollup circuits use a "binary tree of proofs" topology. This allows proof generation to be parallelized across prover instances—each layer of the tree can be computed in parallel, or subtrees can be distributed to different provers. ## Circuit Hierarchy[​](#circuit-hierarchy "Direct link to Circuit Hierarchy") Rollup circuits operate at four levels, each producing outputs consumed by the next: | Level | Circuits | Input | Output | | --------------- | ---------------------------------- | ------------------- | ----------------------- | | **Transaction** | TX Base (Private/Public), TX Merge | Kernel proofs | Transaction rollup data | | **Block** | Block Root, Block Merge | Transaction rollups | Block rollup data | | **Checkpoint** | Checkpoint Root, Checkpoint Merge | Block rollups | Checkpoint data | | **Epoch** | Root Rollup | Checkpoint rollups | Final epoch proof | ## Transaction Level[​](#transaction-level "Direct link to Transaction Level") ### TX Base Rollups[​](#tx-base-rollups "Direct link to TX Base Rollups") Process individual transactions from kernel proofs: * **TX Base Private** - Processes transactions with only private execution. Validates the private kernel proof, updates tree snapshots (note hash, nullifier), and accumulates fees and mana usage. * **TX Base Public** - Processes transactions that include public (AVM) execution. Validates the AVM proof, which has already performed tree updates and fee/mana accumulation during public execution. ### TX Merge Rollup[​](#tx-merge-rollup "Direct link to TX Merge Rollup") Merges pairs of transaction rollup proofs in binary fashion. Can chain recursively to aggregate many transactions into a single proof. Validates proof correctness and consecutive transaction ordering. ## Block Level[​](#block-level "Direct link to Block Level") ### Block Root Rollups[​](#block-root-rollups "Direct link to Block Root Rollups") Transition from transaction-level to block-level outputs. Several variants handle different scenarios: * **Block Root First** - First block of a checkpoint (validates parity root and L1-to-L2 tree) * **Block Root** - Subsequent blocks in a checkpoint * **Block Root Single TX** - Optimized variant for single-transaction blocks * **Block Root Empty TX First** - Handles empty blocks These circuits update the archive tree, compute block headers, and accumulate L2-to-L1 message hashes. ### Block Merge Rollup[​](#block-merge-rollup "Direct link to Block Merge Rollup") Merges pairs of block rollup proofs within a checkpoint. Validates archive continuity and state consistency between blocks. ## Checkpoint Level[​](#checkpoint-level "Direct link to Checkpoint Level") ### Checkpoint Root Rollups[​](#checkpoint-root-rollups "Direct link to Checkpoint Root Rollups") Transition from block-level to checkpoint-level outputs: * **Checkpoint Root** - Standard checkpoint containing multiple blocks * **Checkpoint Root Single Block** - Optimized for single-block checkpoints These circuits validate previous block headers, compute blob commitments, and accumulate fee recipients. ### Checkpoint Merge Rollup[​](#checkpoint-merge-rollup "Direct link to Checkpoint Merge Rollup") Merges pairs of checkpoint proofs. Validates checkpoint continuity and blob accumulator consistency. ### Checkpoint Padding[​](#checkpoint-padding "Direct link to Checkpoint Padding") A special circuit for epochs with only one checkpoint. Provides an empty right child for the binary tree structure. ## Epoch Level (Root Rollup)[​](#epoch-level-root-rollup "Direct link to Epoch Level (Root Rollup)") The final circuit that completes an epoch proof. It: * Merges two checkpoint rollup proofs * Validates epoch-level blob batching challenges * Produces the final `RootRollupPublicInputs` for L1 submission The root rollup output includes: * Previous and new archive roots * Checkpoint header hashes * Accumulated fees across all checkpoints * Final blob public inputs for data availability ## Flexible Tree Topology[​](#flexible-tree-topology "Direct link to Flexible Tree Topology") The architecture supports asymmetric "wonky trees" for efficiency: * Transactions can be grouped variably into blocks * Not all branches need the same depth * Single-element optimizations reduce proof overhead * Padding circuits handle partial epochs This flexibility allows sequencers to optimize proving costs based on actual workload. ## Related Pages[​](#related-pages "Direct link to Related Pages") * [Private Kernel](/developers/testnet/docs/foundational-topics/advanced/circuits/private_kernel.md) - How private function proofs are generated * [Public Execution](/developers/testnet/docs/foundational-topics/advanced/circuits/public_execution.md) - How the AVM produces public execution proofs --- # Indexed Merkle Tree (Nullifier Tree) ## Prerequisites[​](#prerequisites "Direct link to Prerequisites") This page assumes familiarity with: * Merkle trees and membership proofs * The UTXO model for private state * Zero-knowledge proof concepts (circuits, constraints) ## Overview[​](#overview "Direct link to Overview") This page covers indexed merkle trees and how they improve nullifier tree performance in circuits, including: * Why nullifier trees are necessary * How indexed merkle trees work * Membership exclusion proofs * Batch insertions * Tradeoffs This content was presented to the [Privacy + Scaling Explorations team at the Ethereum Foundation](https://pse.dev/). [YouTube video player](https://www.youtube-nocookie.com/embed/x_0ZhUKtWSs?si=TmguEhgz4Gu07Dac) ## Primer on Nullifier Trees[​](#primer-on-nullifier-trees "Direct link to Primer on Nullifier Trees") Privacy in public blockchains requires a UTXO model. State is stored in encrypted UTXOs in merkle trees. Since updating state directly leaks information, we simulate updates by "destroying" old UTXOs and creating new ones, resulting in an append-only merkle tree. A classic merkle tree: ![Classic merkle tree structure showing leaf nodes hashed up to a root](/assets/ideal-img/normal-merkle-tree.568bc10.640.png) To destroy state, a "nullifier" tree stores deterministic values linked to notes in the append-only tree. This is typically implemented as a sparse Merkle Tree. A sparse merkle tree (not every leaf stores a value): ![Sparse merkle tree with empty leaves represented as zeros](/assets/ideal-img/sparse-merkle-tree.59ba475.640.png) To spend or modify a note in the private state tree, you must create a nullifier and prove it does not already exist in the nullifier tree. Since nullifier trees are modeled as sparse merkle trees, non-membership checks are conceptually trivial. Data is stored at the leaf index corresponding to its value. For example, in a sparse tree containing 2256 values, to prove non-membership of value 2128: * Prove tree\_values\[2128]=0 via a merkle membership proof (value does not exist) * Conversely, prove tree\_values\[2128]==1 to show the item exists ## Problems introduced by using Sparse Merkle Trees for Nullifier Trees[​](#problems-introduced-by-using-sparse-merkle-trees-for-nullifier-trees "Direct link to Problems introduced by using Sparse Merkle Trees for Nullifier Trees") While sparse Merkle Trees offer a simple solution, they have significant drawbacks. A sparse nullifier tree must have an index for e∈Fp​, which for the bn254 curve requires a depth of 254. A tree of depth 254 means 254 hashes per membership proof. Each nullifier insertion requires a non-membership check followed by an insertion—two trips from leaf to root. This results in 254×2 hashes per insertion. Since the tree is sparse, insertions are random and must be sequential, so hash count scales linearly with nullifier count. This causes constraint counts in rollup circuits to grow rapidly, leading to long proving times. ## Indexed Merkle Tree Constructions[​](#indexed-merkle-tree-constructions "Direct link to Indexed Merkle Tree Constructions") [This paper](https://eprint.iacr.org/2021/1263.pdf) (page 6) introduces indexed merkle trees, which enable efficient non-membership proofs. Each node stores a value v∈Fp​ and pointers to the leaf with the next higher value: leaf={v,inext​,vnext​}. Based on the tree's insertion rules, no leaves exist between the range (v,vnext​). The merkle tree forms a linked list of increasing values. Once inserted, a leaf's pointers can change but its nullifier value cannot. Since leaves are no longer positioned at (index==value), a deep tree is unnecessary—32 levels suffice. This improves insertions by approximately 8x (256/32). *The node that provides the non-membership check is called a "low nullifier".* The insertion protocol: 1. Look for a nullifier's corresponding low\_nullifier where: low\_nullifiernext\_value​>new\_nullifier > if new\_nullifier is the largest use the leaf: low\_nullifiernext\_value​==0 2. Perform membership check of the low nullifier. 3. Perform a range check on the low nullifier's value and next\_value fields: new\_nullifier​>low\_nullifiervalue​&&(new\_nullifier\<low\_nullifiernext\_value​∣∣low\_nullifiernext\_value​==0)​ 4. Update the low nullifier pointers low\_nullifiernext\_index​=new\_insertion\_index low\_nullifiernext\_value​=new\_nullifier 5. Perform insertion of new updated low nullifier (yields new root) 6. Update pointers on new leaf. Note: low\_nullifier is from before update in step 4 new\_nullifier\_leafvalue​=new\_nullifier new\_nullifier\_leafnext\_value​=low\_nullifiernext\_value​ new\_nullifier\_leafnext\_index​=low\_nullifiernext\_index​ 7. Perform insertion of new leaf (yields new root) ### Insertion constraints[​](#insertion-constraints "Direct link to Insertion constraints") * `3n` hashes of 2 field elements (where `n` is the height of the tree) * `3` hashes of 3 field elements * `2` range checks * A handful of equality constraints ### Special cases[​](#special-cases "Direct link to Special cases") At step 3, low\_nullifiernext\_value​ can be 0. When a value is the maximum, it points to zero instead of a larger value (which does not exist). This closes the loop so insertions always occur within a ring, preventing splits. ### Insertion example[​](#insertion-example "Direct link to Insertion example") 1. Initial state ![Indexed merkle tree initial state with single zero node](/assets/ideal-img/index-merkle-tree-1.37958ac.640.png) 2. Add a new value v=30 ![Indexed merkle tree after inserting value 30](/assets/ideal-img/index-merkle-tree-2.163e5a0.640.png) 3. Add a new value v=10 ![Indexed merkle tree after inserting value 10](/assets/ideal-img/index-merkle-tree-3.1b3a664.640.png) 4. Add a new value v=20 ![Indexed merkle tree after inserting value 20](/assets/ideal-img/index-merkle-tree-4.4a71048.640.png) 5. Add a new value v=50 ![Indexed merkle tree after inserting value 50](/assets/ideal-img/index-merkle-tree-5.29c1da5.640.png) The diagrams show how pointers update between each insertion. Note: The first node (value 0) is pre-populated, so the first insertion goes into the second index. ### Non-membership proof[​](#non-membership-proof "Direct link to Non-membership proof") To prove value `20` does not exist, reveal the leaf that "steps over" `20`—the leaf whose value is less than `20` and whose next value is greater than `20`. This is the `low_nullifier`. * Hash the low nullifier: low\_nullifier=h(10,1,30) * Prove the low leaf exists in the tree: `n` hashes * Check the new value would have belonged in the range given by the low leaf: `2` range checks <!-- --> * If (low\_nullifiernext\_index​==0): <!-- --> * Special case, the low leaf is at the very end, so the new\_value must be higher than all values in the tree: * assert(low\_nullifiervalue​\<new\_valuevalue​) * Else: <!-- --> * assert(low\_nullifiervalue​\<new\_valuevalue​) * assert(low\_nullifiernext\_value​>new\_valuevalue​) This provides significant performance improvement, but since the tree is not sparse, we can also perform batch insertions. ## Batch insertions[​](#batch-insertions "Direct link to Batch insertions") Since nullifiers are inserted deterministically (append-only), we can insert entire subtrees rather than appending nodes individually. However, for every node inserted, low nullifier pointers must be updated. This adds complexity when the low nullifier exists within the subtree being inserted. All impacted low nullifiers must be updated before the subtree insertion. Batch insertion in an append-only merkle tree: 1. Prove the target subtree consists of all empty values 2. Calculate the root of an empty subtree and perform an inclusion proof for this empty root 3. Recreate the subtree within the circuit 4. Use the same sibling path to get the new root after subtree insertion In the following example, a subtree of size 4 is inserted. The subtree is greyed out as "pending". **Legend**: * Green: New Inserted Value * Orange: Low Nullifier **Example** 1. Prepare to insert subtree \[35,50,60,15] ![Preparing to insert subtree with values 35, 50, 60, 15](/assets/ideal-img/subtree-insert-1.04d9287.640.png) 2. Update low nullifier for new nullifier 35 ![Updating low nullifier for value 35](/assets/ideal-img/subtree-insert-2.92b8e75.640.png) 3. Update low nullifier for new nullifier 50 (the low nullifier exists within the pending insertion subtree) ![Updating low nullifier for value 50 from pending subtree](/assets/ideal-img/subtree-insert-3.e86f005.640.png) 4. Update low nullifier for new nullifier 60 ![Updating low nullifier for value 60](/assets/ideal-img/subtree-insert-4.9375e53.640.png) 5. Update low nullifier for new nullifier 15 ![Updating low nullifier for value 15](/assets/ideal-img/subtree-insert-5.0bc9b9a.640.png) 6. Update pointers for new nullifier 15 ![Updating pointers for value 15](/assets/ideal-img/subtree-insert-6.169ec0e.640.png) 7. Insert subtree ![Final state after subtree insertion](/assets/ideal-img/subtree-insert-7.740d73d.640.png) ### Performance gains from subtree insertion[​](#performance-gains-from-subtree-insertion "Direct link to Performance gains from subtree insertion") Sparse nullifier tree insertions require 1 non-membership check (254 hashes) and 1 insertion (254 hashes). For 4 values: 2032 hashes. In a depth-32 indexed tree, each subtree insertion costs 1 non-membership check (32 hashes) and 1 pointer update (32 hashes)
프로젝트로 돌아가기