Aztec 백서

Aztec

원문

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

Once created, the commitment is just a `Field`: it can be copied freely, stored anywhere, and shared with any sender. Holding the commitment is not enough to complete it, though; only the note's designated *completer* can fill in `(storage_slot, value)` and finalize it. With AIP-20, the recipient creates a partial note by calling `initialize_transfer_commitment`, choosing both the eventual owner and the completer: ``` #[external("private")] fn initialize_transfer_commitment(to: AztecAddress, completer: AztecAddress) -> Field ``` The completer is bound into a *validity commitment* `H(partial_commitment, completer)` recorded in the nullifier tree. Despite the name, the nullifier tree is used here only as an append-only set whose entries can be checked for existence. The validity commitment uses its own domain separator, so it is not a note nullifier and consumes nothing. Completion (`transfer_private_to_commitment` or `transfer_public_to_commitment`) sets the completer to the caller's `msg_sender` and checks that the matching validity commitment exists, so a partial note can only be finalized by the address set as its completer. Completion debits a separate, authorized `from` account, so the payer and the completer can be different parties. Two properties make this useful as a payment endpoint: * **The recipient takes no action at payment time.** When the note is created, the token sends the recipient a private message identifying it. The recipient's PXE holds this pending entry and scans for the completion log whenever it has the chance. Receiving an ordinary transfer is just as passive; the difference here is that the recipient also never has to interact with the sender, because the commitment was published ahead of time. * **The completer is fixed when the note is created.** The recipient chooses who can finalize the note at creation time, and that choice is enforced cryptographically. Each partial note is single-use (see [single-use semantics](/developers/testnet/docs/aztec-nr/framework-description/advanced/partial_notes.md#single-use-semantics)), so an endpoint that accepts many payments must hold many partial notes. ## The completer choice[​](#the-completer-choice "Direct link to The completer choice") The choice of `completer` determines who can complete a given partial note, and so how senders pay through it. Two options matter: ### Completer = a specific sender[​](#completer--a-specific-sender "Direct link to Completer = a specific sender") The recipient creates one partial note per known sender ahead of time, with each `completer` set to that sender's address. The sender finalizes the note with their own funds by calling `transfer_private_to_commitment` (or `transfer_public_to_commitment`), acting as both the `from` and the `msg_sender`/completer. This works without any new contracts but requires the recipient to know each sender's address in advance. It is useful for repeat payers (subscriptions, regular invoices) but does not scale to "anyone can pay this name." ### Completer = a relayer contract[​](#completer--a-relayer-contract "Direct link to Completer = a relayer contract") The recipient creates partial notes whose `completer` is a known *relayer* contract: a contract whose only job is to forward a sender's payment into the token's completion function. Any sender can invoke the relayer, the relayer is what the token sees as `msg_sender` (so the validity commitment check passes), and the sender is debited as the authorized `from`. This is the option that scales to unknown senders. The relayer needs no per-name logic, so a single global relayer contract could serve every payment endpoint on the network. ## The relayer contract[​](#the-relayer-contract "Direct link to The relayer contract") An illustrative sketch (not a compilable reference): ``` contract PaymentRelayer { // Called by any sender holding a commitment. Forwards into the token's // completion from the relayer's call frame, so the token sees the relayer // as the completer, while the sender is debited as the authorized `from`. #[external("private")] fn pay_private(token: AztecAddress, commitment: Field, amount: u128, authwit_nonce: Field) { let from = self.context.msg_sender(); self.call(Token::at(token).transfer_private_to_commitment( from, commitment, amount, authwit_nonce, )) } } ``` How the flow works: * The recipient creates notes with `initialize_transfer_commitment(to: recipient, completer: relayer)` and publishes the commitments through their [lookup channel](#what-lives-where). Creating a note is a direct call to the token; the relayer only participates at completion. * A sender calls `pay_private` with a commitment obtained from the recipient's lookup channel. The relayer reads `from = msg_sender` (the sender) and forwards into the token. At the token's frame, `msg_sender` is the relayer, matching the completer the note was created with, so the token debits the sender and completes the note. * An [authwit](/developers/testnet/docs/aztec-nr/framework-description/authentication_witnesses.md) signed by the sender authorizes the relayer to call `transfer_private_to_commitment` with these specific arguments, since the token sees the relayer, not the sender, as the immediate caller. Both private and public payments are supported: `transfer_private_to_commitment` debits the sender's private balance, `transfer_public_to_commitment` debits their public balance. Both take an explicit authorized `from`, so the relayer never needs to hold or be pre-funded with the sender's tokens. Fee sponsorship is separate, handled by a [Fee Payment Contract (FPC)](/developers/testnet/docs/foundational-topics/fees.md) during the transaction's setup phase. ## The distribution choice[​](#the-distribution-choice "Direct link to The distribution choice") Where the mapping "name → partial-note commitments" lives is independent of who completes the notes: * **Offchain.** A static file at `alice.example/aztec.json`, an ENS text record, IPFS, or any other lookup channel. The chain never sees the name or the list size. Requires trust in the hosting and a way to authenticate the result. * **Onchain.** A registry contract with public storage mapping names to commitments. Censorship-resistant and allows atomic lookup-and-pay in a single transaction, but exposes the list size, refill cadence, and the plaintext name. The two choices are orthogonal. Either channel can hand out commitments created with any completer; only the lookup mechanism differs. ## A recommended pattern[​](#a-recommended-pattern "Direct link to A recommended pattern") For "name → unlinkable payment endpoint, passive recipient," the combination that gives the best privacy / UX ratio is offchain distribution (the recipient hosts the lookup), a relayer contract as the completer, and private→private completion so the amount stays hidden from observers who do not hold the commitment. The recipient is responsible for: 1. Periodically creating fresh partial notes with the relayer as completer. 2. Publishing the resulting commitments through whatever lookup channel they choose. 3. Pruning commitments that have been consumed (the recipient's PXE knows when each partial note has been completed). Refill cadence is an operational concern. If senders consume commitments faster than the recipient refills, the lookup will return nothing. Batching the creation of many partial notes in a single transaction reduces the per-payment cost. ## What is hidden, what leaks[​](#what-is-hidden-what-leaks "Direct link to What is hidden, what leaks") The pattern hides: * The recipient's Aztec address from senders. * The link between any two payments to the same name, as long as each payment consumes a different partial note. * The amount, in private→private completion, provided the commitment is not exposed to the observer. The completion log payload is plaintext but only discoverable by a party who can derive the tag, and the tag derives from the commitment. If the recipient's lookup channel hands out the same list to every viewer, any observer who fetches the list can derive tags and read completed amounts from it. Authenticated or sender-specific distribution narrows this exposure. The pattern leaks: * The fact that the relayer contract was invoked in a transaction. * The completion log tag for each payment. The tag does not reveal the recipient, but it confirms that *some* completion happened against *some* partial note. * Anything the lookup channel itself reveals. An offchain channel can hide the existence of the name; an onchain registry cannot. * The recipient's refill cadence, if the transactions that create fresh partial notes are visible. A reused partial note breaks both the privacy property (linkable completions) and the discovery property (the recipient's wallet will miss the second completion). The published commitments must rotate; commitments must not be republished after consumption. ## What this does not solve[​](#what-this-does-not-solve "Direct link to What this does not solve") This pattern is not a stealth-address scheme. It requires the recipient to create and publish a list of commitments ahead of time, and to keep refilling it; senders draw from that list. A stealth-address scheme, by contrast, lets a recipient publish a single meta-address once and stay otherwise passive, with each sender deriving a fresh one-time address non-interactively. Partial-note endpoints trade that recipient passivity for an explicit, recipient-controlled supply of payment slots. ## Forward-looking note[​](#forward-looking-note "Direct link to Forward-looking note") Partial-note creation uses `MessageDelivery::onchain_unconstrained` today. A constrained delivery mode (`MessageDelivery::onchain_constrained`) now exists, but its log tag is not yet fully constrained and partial notes do not use it. Constrained tagging and handshaking is tracked in [aztec-packages issue #14565](https://github.com/AztecProtocol/aztec-packages/issues/14565) and may change how recipients discover partial-note creation messages. The concepts on this page (single-use commitments, completer binding, distribution choice) are stable across that change; specific code patterns on the recipient's discovery side may shift. ## Related[​](#related "Direct link to Related") * [Partial notes](/developers/testnet/docs/aztec-nr/framework-description/advanced/partial_notes.md): the underlying primitive. * [AIP-20: Fungible Token](/developers/testnet/docs/aztec-nr/standards/aip-20.md): the token standard assumed throughout this page. * [Keys](/developers/testnet/docs/foundational-topics/accounts/keys.md): how Aztec accounts derive addresses. Partial-note endpoints offer an alternative to addresses for the specific use case of being paid. * [Fees](/developers/testnet/docs/foundational-topics/fees.md): how fee payment and sponsorship work, independent of the partial-note pattern. --- # Oracle Functions This page goes over what oracles are in Aztec and how they work. Looking for a hands-on guide? You can learn how to use oracles in a smart contract [here](/developers/testnet/docs/aztec-nr/framework-description/advanced/how_to_use_capsules.md). An oracle is something that allows us to get data from the outside world into our contracts. The most widely-known types of oracles in blockchain systems are probably Chainlink price feeds, which allow us to get the price of an asset in USD taking non-blockchain data into account. While this is one type of oracle, the more general oracle, allows us to get any data into the contract. In the context of oracle functions or oracle calls in Aztec, it can essentially be seen as user-provided arguments, that can be fetched at any point in the circuit, and don't need to be an input parameter. **Why is this useful? Why don't just pass them as input parameters?** In the world of EVM, you would just read the values directly from storage and call it a day. However, when we are working with circuits for private execution, this becomes more tricky as you cannot just read the storage directly from your state tree, because there are only commitments (e.g. hashes) there. The pre-images (content) of your commitments need to be provided to the function to prove that you actually allowed to modify them. If we fetch the notes using an oracle call, we can keep the function signature independent of the underlying data and make it easier to use. A similar idea, applied to the authentication mechanism is used for the Authentication Witnesses that allow us to have a single function signature for any wallet implementation, see [AuthWit](/developers/testnet/docs/aztec-nr/framework-description/authentication_witnesses.md) for more information on this. Oracles introduce **non-determinism** into a circuit, and thus are `unconstrained`. It is important that any information that is injected into a circuit through an oracle is later constrained for correctness. Otherwise, the circuit will be **under-constrained** and potentially insecure! `Aztec.nr` has a [module dedicated to its oracles](/aztec-nr-api/testnet/noir_aztec/oracle/index.html) where you can browse the full list. ## Inbuilt oracles[​](#inbuilt-oracles "Direct link to Inbuilt oracles") * [`debug_log`](/aztec-nr-api/testnet/noir_aztec/protocol/logging/fn.debug_log) - Provides debug functions that can be used to log information to the console. Read more about debugging [here](/developers/testnet/docs/aztec-nr/debugging.md). * [`auth_witness`](/aztec-nr-api/testnet/noir_aztec/oracle/auth_witness/index.html) - Provides a way to fetch the authentication witness for a given address. This is useful when building account contracts to support approve-like functionality. * [`get_l1_to_l2_membership_witness`](/aztec-nr-api/testnet/noir_aztec/oracle/get_l1_to_l2_membership_witness/index.html) - Returns the leaf index and sibling path for an L1 to L2 message, used to prove message existence in cross-chain applications like token bridges. * [`notes`](/aztec-nr-api/testnet/noir_aztec/oracle/notes/index.html) - Provides functions related to notes, such as fetching notes from storage, used behind the scenes for value notes and other pre-built note implementations. * [`logs`](/aztec-nr-api/testnet/noir_aztec/oracle/logs/index.html) - Provides functions to log encrypted and unencrypted data. Find a full list [on GitHub](https://github.com/aztec-labs-eng/aztec-node/tree/v6.0.0-rc.1/noir-projects/aztec-nr/aztec/src/oracle). Please note that it is **not** possible to write a custom oracle for your dapp. Oracles are implemented in the PXE, so all users of your dapp would have to use a PXE with your custom oracle included. If you want to inject some arbitrary data that does not have a dedicated oracle, you can use [capsules](/developers/testnet/docs/aztec-nr/framework-description/advanced/how_to_use_capsules.md). --- # Writing Efficient Contracts ## Writing functions[​](#writing-functions "Direct link to Writing functions") On Ethereum L1, all data is public and all execution is completely reproducible. The Aztec L2 takes on the challenge of execution of private functions on private data. This is done client side, along with the generation of corresponding proofs, so that the network can verify the proofs and append any encrypted data/nullifiers (privacy preserving state update). This highlights a key difference with how public vs private functions are written. Writing efficiently * **Public functions** can be written intuitively - optimising for execution/gas as one would for EVM L2s * **Private functions** are optimized differently, as they are compiled to a circuit to be proven locally (see [Thinking in Circuits](https://noir-lang.org/docs/guides/thinking_in_circuits)) ## Assessing efficiency[​](#assessing-efficiency "Direct link to Assessing efficiency") On Aztec (like other L2s) there are several costs/limit to consider... * L1 costs - execution, blobs, events * L2 costs - public execution, data, logs * Local limits - proof generation time, execution ### Local Proof generation[​](#local-proof-generation "Direct link to Local Proof generation") Since proof generation is a significant local burden, being mindful of the gate-count of private functions is important. The gate-count is a proportionate indicator of the memory and time required to prove locally, so should not be ignored. #### Noir for circuits[​](#noir-for-circuits "Direct link to Noir for circuits") An explanation of efficient use of Noir for circuits should be considered for each subsection under [writing efficient Noir](https://noir-lang.org/docs/guides/thinking_in_circuits#writing-efficient-noir-for-performant-products) to avoid hitting local limits. The general theme is to use language features that favour the underlying primitives and representation of a circuit from code. A couple of examples: * Since the underlying cryptography uses an equation made of additions and multiplications, these are more efficient (wrt gate count) in Noir than say bit-shifting. * Unconstrained functions by definition do not constrain their operations/output, so do not contribute to gate count. Using them carefully can bring in some savings, but the results must then be constrained so that proofs are meaningful for your application. Tradeoffs and caveats Each optimisation technique has its own tradeoffs and caveats so should be carefully considered with the full details in the linked [section](https://noir-lang.org/docs/guides/thinking_in_circuits#writing-efficient-noir-for-performant-products). #### Overhead of nested private calls[​](#overhead-of-nested-private-calls "Direct link to Overhead of nested private calls") Every transaction pays a fixed kernel overhead (\~290k gates for init, reset, and tail circuits). Each additional private function call beyond the account entrypoint adds a `private_kernel_inner` iteration (\~101k gates). This overhead compounds with the number of distinct private function calls, so be mindful of calling/nesting too many private functions — this may influence your design towards larger private functions rather than conventionally atomic ones. For example, if you have a function that calls an external verification step as a separate private function, inlining that verification saves an entire kernel iteration (\~101k gates), even if it slightly increases the calling function's own gate count. See [Private Kernel Circuit - Performance Impact](/developers/testnet/docs/foundational-topics/advanced/circuits/private_kernel.md#performance-impact) for detailed numbers. #### Profiling[​](#profiling "Direct link to Profiling") Measuring gate counts is explained in the [profiling guide](/developers/testnet/docs/aztec-nr/framework-description/advanced/how_to_profile_transactions.md). Use `aztec profile gates` for quick per-function gate counts, or `aztec-wallet profile` for full transaction profiling including kernel overhead. ### L2 Data costs[​](#l2-data-costs "Direct link to L2 Data costs") Of the L2 costs, the public/private data being updated is most significant. As L2 functions create notes, nullifiers, encrypted logs, all of this get posted into blobs on ethereum and will be quite expensive Data packing You can reduce storage operation costs by implementing custom `Packable` for your structs, packing multiple sub-`Field` values into fewer `Field` elements. See [Data Packing and Serialization](/developers/testnet/docs/aztec-nr/framework-description/data_packing.md) for details. ### L1 Limits[​](#l1-limits "Direct link to L1 Limits") While most zk rollups don't leverage the zero-knowledge property like Aztec, they do leverage the succinctness property. That is, what is stored in an L1 contract is simply a hash. For data availability, blobs are utilized since data storage is often cheaper here than in contracts. Like other L2s such costs are
프로젝트로 돌아가기