bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 52쪽
function adds a cross-chain call. In such a case, the private function would not have knowledge of the result of the cross-chain call within the same rollup (since it has yet to be executed).
Similarly to the ordering of private and public functions, we can also reap the benefits of intentionally ordering messages between L1 and L2. When a message is sent from L1 to L2, it has been "emitted" by an action in the past (an L1 interaction), allowing us to add it to the list of consumables at the "beginning" of the block execution. This practical approach means that a message could be consumed in the same block it is included. In a sophisticated setup, rollup n could send an L2 to L1 message that is then consumed on L1, and the response is added already in n+1. However, messages going from L2 to L1 will be added as they are emitted.
info
Because everything is unilateral and async, application developers must explicitly handle failure cases so users can gracefully recover. Token bridges are a prime example: it would be very inconvenient if funds are locked on one domain but never minted or unlocked on the other.
## Components[](#components "Direct link to Components")
### Portal[](#portal "Direct link to Portal")
A "portal" refers to the part of an application residing on L1, which is associated with a particular L2 address (the confidential part of the application). It could be a contract or even an EOA on L1.
### Message Boxes[](#message-boxes "Direct link to Message Boxes")
In a logical sense, a Message Box functions as a one-way message passing mechanism with two ends, one residing on each side of the divide, i.e., one component on L1 and another on L2. Essentially, these boxes are utilized to transmit messages between L1 and L2 via the rollup contract. The boxes can be envisaged as multi-sets that enable the same message to be inserted numerous times, a feature that is necessary to accommodate scenarios where, for instance, "deposit 10 eth to A" is required multiple times. The diagram below provides a detailed illustration of how one can perceive a message box in a logical context.

* Here, a `sender` will insert a message into the `pending` set, the specific constraints of the actions depend on the implementation domain, but for now, say that anyone can insert into the pending set.
* At some point, a rollup will be executed, in this step messages are "moved" from pending on Domain A, to ready on Domain B. Note that consuming the message is "pulling & deleting" (or nullifying). The action is atomic, so a message that is consumed from the pending set MUST be added to the ready set, or the state transition should fail. A further constraint is that the `sender` and `recipient` version fields must match the version of their respective inbox/outbox contracts.
* When the message has been added to the ready set, the `recipient` can consume the message as part of a function call.
A difference when compared to other cross-chain setups, is that Aztec is "pulling" messages, and that the message doesn't need to be calldata for a function call. For other rollups, execution is happening FROM the "message bridge", which then calls the L1 contract. For Aztec, you call the L1 contract, and it should then consume messages from the message box.
Why pull instead of push? Privacy. Pushing would require full calldata, which would publicly expose inputs to private functions since L1 → L2 transaction calldata is committed on L1.
By instead pulling, we can have the "message" be something that is derived from the arguments instead. This way, a private function to perform second half of a deposit, leaks the "value" deposited and "who" made the deposit (as this is done on L1), but the new owner can be hidden on L2.
To support messages in both directions we require two of these message boxes (one in each direction). However, due to the limitations of each domain, the message box for sending messages into the rollup and sending messages out are not fully symmetrical. In reality, the setup looks closer to the following:

