From 3dd75257f5fed2b334f722b1ec474fdb1ea1d741 Mon Sep 17 00:00:00 2001 From: Rahul Kothari Date: Mon, 22 May 2023 14:23:36 +0000 Subject: [PATCH] address pr comments --- l1-contracts/src/core/Rollup.sol | 4 +- .../interfaces/messagebridge/IRegistry.sol | 13 +++++-- .../src/core/libraries/DataStructures.sol | 2 +- l1-contracts/src/core/messagebridge/Inbox.sol | 3 +- .../src/core/messagebridge/Outbox.sol | 3 +- .../src/core/messagebridge/Registry.sol | 38 +++++++++++++++---- .../test/portals/RollupNativeAsset.sol | 2 +- l1-contracts/test/portals/TokenPortal.sol | 2 +- 8 files changed, 49 insertions(+), 18 deletions(-) diff --git a/l1-contracts/src/core/Rollup.sol b/l1-contracts/src/core/Rollup.sol index 7be225b8493..85571006e3e 100644 --- a/l1-contracts/src/core/Rollup.sol +++ b/l1-contracts/src/core/Rollup.sol @@ -62,11 +62,11 @@ contract Rollup is Decoder { // @todo (issue #605) handle fee collector // @todo: (issue #624) handle different versions - IInbox inbox = REGISTRY.getLatestInbox(); + IInbox inbox = REGISTRY.getInbox(); inbox.batchConsume(l1ToL2Msgs, msg.sender); // @todo: (issue #624) handle different versions - IOutbox outbox = REGISTRY.getLatestOutbox(); + IOutbox outbox = REGISTRY.getOutbox(); outbox.sendL1Messages(l2ToL1Msgs); emit L2BlockProcessed(l2BlockNumber); diff --git a/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol b/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol index 1ca00ddde47..44966dcbadd 100644 --- a/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol +++ b/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol @@ -7,9 +7,16 @@ import {IInbox} from "./IInbox.sol"; import {IOutbox} from "./IOutbox.sol"; interface IRegistry { - function getLatestRollup() external view returns (IRollup); + function getRollup() external view returns (IRollup); - function getLatestInbox() external view returns (IInbox); + function getInbox() external view returns (IInbox); - function getLatestOutbox() external view returns (IOutbox); + function getOutbox() external view returns (IOutbox); + + function getSnapshot(uint256 _version) + external + view + returns (DataStructures.RegistrySnapshot memory); + + function getLatestSnapshot() external view returns (DataStructures.RegistrySnapshot memory); } diff --git a/l1-contracts/src/core/libraries/DataStructures.sol b/l1-contracts/src/core/libraries/DataStructures.sol index 5314aeeb1ee..2325f7a4e77 100644 --- a/l1-contracts/src/core/libraries/DataStructures.sol +++ b/l1-contracts/src/core/libraries/DataStructures.sol @@ -71,7 +71,7 @@ library DataStructures { * @param outbox - The address of the outbox contract * @param blockNumber - The block number of the snapshot */ - struct Snapshot { + struct RegistrySnapshot { address rollup; address inbox; address outbox; diff --git a/l1-contracts/src/core/messagebridge/Inbox.sol b/l1-contracts/src/core/messagebridge/Inbox.sol index e88b73395dd..45e328aabdb 100644 --- a/l1-contracts/src/core/messagebridge/Inbox.sol +++ b/l1-contracts/src/core/messagebridge/Inbox.sol @@ -24,7 +24,8 @@ contract Inbox is IInbox { mapping(address account => uint256 balance) public feesAccrued; modifier onlyRollup() { - if (msg.sender != address(REGISTRY.getLatestRollup())) revert Errors.Inbox__Unauthorized(); + // @todo: (issue #624) handle different versions + if (msg.sender != address(REGISTRY.getRollup())) revert Errors.Inbox__Unauthorized(); _; } diff --git a/l1-contracts/src/core/messagebridge/Outbox.sol b/l1-contracts/src/core/messagebridge/Outbox.sol index fe2596c2dcd..6249531e10b 100644 --- a/l1-contracts/src/core/messagebridge/Outbox.sol +++ b/l1-contracts/src/core/messagebridge/Outbox.sol @@ -24,7 +24,8 @@ contract Outbox is IOutbox { mapping(bytes32 entryKey => DataStructures.Entry entry) internal entries; modifier onlyRollup() { - if (msg.sender != address(REGISTRY.getLatestRollup())) revert Errors.Outbox__Unauthorized(); + // @todo: (issue #624) handle different versions + if (msg.sender != address(REGISTRY.getRollup())) revert Errors.Outbox__Unauthorized(); _; } diff --git a/l1-contracts/src/core/messagebridge/Registry.sol b/l1-contracts/src/core/messagebridge/Registry.sol index 128d2d03686..91204bcd047 100644 --- a/l1-contracts/src/core/messagebridge/Registry.sol +++ b/l1-contracts/src/core/messagebridge/Registry.sol @@ -15,23 +15,45 @@ import {DataStructures} from "@aztec/core/libraries/DataStructures.sol"; */ contract Registry is IRegistry { uint256 public latestVersionNumber; - mapping(uint256 version => DataStructures.Snapshot snapshot) public snapshots; + mapping(uint256 version => DataStructures.RegistrySnapshot snapshot) snapshots; + DataStructures.RegistrySnapshot latestSnapshot; // todo: this function has to be permissioned. function upgrade(address _rollup, address _inbox, address _outbox) public { latestVersionNumber++; - snapshots[latestVersionNumber] = DataStructures.Snapshot(_rollup, _inbox, _outbox, block.number); + DataStructures.RegistrySnapshot memory newSnapshot = + DataStructures.RegistrySnapshot(_rollup, _inbox, _outbox, block.number); + latestSnapshot = newSnapshot; + snapshots[latestVersionNumber] = newSnapshot; } - function getLatestRollup() external view override returns (IRollup) { - return IRollup(snapshots[latestVersionNumber].rollup); + function getRollup() external view override returns (IRollup) { + return IRollup(latestSnapshot.rollup); } - function getLatestInbox() external view override returns (IInbox) { - return IInbox(snapshots[latestVersionNumber].inbox); + function getInbox() external view override returns (IInbox) { + return IInbox(latestSnapshot.inbox); } - function getLatestOutbox() external view override returns (IOutbox) { - return IOutbox(snapshots[latestVersionNumber].outbox); + function getOutbox() external view override returns (IOutbox) { + return IOutbox(latestSnapshot.outbox); + } + + function getSnapshot(uint256 _version) + external + view + override + returns (DataStructures.RegistrySnapshot memory) + { + return snapshots[_version]; + } + + function getLatestSnapshot() + external + view + override + returns (DataStructures.RegistrySnapshot memory) + { + return latestSnapshot; } } diff --git a/l1-contracts/test/portals/RollupNativeAsset.sol b/l1-contracts/test/portals/RollupNativeAsset.sol index c22d9a904f1..b9daf848a53 100644 --- a/l1-contracts/test/portals/RollupNativeAsset.sol +++ b/l1-contracts/test/portals/RollupNativeAsset.sol @@ -28,7 +28,7 @@ contract RollupNativeAsset is ERC20 { }); // @todo: (issue #624) handle different versions - bytes32 entryKey = registry.getLatestOutbox().consume(message); + bytes32 entryKey = registry.getOutbox().consume(message); _mint(_recipient, _amount); diff --git a/l1-contracts/test/portals/TokenPortal.sol b/l1-contracts/test/portals/TokenPortal.sol index 723035a3eca..9e761ce1316 100644 --- a/l1-contracts/test/portals/TokenPortal.sol +++ b/l1-contracts/test/portals/TokenPortal.sol @@ -37,7 +37,7 @@ contract TokenPortal { { // Preamble // @todo: (issue #624) handle different versions - IInbox inbox = registry.getLatestInbox(); + IInbox inbox = registry.getInbox(); DataStructures.L2Actor memory actor = DataStructures.L2Actor(l2TokenAddress, 1); // Hash the message content to be reconstructed in the receiving contract