bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 53쪽
e roots via `insert()` as proofs land. A proof can cover a prefix of an epoch's checkpoints (a partial proof), so an epoch can have several roots, one per number of checkpoints covered.
**Links**: [Interface](https://github.com/AztecProtocol/aztec-packages/blob/v6.0.0-rc.1/l1-contracts/src/core/interfaces/messagebridge/IOutbox.sol), [Implementation](https://github.com/AztecProtocol/aztec-packages/blob/v6.0.0-rc.1/l1-contracts/src/core/messagebridge/Outbox.sol).
## `insert()`[](#insert "Direct link to insert")
Inserts the root of a merkle tree containing all of the L2 to L1 messages in an epoch, after a proof covering the first `_numCheckpointsInEpoch` checkpoints of that epoch lands. This function is only callable by the Rollup contract.
outbox\_insert
```
/**
* @notice Inserts the root of a merkle tree containing all of the L2 to L1 messages in an epoch
* after a proof covering the first `_numCheckpointsInEpoch` checkpoints of that epoch lands.
* @dev Only callable by the rollup contract
* @dev Emits `RootAdded` upon inserting the root successfully
* @dev Successive inserts for the same epoch with larger `_numCheckpointsInEpoch` values do not
* disturb earlier entries, so users with witnesses built against an earlier partial proof can still
* consume them.
* @param _epoch - The epoch in which the L2 to L1 messages reside
* @param _numCheckpointsInEpoch - The number of checkpoints the inserting proof covered in this
* epoch. Must be in [1, MAX_CHECKPOINTS_PER_EPOCH].
* @param _root - The merkle root of the tree where all the L2 to L1 messages are leaves
*/
function insert(Epoch _epoch, uint256 _numCheckpointsInEpoch, bytes32 _root) external;
```
> [Source code: l1-contracts/src/core/interfaces/messagebridge/IOutbox.sol#L28-L43](https://github.com/AztecProtocol/aztec-packages/blob/v6.0.0-rc.1/l1-contracts/src/core/interfaces/messagebridge/IOutbox.sol#L28-L43)
| Name | Type | Description |
| ------------------------ | --------- | --------------------------------------------------------------------------------------------------------- |
| `_epoch` | `Epoch` | The epoch in which the L2 to L1 messages reside |
| `_numCheckpointsInEpoch` | `uint256` | The number of checkpoints the inserting proof covered in this epoch (in `[1, MAX_CHECKPOINTS_PER_EPOCH]`) |
| `_root` | `bytes32` | The merkle root of the tree where all the L2 to L1 messages are leaves |
### Edge cases[](#edge-cases "Direct link to Edge cases")
* Will revert with `Outbox__Unauthorized()` if `msg.sender != ROLLUP_CONTRACT`.
## `consume()`[](#consume "Direct link to consume")
Allows a recipient to consume a message from the `Outbox`.
outbox\_consume
```
/**
* @notice Consumes an entry from the Outbox
* @dev Only useable by portals / recipients of messages
* @dev Emits `MessageConsumed` when consuming messages
* @param _message - The L2 to L1 message
* @param _epoch - The epoch that contains the message we want to consume
* @param _numCheckpointsInEpoch - The number of checkpoints in the partial proof whose root this
* consume verifies against. The caller's witness path must have been built against the epoch tree
* padded to that number of real checkpoints.
* @param _leafIndex - The index at the level in the epoch message tree where the message is located
* @param _path - The sibling path used to prove inclusion of the message, the _path length depends
* on the location of the L2 to L1 message in the epoch message tree.
*/
function consume(
DataStructures.L2ToL1Msg calldata _message,
Epoch _epoch,
uint256 _numCheckpointsInEpoch,
uint256 _leafIndex,
bytes32[] calldata _path
) external;
```
> [Source code: l1-contracts/src/core/interfaces/messagebridge/IOutbox.sol#L45-L66](https://github.com/AztecProtocol/aztec-packages/blob/v6.0.0-rc.1/l1-contracts/src/core/interfaces/messagebridge/IOutbox.sol#L45-L66)
| Name | Type | Description |
| ------------------------ | ----------- | ----------------------------------------------------------------------------------------------------- |
| `_message` | `L2ToL1Msg` | The L2 to L1 message to consume |
| `_epoch` | `Epoch` | The epoch that contains the message to consume |
| `_numCheckpointsInEpoch` | `uint256` | The number of checkpoints in the partial proof whose root this consume verifies against |
| `_leafIndex` | `uint256` | The index inside the merkle tree where the message is located |
| `_path` | `bytes32[]` | The sibling path used to prove inclusion of the message (built against the tree for that proof depth) |
### Edge cases[](#edge-cases-1 "Direct link to Edge cases")
* Will revert with `Outbox__PathTooLong()` if the path length is >= 256.
* Will revert with `Outbox__LeafIndexOutOfBounds(uint256 leafIndex, uint256 pathLength)` if the leaf index exceeds the tree capacity for the given path length.
* Will revert with `Outbox__VersionMismatch(uint256 expected, uint256 actual)` if the message version does not match the Outbox version.
* Will revert with `Outbox__InvalidRecipient(address expected, address actual)` if `msg.sender != _message.recipient.actor`.
* Will revert with `Outbox__InvalidChainId()` if `block.chainid != _message.recipient.chainId`.
* Will revert with `Outbox__NothingToConsumeAtEpoch(Epoch epoch)` if the root for the epoch has not been set.
* Will revert with `Outbox__AlreadyNullified(Epoch epoch, uint256 leafIndex)` if the message has already been consumed.
* Will revert with `MerkleLib__InvalidIndexForPathLength()` if the leaf index has bits set beyond the tree height.
* Will revert with `MerkleLib__InvalidRoot(bytes32 expected, bytes32 actual, bytes32 leaf, uint256 leafIndex)` if the merkle proof verification fails.
## `hasMessageBeenConsumedAtEpoch()`[](#hasmessagebeenconsumedatepoch "Direct link to hasmessagebeenconsumedatepoch")
Checks if an L2 to L1 message in a specific epoch has been consumed.
outbox\_has\_message\_been\_consumed\_at\_epoch\_and\_index
```
/**
* @notice Checks to see if an L2 to L1 message in a specific epoch has been consumed
* @dev - This function does not throw. Out-of-bounds access is considered valid, but will always return false
* @param _epoch - The epoch that contains the message we want to check
* @param _leafId - The unique id of the message leaf
*/
function hasMessageBeenConsumedAtEpoch(Epoch _epoch, uint256 _leafId) external view returns (bool);
```
> [Source code: l1-contracts/src/core/interfaces/messagebridge/IOutbox.sol#L68-L76](https://github.com/AztecProtocol/aztec-packages/blob/v6.0.0-rc.1/l1-contracts/src/core/interfaces/messagebridge/IOutbox.sol#L68-L76)
| Name | Type | Description |
| --------- | --------- | -------------------------------------------- |
| `_epoch` | `Epoch` | The epoch that contains the message to check |
| `_leafId` | `uint256` | The unique id of the message leaf |
### Edge cases[](#edge-cases-2 "Direct link to Edge cases")
* This function does not throw. Out-of-bounds access is considered valid, but will always return false.
## `getRootData()`[](#getrootdata "Direct link to getrootdata")
Returns the merkle root for a given epoch and partial-proof depth. Returns `bytes32(0)` if no proof covering that number of checkpoints has been inserted.
```
function getRootData(Epoch _epoch, uint256 _numCheckpointsInEpoch) external view returns (bytes32);
```
| Name | Type | Description |
| ------------------------ | --------- | ------------------------------------------------------------------ |
| `_epoch` | `Epoch` | The epoch to fetch the root data for |
| `_numCheckpointsInEpoch` | `uint256` | The number of checkpoints in the partial proof whose root to fetch |
**Returns**: The merkle root of the L2 to L1 message tree for that epoch and proof depth, or `bytes32(0)` if not proven.
There is also `getRoots(Epoch _epoch)`, which returns every root stored for an epoch: slot `i` of the returned array holds the root for `numCheckpointsInEpoch = i + 1`.
## Related pages[](#related-pages "Direct link to Related pages")
* [Inbox](/developers/testnet/docs/foundational-topics/ethereum-aztec-messaging/inbox.md) - L1 to L2 message passing
* [Data Structures](/developers/testnet/docs/foundational-topics/ethereum-aztec-messaging/data_structures.md) - Message struct definitions
* [L1-L2 Communication (Portals)](/developers/testnet/docs/foundational-topics/ethereum-aztec-messaging.md) - Overview of cross-chain messaging
---
# Registry
The Registry is a contract deployed on L1 that tracks canonical and historical rollup instances. It allows you to query the current rollup contract and look up prior deployments by version.
**Links**: [Interface](https://github.com/AztecProtocol/aztec-packages/blob/v6.0.0-rc.1/l1-contracts/src/governance/interfaces/IRegistry.sol), [Implementation](https://github.com/AztecProtocol/aztec-packages/blob/v6.0.0-rc.1/l1-contracts/src/governance/Registry.sol).
## `numberOfVersions()`[](#numberofversions "Direct link to numberofversions")
Retrieves the number of versions that have been deployed.
registry\_number\_of\_versions
```
function numberOfVersions() external view returns (uint256);
```
> [Source code: l1-contracts/src/governance/interfaces/IRegistry.sol#L25-L27](https://github.com/AztecProtocol/aztec-packages/blob/v6.0.0-rc.1/l1-contracts/src/governance/interfaces/IRegistry.sol#L25-L27)
| Name | Description |
| ----------- | ---------------------------------------------- |
| ReturnValue | The number of versions that have been deployed |
## `getCanonicalRollup()`[](#getcanonicalrollup "Direct link to getcanonicalrollup")
Retrieves the current rollup contract.
registry\_get\_canonical\_rollup
```
function getCanonicalRollup() external view returns (IHaveVersion);
```
> [Source code: l1-contracts/src/governance/interfaces/IRegistry.sol#L17-L19](https://github.com/AztecProtocol/aztec-packages/blob/v6.0.0-rc.1/l1-contracts/src/governance/interfaces/IRegistry.sol#L17-L19)
| Name | Description |
| ----------- | ------------------ |
| ReturnValue | The current rollup |
## `getRollup(uint256 _version)`[](#getrollupuint256-_version "Direct link to getrollupuint256-_version")
Retrieves the rollup contract for a specific version.
registry\_get\_rollup
```
function getRollup(uint256 _chainId) external view returns (IHaveVersion);
```
> [Source code: l1-contracts/src/governance/interfaces/IRegistry.sol#L21-L23](https://github.com/AztecProtocol/aztec-packages/blob/v6.0.0-rc.1/l1-contracts/src/governance/interfaces/IRegistry.sol#L21-L23)
| Name | Description |
| ----------- | ------------------------------------ |
| `_version` | The version identifier of the rollup |
| ReturnValue | The rollup for the specified version |
## Other view functions[](#other-view-functions "Direct link to Other view functions")
| Function | Returns | Description |
| ------------------------ | -------------------- | ------------------------------------------------------------------------------------ |
| `getVersion(uint256)` | `uint256` | Returns the version number stored at the given index in the historical versions list |
| `getGovernance()` | `address` | Returns the governance contract address (owner) |
| `getRewardDistributor()` | `IRewardDistributor` | Returns the reward distributor contract |
## Related pages[](#related-pages "Direct link to Related pages")
* [Inbox](/developers/testnet/docs/foundational-topics/ethereum-aztec-messaging/inbox.md) - L1 to L2 message passing
* [Outbox](/developers/testnet/docs/foundational-topics/ethereum-aztec-messaging/outbox.md) - L2 to L1 message passing
* [L1-L2 Communication (Portals)](/developers/testnet/docs/foundational-topics/ethereum-aztec-messaging.md) - Overview of cross-chain messaging
---
# Fees
Fees are an integral part of any protocol's design. Proper fee pricing contributes to the longevity and security of a network, and the fee payment mechanisms available inform the types of applications that can be built.
In a nutshell, the pricing of transactions transparently accounts for:
* L1 costs, including L1 execution of a block, and data availability via blobs,
* L2 node operating costs, including proving
This is achieved through multiple variables and calculations.
## Terminology[](#terminology "Direct link to Terminology")
Familiar terms from Ethereum mainnet as referred to on the Aztec network:
| Ethereum Mainnet | Aztec | Description |
| ---------------- | ------------------ | -------------------------------------------------------------- |
| gas | mana | Unit measuring computational effort for transaction operations |
| fee per gas | Fee Juice per mana | Price per unit of mana |
| fee (wei) | Fee Juice | Total fee paid for a transaction |
## What is mana?[](#what-is-mana "Direct link to What is mana?")
Mana is Aztec's unit of computational effort, equivalent to gas on Ethereum. Every transaction consumes mana based on the operations it performs.
Mana has two dimensions:
* **Data Availability (DA) mana**: Cost of publishing transaction data to the data availability layer
* **L2 mana**: Cost of executing the transaction on Aztec
The total transaction fee is calculated as:
```
fee = (daMana × feePerDaMana) + (l2Mana × feePerL2Mana)
```
note
The SDK and protocol code use "gas" in variable names (e.g., `daGas`, `l2Gas`, `feePerDaGas`, `feePerL2Gas`) rather than "mana". When reading code, `Gas` and mana refer to the same concept.
## What is Fee Juice?[](#what-is-fee-juice "Direct link to What is Fee Juice?")
Fee Juice is the native fee token on Aztec, used to pay for transaction fees. It is bridged Aztec tokens from Ethereum and is **non-transferable** on Aztec - it can only be used to pay fees, not sent between accounts.
Aztec borrows ideas from EIP-1559, including congestion multipliers and the ability to specify base and priority fees per mana.
## Factors affecting fees[](#factors-affecting-fees "Direct link to Factors affecting fees")
Other fields used in mana and fee calculations are determined in various ways:
* hard-coded constants (eg congestion update fraction)
* values assumed constant (eg L1 gas cost of publishing a block, blobs per block)
* informed from previous block header and/or L1 rollup contract (eg base fee per mana)
* informed via an oracle (eg wei per mana)
Most constants are defined by the protocol, while others are part of the rollup contract on L1.
### User-defined settings[](#user-defined-settings "Direct link to User-defined settings")
Users can define the following settings as part of a transaction:
<!-- -->
gas\_settings\_vars
```
/** Gas usage and fees limits set by the transaction sender for different dimensions and phases. */
export class GasSettings {
constructor(
/** Total gas the tx may consume across all phases, teardown included. */
public readonly gasLimits: Gas,
/** Portion of gasLimits reserved for the teardown phase, billed in full when the tx has a teardown call. */
public readonly teardownGasLimits: Gas,
/** Maximum fees per gas unit the sender is willing to pay. */
public readonly maxFeesPerGas: GasFees,
/** Maximum priority fees per gas unit the sender is willing to pay on top of the base fee. */
public readonly maxPriorityFeesPerGas: GasFees,
) {}
```
> [Source code: yarn-project/stdlib/src/gas/gas\_settings.ts#L28-L41](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/yarn-project/stdlib/src/gas/gas_settings.ts#L28-L41)
The `Gas` and `GasFees` types each specify Data availability and L2 cost components, so the settings are:
* gasLimits: total DA and L2 gas limits for the transaction, covering all phases including teardown
* teardownGasLimits: portion of gasLimits reserved for an optional teardown call. A tx with a teardown call is billed these limits in full, regardless of actual teardown consumption
* maxFeesPerGas: maximum DA and L2 fees-per-gas
* maxPriorityFeesPerGas: maximum priority DA and L2 fees-per-gas
## Fee payment[](#fee-payment "Direct link to Fee payment")
A fee payer obtains Fee Juice by bridging Aztec tokens from Ethereum. The fee payer can be the account itself or a fee-paying contract (FPC), which functions similarly to a paymaster on Ethereum. On Aztec, Fee Juice is held as a public balance, is non-transferable, and is only deducted by the protocol to pay for fees.
### Bridging Fee Juice from Ethereum[](#bridging-fee-juice-from-ethereum "Direct link to Bridging Fee Juice from Ethereum")
Fee Juice originates on Ethereum as an ERC-20 token. Bridging means depositing that token into the enshrined `FeeJuicePortal` contract on L1, then claiming the resulting balance on L2. Unlike user-deployed token portals, the `FeeJuicePortal` is part of the protocol's L1 deployment, but it uses the same [cross-chain messaging](/developers/testnet/docs/aztec-nr/framework-description/ethereum_aztec_messaging.md) mechanism available to any token; the [Token Bridge Tutorial](/developers/testnet/docs/tutorials/js_tutorials/token_bridge.md) describes portal contracts in general.
Bridging happens in two steps:
1. **Deposit on L1.** The depositor generates a random claim secret, approves the `FeeJuicePortal` to spend their tokens, and calls its deposit function with the recipient's Aztec address, the amount, and the hash of the claim secret. The portal locks the tokens and sends an L1-to-L2 message addressed to the `FeeJuice` protocol contract on Aztec.
2. **Claim on L2.** After the message becomes available on Aztec (about two L2 blocks after the deposit), the claimant presents the claim secret to the `FeeJuice` contract. It consumes the message, emitting a nullifier so the same deposit cannot be claimed twice, and credits the recipient's public Fee Juice balance.
Only the hash of the claim secret appears on L1, and the recipient address is fixed at deposit time, so revealing the secret on L2 releases the funds only to the intended recipient.
The bridge is one-way. There is no withdrawal path back to L1 for users: bridged Fee Juice can only be spent on fees, and tokens leave the L1 portal only when the rollup contract distributes collected fees to sequencers and provers.
Claiming is itself an L2 transaction whose fee must be paid, which would leave a brand-new account stuck. The protocol resolves this by letting a transaction claim Fee Juice and spend it on that same transaction's fee: the claim runs in the transaction's non-revertible [setup phase](/developers/testnet/docs/foundational-topics/transactions.md#setup-phase-non-revertible), so the credited balance is available to cover the fee even if the rest of the transaction reverts. This is how a new account can pay for its own deployment with bridged Fee Juice. The `FeeJuice` contract also offers a standalone claim for pre-funding an account that will pay fees later.
In `aztec.js`, the `L1FeeJuicePortalManager` class handles the L1 side (token approval and deposit) and returns the claim details, and `FeeJuicePaymentMethodWithClaim` performs the claim and fee payment in a single transaction. See [Bridge Fee Juice from L1](/developers/testnet/docs/aztec-js/how_to_pay_fees.md#bridge-fee-juice-from-l1) for a code walkthrough. The `aztec-wallet` CLI's `bridge-fee-juice` command handles the L1 deposit step and prints the claim details for use in a later transaction.
### Payment methods[](#payment-methods "Direct link to Payment methods")
An account with Fee Juice can pay for its transactions directly. A new account can even pay for its own deployment transaction, provided Fee Juice was bridged to its address before deployment.
Alternatively, accounts can use [fee-paying contracts (FPCs)](/developers/testnet/docs/aztec-js/how_to_pay_fees.md#use-fee-payment-contracts) to pay for transactions. An FPC holds its own Fee Juice balance to pay the protocol, and can accept other tokens from users in exchange.
The **Sponsored FPC** pays fees unconditionally, enabling free transactions. It is available on testnet, dev프로젝트로 돌아가기