info
The L2 -> L1 pending messages set only exist logically, as it is practically unnecessary. For anything to happen to the L2 state (e.g., update the pending messages), the state will be updated on L1, meaning that we could just as well insert the messages directly into the ready set.
### Rollup Contract[](#rollup-contract "Direct link to Rollup Contract")
The rollup contract has a few very important responsibilities. The contract must keep track of the *L2 rollup state root*, perform *state transitions* and ensure that the data is available for anyone else to synchronize to the current state.
To ensure that *state transitions* are performed correctly, the contract will derive public inputs for the **rollup circuit** based on the input data, and then use a *verifier* contract to validate that inputs correctly transition the current state to the next. All data needed for the public inputs to the circuit must be from the rollup block, ensuring that the block is available. For a valid proof, the *rollup state root* is updated and it will emit an *event* to make it easy for anyone to find the data.
As part of *state transitions* where cross-chain messages are included, the contract must "move" messages along the way, e.g., from "pending" to "ready".
### Kernel Circuit[](#kernel-circuit "Direct link to Kernel Circuit")
For L2 to L1 messages, the kernel circuit's public inputs contain a dynamic array of messages, limited to `MAX_L2_TO_L1_MSGS_PER_TX` to ensure transactions can always be included. The circuit scopes each message to the contract address that emitted it, ensuring the sender cannot be spoofed.
When consuming L1 to L2 messages, user contracts call `process_l1_to_l2_message()` which verifies the message exists in the L1 to L2 message tree and creates a nullifier to prevent double-consumption. The kernel circuit accumulates these nullifiers in its public inputs.
### Rollup Circuit[](#rollup-circuit "Direct link to Rollup Circuit")
The rollup circuit must ensure that, provided two states S and S′ and the rollup block B, applying B to S using the transition function must give us S′, e.g., T(S,B)↦S′. If this is not the case, the constraints are not satisfied.
For cross-chain messages, this means inserting and nullifying L1 → L2 messages in the trees and publishing L2 → L1 messages on chain.
### Messages[](#messages "Direct link to Messages")
While a message could theoretically be arbitrarily long, we want to limit the cost of the insertion on L1 as much as possible. Therefore, we allow the users to send 32 bytes of "content" between L1 and L2. If 32 suffices, no packing required. If the 32 is too "small" for the message directly, the sender should simply pass along a `sha256(content)` instead of the content directly (note that this hash should fit in a field element which is \~254 bits. More info on this below). The content can then either be emitted as an event on L2 or kept by the sender, who should then be the only entity that can "unpack" the message. In this manner, there is some way to "unpack" the content on the receiving domain.
The message that is passed along requires the `sender/recipient` pair to be communicated as well (we need to know who should receive the message and be able to check). By having the pending messages be a contract on L1, we can ensure that the `sender = msg.sender` and let only `content` and `recipient` be provided by the caller. We only store the commitment (`sha256(LxToLyMsg)`) on chain or in the trees, so we only need to update a single storage slot per message.
See the [Data Structures](/developers/testnet/docs/foundational-topics/ethereum-aztec-messaging/data_structures.md) page for the full message structure definitions (`L1Actor`, `L2Actor`, `L1ToL2Msg`, `L2ToL1Msg`).
info
The `bytes32` elements for `content` and `secretHash` hold values that must fit in a field element (\~ 254 bits).
info
The nullifier computation should include the index of the message in the message tree to ensure that it is possible to send duplicate messages (e.g., 2 x deposit of 500 dai to the same account).
To make it possible to hide when a specific message is consumed, the `L1ToL2Msg` is extended with a `secretHash` field, where the `secretPreimage` is used as part of the nullifier computation. This way, it is not possible for someone just seeing the `L1ToL2Msg` on L1 to know when it is consumed on L2.
## Combined Architecture[](#combined-architecture "Direct link to Combined Architecture")
The following diagram shows the overall architecture, combining the earlier sections.

