Aztec 백서

Aztec

원문

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

net, and local network. On mainnet, ecosystem-deployed FPCs are the practical option: the built-in reference FPC contract does not work on mainnet alpha because custom token class IDs are not included in the default public setup allowlist. As an example, Nethermind's [Private Multi Asset FPC](https://github.com/NethermindEth/aztec-fpc) demonstrates one such design; it accepts multiple tokens and routes fee payments as private notes. ### How FPCs work[​](#how-fpcs-work "Direct link to How FPCs work") An FPC acts as a fee payer on the user's behalf. Simpler FPCs (like the Sponsored FPC) just call `set_as_fee_payer()` with no user payment at all. More sophisticated FPCs accept user tokens in exchange for paying Fee Juice. A common pattern for quote-based FPCs works as follows: 1. **Quote.** The user requests a fee quote from the FPC operator, specifying the token they want to pay with and the estimated gas cost. The operator signs the quote, binding it to the user, asset, amounts, and an expiry. 2. **Authorization.** The user creates an [authentication witness](/developers/testnet/docs/foundational-topics/advanced/authwit.md) authorizing the FPC to transfer tokens from their balance. This is the same authwit mechanism used for any delegated token transfer. 3. **Setup phase (non-revertible).** The FPC's entrypoint runs during the transaction's [setup phase](/developers/testnet/docs/foundational-topics/transactions.md#setup-phase-non-revertible). It verifies the quote, collects the user's payment, declares itself as the fee payer via `set_as_fee_payer()`, and calls `end_setup()` to mark the boundary between non-revertible and revertible execution. Because this runs in the non-revertible phase, the payment is **irrevocably committed** before application logic executes: the user pays regardless of whether the app-logic phase reverts. 4. **App phase (revertible).** The user's actual transaction logic runs here. In the common fee-entrypoint flow the FPC is not involved in this phase, though some FPC designs (such as cold-start flows) perform additional app-phase work like claiming bridged tokens. Setup-phase allowlist Setup-phase execution is restricted by a protocol-level allowlist of permitted public function calls. Public token functions such as `transfer_in_public` and `_increase_public_balance` have been removed from the default allowlist; custom FPCs may only call protocol-contract setup functions (for example those on `AuthRegistry` and `FeeJuice`). See the [migration note](/developers/testnet/docs/resources/migration_notes.md#custom-token-fpcs-removed-from-default-public-setup-allowlist) for details. Key properties for developers integrating with an FPC: * **Authwit scope.** The authwit authorizes a specific action hash (typically covering the transfer amount). A nonce can be included when otherwise-identical actions need to be distinguishable. The authwit is single-use, consumed by a nullifier onchain. * **Token interface.** On networks that use the default setup allowlist, an FPC cannot call arbitrary public token functions during setup (see the callout above). Fee collection for quote-based FPCs therefore typically happens in the private domain: the user privately transfers an agreed amount to the FPC (or its operator) under the authwit from step 2, and the FPC separately declares itself the fee payer during setup using only protocol-contract calls. Any token that implements the standard Aztec token interface with authwit verification is compatible with this private-note pattern. * **Gas estimation first.** The Fee Juice amount in the quote is typically derived from the transaction's gas estimate. Simulate and estimate gas *before* requesting a quote, then pass the estimated cost to the FPC operator. * **Quote expiry.** Quotes are time-bound and single-use. Fetch a fresh quote per transaction. * **Cold-start variant.** Some FPCs offer a cold-start entrypoint where a brand-new account can bridge tokens from L1, claim them on L2, and pay the fee in one transaction, with no prior L2 balance or authwit needed, because the FPC itself claims and distributes the bridged tokens. The user still needs L1 tokens and ETH for the initial bridge transaction. Fee payments themselves can also be made private via a fully private FPC that holds Fee Juice internally and nominates itself as the fee payer during the setup phase, without revealing who initiated the transaction. See [Pay Fees Privately](/developers/testnet/docs/aztec-js/how_to_use_private_fee_juice.md) for how this pattern works and an example implementation. ### Teardown phase[​](#teardown-phase "Direct link to Teardown phase") Transactions can optionally have a "teardown" phase as part of their public execution, during which the "transaction fee" is available to public functions. This is useful to transactions/contracts that need to compute a "refund", e.g. contracts that facilitate fee abstraction. This enables FPCs to calculate the actual transaction cost and refund any overpayment to the user. Not all FPC designs use the teardown phase; some charge a fixed quoted amount with no refund, keeping unused Fee Juice in the FPC's balance for future transactions. ### Operator rewards[​](#operator-rewards "Direct link to Operator rewards") The calculated fee of a transaction is deducted from the fee payer (nominated account or fee-paying contract), then pooled together across transactions, blocks, and epochs. Once an epoch is proven, the total collected fees (minus any burnt congestion amount) are distributed to the provers and block proposers that contributed to the epoch. ## Next steps[​](#next-steps "Direct link to Next steps") For a guide on paying fees programmatically, including how to bridge Fee Juice from L1, see [How to Pay Fees](/developers/testnet/docs/aztec-js/how_to_pay_fees.md). --- # Private Execution Environment (PXE) This page describes the Private Execution Environment (PXE, pronounced "pixie"), a client-side library for the execution of private operations. It is a TypeScript library that can be run within Node.js, inside wallet software or a browser. The PXE generates proofs of private function execution, and sends these proofs along with public function execution requests to the sequencer. Private inputs never leave the client-side PXE. The PXE is responsible for: * storing secrets (e.g. encryption keys, notes, tagging secrets for note discovery) and exposing an interface for safely accessing them * orchestrating private function (circuit) execution and proof generation, including implementing [oracles](/developers/testnet/docs/aztec-nr/framework-description/advanced/protocol_oracles.md) needed for transaction execution * syncing users' relevant network state, obtained from an Aztec node * safely handling multiple accounts with siloed data and permissions One PXE can handle data and secrets for multiple accounts, while also providing isolation between them as required. ## System architecture[​](#system-architecture "Direct link to System architecture") <!-- --> Privacy consideration When the PXE queries the node for world state (e.g., to check if a nullifier exists), the node learns which data the user is interested in. This is a known tradeoff. Users can mitigate this by running their own node. ## Components[​](#components "Direct link to Components") ### Contract Function Simulator[​](#contract-function-simulator "Direct link to Contract Function Simulator") An application prompts the user's PXE to execute a transaction (e.g. execute function X with arguments Y from account Z). The application or wallet may handle gas estimation. The contract function simulator handles execution of smart contract functions by simulating transactions. It generates the required data and inputs for these functions, including partial witnesses and public inputs. By default, the simulator runs in a [kernelless mode](/developers/testnet/docs/foundational-topics/pxe/kernelless_simulations.md): it executes the private bytecode and computes the values the private kernels would have produced in TypeScript, instead of running the kernel circuits themselves. This is faster than a full simulation and lets the wallet capture authentication witness requests as offchain effects without prompting the user to sign during simulation. ### Proof Generation[​](#proof-generation "Direct link to Proof Generation") After simulation, the wallet calls `proveTx` on the PXE with all of the data generated during simulation and any [authentication witnesses](/developers/testnet/docs/foundational-topics/advanced/authwit.md) (for allowing contracts to act on behalf of the user's account contract). Once proven, the wallet sends the transaction to the network and sends the transaction hash back to the application. ### Database[​](#database "Direct link to Database") The PXE database stores various types of data locally: * **Notes**: Data representing users' private state. Notes are stored onchain as encrypted logs. Once discovered via [note tagging](/developers/testnet/docs/foundational-topics/advanced/storage/note_discovery.md), notes are decrypted and stored locally in the PXE. * **Authentication Witnesses**: Data used to approve others for executing transactions on your behalf. The PXE provides this data to transactions on-demand during transaction simulation via oracles. * **Capsules**: Per-contract non-volatile local storage for caching computation results and persisting data across transactions. See [Using Capsules](/developers/testnet/docs/aztec-nr/framework-description/advanced/how_to_use_capsules.md) for more details. * **Address Book**: Complete addresses (address + public keys) for registered accounts and known senders. This enables the PXE to sync private logs tagged with registered sender addresses. Note discovery is handled by Aztec contracts, not the PXE. This allows users to customize or update their note discovery mechanism as needed. ### Contract management[​](#contract-management "Direct link to Contract management") Applications can add contract code required for a user to interact with the application to the user's PXE. The PXE will check whether the required contracts have already been registered. There are no getters to check whether a contract has been registered, as this could leak privacy (e.g. a dapp could check whether specific contracts have been registered in a user's PXE and infer information about their interaction history). ### Keystore[​](#keystore "Direct link to Keystore") The keystore securely stores cryptographic keys for registered accounts, including: * **Nullifier keys**: Used to create nullifiers that invalidate notes when spent * **Incoming viewing keys**: Used to decrypt notes sent to the account * **Outgoing viewing keys**: Used to decrypt notes sent by the account * **Tagging keys**: Used for note discovery via the tagging protocol ### Oracles[​](#oracles "Direct link to Oracles") Oracles are pieces of data that are injected into a smart contract function from the client side. Learn more about [how oracles work](/developers/testnet/docs/aztec-nr/framework-description/advanced/protocol_oracles.md). ## Oracle versioning[​](#oracle-versioning "Direct link to Oracle versioning") The set of oracles that the PXE exposes to private and utility functions is versioned, so that contracts can declare which oracles they expect to be available. Every contract compiled with `Aztec.nr` records the oracle version it was built against, and the PXE checks this version before executing any oracle call. The version uses two components, `major.minor`, with the following compatibility rules: * **`major`** must match exactly. A major bump is a breaking change: oracles were removed or their signatures changed, and a PXE on a different major cannot safely run the contract. * **`minor`** indicates additive changes (new oracles). The PXE uses a best-effort approach here: a contract compiled against a higher `minor` than the PXE supports is still allowed to run, and an error is only thrown if the contract actually invokes an oracle the PXE does not know about. In practice, a contract built with a newer Aztec.nr may not use any of the newly added oracles at all, in which case it runs fine on an older PXE. The canonical version constants live in the PXE (`ORACLE_VERSION_MAJOR` / `ORACLE_VERSION_MINOR` in `yarn-project/pxe/src/oracle_version.ts`) and in Aztec.nr (`noir-projects/aztec-nr/aztec/src/oracle/version.nr`). The two are kept in lockstep as part of each release. ### Resolving a version mismatch[​](#resolving-a-version-mismatch "Direct link to Resolving a version mismatch") If you see an error like *"Oracle '…' not found. … The contract was compiled with Aztec.nr oracle version X.Y, but this private execution environment only supports up to A.B"*, the contract uses one or more oracles from a newer Aztec.nr than your PXE supports. To fix it, upgrade the software that ships the PXE (sandbox, wallet, or whatever embeds `@aztec-labs/pxe`) to a release whose Aztec.nr version is at least as new as the one the contract was compiled with. If the PXE reports a version that *should* include every oracle the contract needs but an oracle is still missing, that is a contract bug rather than a version problem and you should likely report it to the app developer. ## For developers[​](#for-developers "Direct link to For developers") To learn how to develop on top of the PXE, refer to these guides: * [Using capsules for local storage](/developers/testnet/docs/aztec-nr/framework-description/advanced/how_to_use_capsules.md) * [Using oracles in smart contracts](/developers/testnet/docs/aztec-nr/framework-description/advanced/protocol_oracles.md) * [Authentication witnesses](/developers/testnet/docs/foundational-topics/advanced/authwit.md) ## Next steps[​](#next-steps "Direct link to Next steps") * [Wallets](/developers/testnet/docs/foundational-topics/wallets.md) - Learn how wallets interact with the PXE * [State management](/developers/testnet/docs/foundational-topics/state_management.md) - Understand how private state is managed * [Note discovery](/developers/testnet/docs/foundational-topics/advanced/storage/note_discovery.md) - Learn how notes are discovered and synced --- # Execution hooks Execution hooks are callbacks that the PXE invokes during client-side simulation when an operation needs a decision from the wallet. They let the wallet apply its own policies before execution proceeds, such as prompting the user, consulting a dynamic allowlist, or inspecting call arguments. All hooks are optional; when a hook is absent, the PXE applies a conservative default: for example it avoids privacy leaks (such as revealing a message's recipient onchain) unless specifically told otherwise. ## Configuring hooks[​](#configuring-hooks "Direct link to Configuring hooks") Pass a `hooks` object when creating the PXE: ``` import { createPXE } from "@aztec-labs/pxe/server"; const pxe = await createPXE(node, config, { hooks: { // Allow calls to a known helper contract, deny everything else. authorizeUtilityCall: async (request) => { return request.target.equals(trustedHelper) ? { authorized: true } : { authorized: false, reason: "Unknown target" }; }, // When no onchain handshake is registered for the recipient, fall back to a non-interactive handshake. resolveTaggingSecretStrategy: async () => ({ type: "non-interactive-handshake" }), }, }); ``` ## `authorizeUtilityCall`[​](#authorizeutilitycall "Direct link to authorizeutilitycall") Called whenever a utility function makes a cross-contract call. A call made by a malicious contract could leak private information, so the hook lets the wallet decide, per call, whether to allow it. A static allowlist would not work here because neither the app nor the wallet can predict ahead of time which contracts will be invoked during execution: permission must be asked after execution has begun. Calls to standard contracts (such as the HandshakeRegistry, which is queried during every contract's sync) bypass this hook and are always authorized. Unlike [authentication witnesses (authwits)](/developers/testnet/docs/aztec-js/how_to_use_authwit.md), the hook is invoked live, while execution is underway. Authwits can be recorded during simulation and signed once at the end, but the PXE cannot predict what a utility call would return, so it must ask before continuing. Most of the time the wallet should answer on its own, for example against a list of audited or previously trusted contracts, to avoid interrupting execution multiple times asking the user for confirmation. ### Deciding what to authorize[​](#deciding-what-to-authorize "Direct link to Deciding what to authorize") Private state is siloed per contract: a utility function runs on your device with access to its own contract's private state, and nothing else. Reading your own balance through a token contract's utility function is fine, and the hook never fires, because no contract boundary is crossed. The risk appears only when one contract's utility function calls into a *different* contract, because that call can reach private state the caller could not read on its own. Consider a single cross-contract operation, reading your token balance, made by two different callers. When a DeFi router calls the token's balance utility to quote you a swap, that is a legitimate cross-contract read, and you want it allowed. When an unknown, possibly malicious contract makes the very same call to snoop your balance, you want it denied. The exposed data is identical in both cases; the only thing that differs is *who is making the call*, which is exactly the decision the hook delegates to the wallet. The wallet makes that decision by inspecting the request, which identifies the caller and target by both address and contract class ID, to judge whether the call is safe to authorize. ### In Noir tests[​](#in-noir-tests "Direct link to In Noir tests") When testing cross-contract utility calls in Noir using `TestEnvironment`, use `with_authorized_utility_call_targets` on your call options: ``` // For private calls: env.call_private_opts( account, CallPrivateOptions::new().with_authorized_utility_call_targets([target_address]), MyContract::at(caller).some_private_fn(), ); // For private view calls: env.view_private_opts( account, ViewPrivateOptions::new().with_authorized_utility_call_targets([target_address]), MyContract::at(caller).some_view_fn(), ); // For utility calls: env.execute_utility_opts( ExecuteUtilityOptions::new().with_authorized_utility_call_targets([target_address]), MyContract::at(caller).some_utility_fn(), ); ``` ### In production[​](#in-production "Direct link to In production") Pass an `authorizeUtilityCall` hook when [creating the PXE](#configuring-hooks). It receives a `UtilityCallAuthorizationRequest` with the caller and target addresses, their contract class IDs, the function selector, the function name, the arguments, and the caller context (`'private'`, `'private view'`, or `'utility'`). Return `{ authorized: true }` to allow the call, or `{ authorized: false, reason: '...' }` to deny it with a message. When the hook is absent, cross-contract utility calls are denied. See [Cross-contract utility call denied](/developers/testnet/docs/aztec-nr/debugging.md#cross-contract-utility-call-denied) for the resulting error. ## `resolveTaggingSecretStrategy`[​](#resolvetaggingsecretstrategy "Direct link to resolvetaggingsecretstrategy") Called as a fallback for message delivery: a registered onchain handshake's secret is reused directly, so this hook only fires when the sender-recipient pair has none yet. The wallet returns a concrete `TaggingSecretStrategy` (and any material the chosen derivation needs); see [Tagging secret strategy](/developers/testnet/docs/aztec-nr/framework-description/note_delivery.md#tag
프로젝트로 돌아가기