Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,10 @@ These functions allow you to query the current state of the Inbox.

| Function | Returns | Description |
| -------------------------- | ----------------- | ------------------------------------------------ |
| `getRoot(uint256)` | `bytes32` | Returns the root of a message tree for a given checkpoint number. |
| `getState()` | `InboxState` | Returns the current inbox state (rolling hash, total messages inserted, in-progress checkpoint). |
| `getState()` | `InboxState` | Returns the current inbox state (rolling hash, total messages inserted). |
| `getTotalMessagesInserted()` | `uint64` | Returns the total number of messages inserted into the inbox. |
| `getInProgress()` | `uint64` | Returns the checkpoint number currently being filled. |
| `getFeeAssetPortal()` | `address` | Returns the address of the Fee Juice portal. |

## Internal functions

:::note
The following functions are only callable by the Rollup contract and are documented here for completeness.
:::

### `consume()`

Consumes a message tree for a given checkpoint number.

#include_code consume l1-contracts/src/core/interfaces/messagebridge/IInbox.sol solidity

| Name | Type | Description |
| ----------- | --------- | ---------------------------------------- |
| _toConsume | `uint256` | The checkpoint number to consume. |
| ReturnValue | `bytes32` | The root of the consumed message tree. |

#### Edge cases

- Will revert with `Inbox__Unauthorized()` if `msg.sender != ROLLUP`.
- Will revert with `Inbox__MustBuildBeforeConsume()` if trying to consume a checkpoint that hasn't been built yet.

## Related pages

