From 9dc69d0cfc48e8d13a1a1203243bb961d9b47bc5 Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 5 Mar 2024 10:45:34 +0000 Subject: [PATCH] linter fix --- .../interfaces/messagebridge/INewInbox.sol | 42 +++++++++++++++++++ .../src/core/messagebridge/NewInbox.sol | 9 ++-- 2 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 l1-contracts/src/core/interfaces/messagebridge/INewInbox.sol diff --git a/l1-contracts/src/core/interfaces/messagebridge/INewInbox.sol b/l1-contracts/src/core/interfaces/messagebridge/INewInbox.sol new file mode 100644 index 00000000000..35b90ed6c3a --- /dev/null +++ b/l1-contracts/src/core/interfaces/messagebridge/INewInbox.sol @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright 2023 Aztec Labs. +pragma solidity >=0.8.18; + +import {DataStructures} from "../../libraries/DataStructures.sol"; + +/** + * @title Inbox + * @author Aztec Labs + * @notice Lives on L1 and is used to pass messages into the rollup, e.g., L1 -> L2 messages. + */ +// TODO: rename to IInbox once all the pieces of the new message model are in place. +interface INewInbox { + event LeafInserted(uint256 indexed blockNumber, uint256 index, bytes32 value); + + // docs:start:send_l1_to_l2_message + /** + * @notice Inserts a new message into the Inbox + * @dev Emits `LeafInserted` 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 + */ + function sendL2Message( + DataStructures.L2Actor memory _recipient, + bytes32 _content, + bytes32 _secretHash + ) external returns (bytes32); + // docs:end:send_l1_to_l2_message + + // docs:start:inbox_batch_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 block's messages tree is always + * empty because there has to be a 1 block lag to prevent sequencer DOS attacks + * @return The root of the consumed tree + */ + function consume() external returns (bytes32); + // docs:end:inbox_batch_consume +} diff --git a/l1-contracts/src/core/messagebridge/NewInbox.sol b/l1-contracts/src/core/messagebridge/NewInbox.sol index f0f9d1db897..e43343b108e 100644 --- a/l1-contracts/src/core/messagebridge/NewInbox.sol +++ b/l1-contracts/src/core/messagebridge/NewInbox.sol @@ -5,6 +5,7 @@ pragma solidity >=0.8.18; // Interfaces import {IFrontier} from "../interfaces/messagebridge/IFrontier.sol"; import {IRegistry} from "../interfaces/messagebridge/IRegistry.sol"; +import {INewInbox} from "../interfaces/messagebridge/INewInbox.sol"; // Libraries import {Constants} from "../libraries/ConstantsGen.sol"; @@ -21,7 +22,7 @@ import {FrontierMerkle} from "./frontier_tree/Frontier.sol"; * @notice Lives on L1 and is used to pass messages into the rollup, e.g., L1 -> L2 messages. */ // TODO: rename to Inbox once all the pieces of the new message model are in place. -contract NewInbox { +contract NewInbox is INewInbox { using Hash for DataStructures.L1ToL2Msg; address public immutable ROLLUP; @@ -35,8 +36,6 @@ contract NewInbox { mapping(uint256 blockNumber => IFrontier tree) internal trees; - event LeafInserted(uint256 indexed blockNumber, uint256 index, bytes32 value); - constructor(address _rollup, uint256 _height) { ROLLUP = _rollup; @@ -62,7 +61,7 @@ contract NewInbox { DataStructures.L2Actor memory _recipient, bytes32 _content, bytes32 _secretHash - ) external returns (bytes32) { + ) external override(INewInbox) returns (bytes32) { if (uint256(_recipient.actor) > Constants.MAX_FIELD_VALUE) { revert Errors.Inbox__ActorTooLarge(_recipient.actor); } @@ -104,7 +103,7 @@ contract NewInbox { * empty because there has to be a 1 block lag to prevent sequencer DOS attacks * @return The root of the consumed tree */ - function consume() external returns (bytes32) { + function consume() external override(INewInbox) returns (bytes32) { if (msg.sender != ROLLUP) { revert Errors.Inbox__Unauthorized(); }