## Using the L1 contract interfaces in your own project[](#using-the-l1-contract-interfaces-in-your-own-project "Direct link to Using the L1 contract interfaces in your own project")
Portal contracts import Aztec's L1 interfaces (`IRegistry`, `IInbox`, `IOutbox`, `IRollup`, and supporting libraries). These ship in the [`@aztec-foundation/l1-artifacts`](https://www.npmjs.com/package/@aztec-foundation/l1-artifacts) npm package as a self-contained Foundry project under `l1-contracts/`, versioned to match each Aztec release:
```
npm install @aztec-foundation/l1-artifacts@<aztec-version>
```
In a Foundry project, add remappings so `@aztec/*` imports (and the bundled OpenZeppelin copy) resolve into the package:
```
# foundry.toml
remappings = [
"@aztec/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/",
"@oz/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/",
"@aztec-blob-lib/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/core/libraries/rollup/"
]
```
Then import interfaces as `@aztec/core/interfaces/IRollup.sol`, `@aztec/governance/interfaces/IRegistry.sol`, and so on. Note that `forge install` cannot fetch the package: it only clones whole git repositories, and the L1 contract sources include generated files that exist only in built distributions, so npm is the supported channel.
In a Hardhat project, import with full package paths (`@aztec-foundation/l1-artifacts/l1-contracts/src/core/interfaces/IRollup.sol`), or configure equivalent aliases pointing at `node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src`.
## See also[](#see-also "Direct link to See also")
* [Communicating Cross-Chain](/developers/testnet/docs/aztec-nr/framework-description/ethereum_aztec_messaging.md) - Practical guide with code examples for L1-L2 messaging
* [Data Structures](/developers/testnet/docs/foundational-topics/ethereum-aztec-messaging/data_structures.md) - Message and actor type definitions
* [Inbox](/developers/testnet/docs/foundational-topics/ethereum-aztec-messaging/inbox.md) - L1 contract for sending messages to L2
* [Outbox](/developers/testnet/docs/foundational-topics/ethereum-aztec-messaging/outbox.md) - L1 contract for consuming messages from L2
---
# Data Structures
This page documents the Solidity structs used for L1-L2 message passing in the Aztec protocol.
**Source**: [DataStructures.sol](https://github.com/AztecProtocol/aztec-packages/blob/v6.0.0-rc.1/l1-contracts/src/core/libraries/DataStructures.sol)
## `L1Actor`[](#l1actor "Direct link to l1actor")
An entity on L1, specifying the address and the chainId. Used when specifying a sender or recipient on L1.
l1\_actor
```
/**
* @notice Actor on L1.
* @param actor - The address of the actor
* @param chainId - The chainId of the actor
*/
struct L1Actor {
address actor;
uint256 chainId;
}
```
> [Source code: l1-contracts/src/core/libraries/DataStructures.sol#L11-L22](https://github.com/AztecProtocol/aztec-packages/blob/v6.0.0-rc.1/l1-contracts/src/core/libraries/DataStructures.sol#L11-L22)
## `L2Actor`[](#l2actor "Direct link to l2actor")
An entity on L2, specifying the Aztec address and the protocol version. Used when specifying a sender or recipient on L2.
l2\_actor
```
/**
* @notice Actor on L2.
* @param actor - The aztec address of the actor
* @param version - Ahe Aztec instance the actor is on
*/
struct L2Actor {
bytes32 actor;
uint256 version;
}
```
> [Source code: l1-contracts/src/core/libraries/DataStructures.sol#L24-L35](https://github.com/AztecProtocol/aztec-packages/blob/v6.0.0-rc.1/l1-contracts/src/core/libraries/DataStructures.sol#L24-L35)
## `L1ToL2Msg`[](#l1tol2msg "Direct link to l1tol2msg")
A message sent from L1 to L2. The `secretHash` field contains the hash of a secret pre-image that must be known to consume the message on L2. Use [`computeSecretHash`](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/yarn-project/stdlib/src/hash/hash.ts) to compute it from a secret.
l1\_to\_l2\_msg
```
/**
* @notice Struct containing a message from L1 to L2
* @param sender - The sender of the message
* @param recipient - The recipient of the message
* @param content - The content of the message (application specific) padded to bytes32 or hashed if larger.
* @param secretHash - The secret hash of the message (make it possible to hide when a specific message is consumed on
* L2).
* @param index - Global leaf index on the L1 to L2 messages tree.
*/
struct L1ToL2Msg {
L1Actor sender;
L2Actor recipient;
bytes32 content;
bytes32 secretHash;
uint256 index;
}
```
> [Source code: l1-contracts/src/core/libraries/DataStructures.sol#L37-L55](https://github.com/AztecProtocol/aztec-packages/blob/v6.0.0-rc.1/l1-contracts/src/core/libraries/DataStructures.sol#L37-L55)
## `L2ToL1Msg`[](#l2tol1msg "Direct link to l2tol1msg")
A message sent from L2 to L1.
l2\_to\_l1\_msg
```
/**
* @notice Struct containing a message from L2 to L1
* @param sender - The sender of the message
* @param recipient - The recipient of the message
* @param content - The content of the message (application specific) padded to bytes32 or hashed if larger.
* @dev Not to be confused with L2ToL1Message in Noir circuits
*/
struct L2ToL1Msg {
DataStructures.L2Actor sender;
DataStructures.L1Actor recipient;
bytes32 content;
}
```
> [Source code: l1-contracts/src/core/libraries/DataStructures.sol#L57-L70](https://github.com/AztecProtocol/aztec-packages/blob/v6.0.0-rc.1/l1-contracts/src/core/libraries/DataStructures.sol#L57-L70)
## See also[](#see-also "Direct link to See also")
* [Inbox](/developers/testnet/docs/foundational-topics/ethereum-aztec-messaging/inbox.md) - L1 contract for sending messages to L2
* [Outbox](/developers/testnet/docs/foundational-topics/ethereum-aztec-messaging/outbox.md) - L1 contract for consuming messages from L2
* [Portal messaging overview](/developers/testnet/docs/foundational-topics/ethereum-aztec-messaging.md) - How L1-L2 messaging works
---
# Inbox
The `Inbox` is a contract deployed on L1 that handles message passing from L1 to L2.
**Links**: [Interface](https://github.com/AztecProtocol/aztec-packages/blob/v6.0.0-rc.1/l1-contracts/src/core/interfaces/messagebridge/IInbox.sol), [Implementation](https://github.com/AztecProtocol/aztec-packages/blob/v6.0.0-rc.1/l1-contracts/src/core/messagebridge/Inbox.sol).
## `sendL2Message()`[](#sendl2message "Direct link to sendl2message")
Sends a message from L1 to L2.
send\_l1\_to\_l2\_message
```
/**
* @notice Inserts a new message into the Inbox
* @dev Emits `MessageSent` with data for easy access by the sequencer
* @param _recipient - The recipient of the message
* @param _content - The content of the message (application specific)
* @param _secretHash - The secret hash of the message (make it possible to hide when a specific message is consumed
* on L2)
* @return The key of the message in the set and its compact cumulative index
*/
function sendL2Message(DataStructures.L2Actor memory _recipient, bytes32 _content, bytes32 _secretHash)
external
returns (bytes32, uint256);
```
> [Source code: l1-contracts/src/core/interfaces/messagebridge/IInbox.sol#L67-L80](https://github.com/AztecProtocol/aztec-packages/blob/v6.0.0-rc.1/l1-contracts/src/core/interfaces/messagebridge/IInbox.sol#L67-L80)
| Name | Type | Description |
| ----------- | ------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Recipient | [`L2Actor`](/developers/testnet/docs/foundational-topics/ethereum-aztec-messaging/data_structures.md#l2actor) | The recipient of the message. The recipient's version **MUST** match the inbox version and the actor must be an Aztec contract that is **attached** to the contract making this call. If the recipient is not attached to the caller, the message cannot be consumed by it. |
| Content | `field` (\~254 bits) | The content of the message. This is the data that will be passed to the recipient. The content is limited to a single field for rollup purposes. If the content is small enough it can be passed directly, otherwise it should be hashed and the hash passed along (you can use our [`Hash`](https://github.com/AztecProtocol/aztec-packages/blob/v6.0.0-rc.1/l1-contracts/src/core/libraries/crypto/Hash.sol) utilities with `sha256ToField` functions). |
| Secret Hash | `field` (\~254 bits) | A hash of a secret used when consuming the message on L2. Keep this preimage secret to make the consumption private. To consume the message the caller must know the pre-image (the value that was hashed). Use [`computeSecretHash`](https://github.com/aztec-labs-eng/aztec-node/blob/v6.0.0-rc.1/yarn-project/stdlib/src/hash/hash.ts) to compute it from a secret. |
| ReturnValue | `(bytes32, uint256)` | The message hash (used as an identifier) and the leaf index in the tree. |
#### Edge cases[](#edge-cases "Direct link to Edge cases")
* Will revert with `Inbox__ActorTooLarge(bytes32 actor)` if the recipient actor is larger than the field size (\~254 bits).
* Will revert with `Inbox__VersionMismatch(uint256 expected, uint256 actual)` if the recipient version doesn't match the inbox version.
* Will revert with `Inbox__ContentTooLarge(bytes32 content)` if the content is larger than the field size (\~254 bits).
* Will revert with `Inbox__SecretHashTooLarge(bytes32 secretHash)` if the secret hash is larger than the field size (\~254 bits).
## View functions[](#view-functions "Direct link to View functions")
These functions allow you to query the current state of the Inbox.
| Function | Returns | Description |
| ---------------------------- | ------------ | ------------------------------------------------------------------------ |
| `getState()` | `InboxState` | Returns the current inbox state (rolling hash, total messages inserted). |
| `getTotalMessagesInserted()` | `uint64` | Returns the total number of messages inserted into the inbox. |
| `getFeeAssetPortal()` | `address` | Returns the address of the Fee Juice portal. |
## Related pages[](#related-pages "Direct link to Related pages")
* [Outbox](/developers/testnet/docs/foundational-topics/ethereum-aztec-messaging/outbox.md) - L2 to L1 message passing
* [Data Structures](/developers/testnet/docs/foundational-topics/ethereum-aztec-messaging/data_structures.md) - Message and actor type definitions
---
# Outbox
The `Outbox` is a contract deployed on L1 that handles message passing from L2 to L1. Portal contracts call `consume()` to receive and process messages that were sent from L2 contracts. The Rollup contract inserts messag프로젝트로 돌아가기