- [Outbox](./outbox.md) - L2 to L1 message passing
Expand Down
1 change: 0 additions & 1 deletion docs/examples/ts/aave_bridge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ const INBOX_ABI = [
type: "event",
name: "MessageSent",
inputs: [
{ name: "checkpointNumber", type: "uint256", indexed: true },
{ name: "index", type: "uint256", indexed: false },
{ name: "hash", type: "bytes32", indexed: true },
{ name: "rollingHash", type: "bytes16", indexed: false },
Expand Down
1 change: 0 additions & 1 deletion docs/examples/ts/example_swap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ const INBOX_ABI = [
type: "event",
name: "MessageSent",
inputs: [
{ name: "checkpointNumber", type: "uint256", indexed: true },
{ name: "index", type: "uint256", indexed: false },
{ name: "hash", type: "bytes32", indexed: true },
{ name: "rollingHash", type: "bytes16", indexed: false },
Expand Down
1 change: 0 additions & 1 deletion docs/examples/ts/token_bridge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ const INBOX_ABI = [
type: "event",
name: "MessageSent",
inputs: [
{ name: "checkpointNumber", type: "uint256", indexed: true },
{ name: "index", type: "uint256", indexed: false },
{ name: "hash", type: "bytes32", indexed: true },
{ name: "rollingHash", type: "bytes16", indexed: false },
Expand Down
1 change: 0 additions & 1 deletion l1-contracts/script/deploy/RollupConfiguration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ contract RollupConfiguration is IRollupConfiguration, Test {
config.targetCommitteeSize = vm.envUint("AZTEC_TARGET_COMMITTEE_SIZE");
config.lagInEpochsForValidatorSet = vm.envUint("AZTEC_LAG_IN_EPOCHS_FOR_VALIDATOR_SET");
config.lagInEpochsForRandao = vm.envUint("AZTEC_LAG_IN_EPOCHS_FOR_RANDAO");
config.inboxLag = vm.envUint("AZTEC_INBOX_LAG");
config.aztecProofSubmissionEpochs = vm.envUint("AZTEC_PROOF_SUBMISSION_EPOCHS");
config.localEjectionThreshold = vm.envUint("AZTEC_LOCAL_EJECTION_THRESHOLD");
config.slashingQuorum = vm.envOr("AZTEC_SLASHING_QUORUM", slashingRoundSize / 2 + 1);
Expand Down
14 changes: 1 addition & 13 deletions l1-contracts/src/core/RollupCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {IStakingCore} from "@aztec/core/interfaces/IStaking.sol";
import {IValidatorSelectionCore} from "@aztec/core/interfaces/IValidatorSelection.sol";
import {IInbox} from "@aztec/core/interfaces/messagebridge/IInbox.sol";
import {IOutbox} from "@aztec/core/interfaces/messagebridge/IOutbox.sol";
import {Constants} from "@aztec/core/libraries/ConstantsGen.sol";
import {CommitteeAttestations} from "@aztec/core/libraries/rollup/AttestationLib.sol";
import {Errors} from "@aztec/core/libraries/Errors.sol";
import {EpochProofExtLib} from "@aztec/core/libraries/rollup/EpochProofExtLib.sol";
Expand Down Expand Up @@ -620,18 +619,7 @@ contract RollupCore is EIP712("Aztec Rollup", "1"), Ownable, IStakingCore, IVali
rollupStore.config.epochProofVerifier = _epochProofVerifier;
rollupStore.config.version = _config.version;

IInbox inbox = IInbox(
address(
new Inbox(
address(this),
_feeAsset,
_config.version,
Constants.L1_TO_L2_MSG_SUBTREE_HEIGHT,
_config.inboxLag,
INBOX_BUCKET_RING_SIZE
)
)
);
IInbox inbox = IInbox(address(new Inbox(address(this), _feeAsset, _config.version, INBOX_BUCKET_RING_SIZE)));

rollupStore.config.inbox = inbox;
rollupStore.config.outbox = IOutbox(address(new Outbox(address(this), _config.version)));
Expand Down
6 changes: 2 additions & 4 deletions l1-contracts/src/core/interfaces/IRollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ struct PublicInputArgs {
bytes32 previousArchive;
bytes32 endArchive;
bytes32 outHash;
// Inbox rolling-hash chain segment consumed across the proven epoch (AZIP-22 Fast Inbox). Deliberately UNVALIDATED
// until the Fast Inbox flip, when they get checked against per-checkpoint records written at propose; for now they
// are only passed through to the proof's public inputs.
// Inbox rolling-hash chain segment consumed across the proven epoch (AZIP-22 Fast Inbox). Both boundaries are
// anchored at proof submission against the rolling hashes recorded at propose for checkpoints start - 1 and end.
bytes32 previousInboxRollingHash;
bytes32 endInboxRollingHash;
address proverId;
Expand Down Expand Up @@ -84,7 +83,6 @@ struct RollupConfigInput {
RewardBoostConfig rewardBoostConfig;
StakingQueueConfig stakingQueueConfig;
uint256 localEjectionThreshold;
uint256 inboxLag;
}

struct RollupConfig {
Expand Down
50 changes: 12 additions & 38 deletions l1-contracts/src/core/interfaces/messagebridge/IInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ pragma solidity >=0.8.27;
import {DataStructures} from "../../libraries/DataStructures.sol";

// Maximum number of messages a single bucket can hold before further messages in the same L1 block spill over
// into the next bucket. Matches the number of L1 to L2 messages a single L2 block can insert once the streaming
// inbox is live, so any one bucket is always consumable by one block.
// into the next bucket. Matches the number of L1 to L2 messages a single L2 block can insert, so any one bucket
// is always consumable by one block.
uint256 constant MAX_MSGS_PER_BUCKET = 256;

/**
Expand All @@ -16,16 +16,14 @@ uint256 constant MAX_MSGS_PER_BUCKET = 256;
*/
interface IInbox {
struct InboxState {
// Rolling hash of all messages inserted into the inbox.
// Used by clients to check for consistency.
// TODO: remove once the streaming inbox (AZIP-22 Fast Inbox) flips on and clients rely on the
// consensus rolling hash tracked in the buckets instead.
// Legacy 128-bit keccak rolling hash of all messages inserted into the inbox. Consumed only by the
// node for message sync and L1-reorg detection.
// TODO: remove once the node relies on the full-width consensus rolling hash tracked in the buckets
// instead (AZIP-22 Fast Inbox).
bytes16 rollingHash;
// This value is not used much by the contract, but it is useful for synching the node faster
// as it can more easily figure out if it can just skip looking for events for a time period.
// Cumulative number of messages inserted into the inbox. Useful for synching the node faster as it can
// more easily figure out if it can just skip looking for events for a time period.
uint64 totalMessagesInserted;
// Number of a tree which is currently being filled
uint64 inProgress;
}

/**
Expand All @@ -50,20 +48,14 @@ interface IInbox {

/**
* @notice Emitted when a message is sent
* @param checkpointNumber - The checkpoint number in which the message is included
* @param index - The index of the message in the L1 to L2 messages tree
* @param index - The compact cumulative index of the message in the Inbox insertion order
* @param hash - The hash of the message
* @param rollingHash - The rolling hash of all messages inserted into the inbox
* @param rollingHash - The legacy 128-bit rolling hash of all messages inserted into the inbox
* @param inboxRollingHash - The consensus rolling hash (truncated sha256 chain) after this message
* @param bucketSeq - The sequence number of the bucket this message was absorbed into
*/
event MessageSent(
uint256 indexed checkpointNumber,
uint256 index,
bytes32 indexed hash,
bytes16 rollingHash,
bytes32 inboxRollingHash,
uint256 bucketSeq
uint256 index, bytes32 indexed hash, bytes16 rollingHash, bytes32 inboxRollingHash, uint256 bucketSeq
);

// docs:start:send_l1_to_l2_message
Expand All @@ -74,37 +66,19 @@ interface IInbox {
* @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 leaf index in the tree
* @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);
// docs:end:send_l1_to_l2_message

// docs:start:consume
/**
* @notice Consumes the current tree, and starts a new one if needed
* @dev Only callable by the rollup contract
* @dev In the first iteration we return empty tree root because first checkpoint's messages tree is always
* empty because there has to be a 1 checkpoint lag to prevent sequencer DOS attacks
*
* @param _toConsume - The checkpoint number to consume
*
* @return The root of the consumed tree
*/
function consume(uint256 _toConsume) external returns (bytes32);
// docs:end:consume

function getFeeAssetPortal() external view returns (address);

function getRoot(uint256 _checkpointNumber) external view returns (bytes32);

function getState() external view returns (InboxState memory);

function getTotalMessagesInserted() external view returns (uint64);

function getInProgress() external view returns (uint64);

/**
* @notice Returns the sequence number of the bucket currently accumulating messages
* @return The current bucket sequence number
Expand Down
3 changes: 0 additions & 3 deletions l1-contracts/src/core/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ library Errors {
error DevNet__InvalidProposer(address expected, address actual); // 0x11e6e6f7

// Inbox
error Inbox__Unauthorized(); // 0xe5336a6b
error Inbox__ActorTooLarge(bytes32 actor); // 0xa776a06e
error Inbox__VersionMismatch(uint256 expected, uint256 actual); // 0x47452014
error Inbox__ContentTooLarge(bytes32 content); // 0x47452014
error Inbox__SecretHashTooLarge(bytes32 secretHash); // 0xecde7e2c
error Inbox__MustBuildBeforeConsume(); // 0xc4901999
error Inbox__BucketOutOfWindow(uint256 seq, uint256 current); // 0xfee255b7

// Outbox
Expand Down Expand Up @@ -58,7 +56,6 @@ library Errors {
error Rollup__InvalidCheckpointHeader(bytes32 expected, bytes32 actual);
error Rollup__InvalidCheckpointHeaderCount(uint256 expected, uint256 actual);
error Rollup__InvalidCheckpointNumber(uint256 expected, uint256 actual); // 0xd1ba9bfa
error Rollup__InvalidInHash(bytes32 expected, bytes32 actual); // 0xcd6f4233
error Rollup__InvalidInboxRollingHash(bytes32 expected, bytes32 actual); // 0xed1f7bb5
error Rollup__InvalidPreviousInboxRollingHash(bytes32 expected, bytes32 actual); // 0x2fe7cae5
error Rollup__InvalidEndInboxRollingHash(bytes32 expected, bytes32 actual); // 0x4a9cdb72
Expand Down
8 changes: 4 additions & 4 deletions l1-contracts/src/core/libraries/rollup/ProposeLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ library ProposeLib {
* - Checkpoint header validations (see validateHeader function for details)
* - Proposer signature is valid for designated slot proposer:
* Errors.ValidatorSelection__MissingProposerSignature
* - Inbox hash matches expected value: Errors.Rollup__InvalidInHash
* - Streaming Inbox consumption is valid: Errors.Rollup__InvalidInboxRollingHash
* - Archive root is within the scalar field: Errors.Rollup__FieldElementOutOfRange
*
* Validations NOT performed:
Expand All @@ -154,7 +154,7 @@ library ProposeLib {
* - Store archive root for the new checkpoint number
* - Store checkpoint metadata in circular storage (TempCheckpointLog)
* - Update L1 gas fee oracle
* - Consume inbox messages
* - Validate streaming Inbox consumption against the parent checkpoint
* - Setup epoch for validator selection (first block of the epoch)
*
* @param _args - The arguments to propose the checkpoint
Expand Down Expand Up @@ -401,8 +401,8 @@ library ProposeLib {

/**
* @notice Validates a checkpoint's Inbox consumption against the streaming inbox buckets and returns how
* far consumption has reached. Not yet called from propose(): the legacy `consume()`/`inHash` flow
* remains the enforced path until the streaming inbox (AZIP-22 Fast Inbox) flips on.
* far consumption has reached. Called from propose() as the enforced consumption path (AZIP-22 Fast
* Inbox).
*
* @dev Read-only; performs no Inbox write. Checks, in order:
* 1. The checkpoint header's `inboxRollingHash` must equal the rolling hash snapshotted in the Inbox
Expand Down
Loading
Loading