From b0a8039f5a09acb769c5cbf0cc27d96e8a5fc769 Mon Sep 17 00:00:00 2001 From: Rahul Kothari Date: Fri, 19 May 2023 10:08:06 +0000 Subject: [PATCH] fix #526 --- l1-contracts/src/core/Rollup.sol | 6 ++-- .../interfaces/messagebridge/IRegistry.sol | 8 ++---- .../src/core/libraries/DataStructures.sol | 6 ++-- l1-contracts/src/core/messagebridge/Inbox.sol | 2 +- .../src/core/messagebridge/Outbox.sol | 2 +- .../src/core/messagebridge/Registry.sol | 28 ++++++++----------- l1-contracts/test/Inbox.t.sol | 2 +- l1-contracts/test/Outbox.t.sol | 2 +- l1-contracts/test/Rollup.t.sol | 2 +- l1-contracts/test/portals/RNA.t.sol | 2 +- .../test/portals/RollupNativeAsset.sol | 3 +- l1-contracts/test/portals/TokenPortal.sol | 3 +- l1-contracts/test/portals/TokenPortal.t.sol | 2 +- .../end-to-end/src/deploy_l1_contracts.ts | 2 +- 14 files changed, 35 insertions(+), 35 deletions(-) diff --git a/l1-contracts/src/core/Rollup.sol b/l1-contracts/src/core/Rollup.sol index 74e542c5343..7be225b8493 100644 --- a/l1-contracts/src/core/Rollup.sol +++ b/l1-contracts/src/core/Rollup.sol @@ -61,10 +61,12 @@ contract Rollup is Decoder { rollupStateHash = newStateHash; // @todo (issue #605) handle fee collector - IInbox inbox = REGISTRY.getInbox(); + // @todo: (issue #624) handle different versions + IInbox inbox = REGISTRY.getLatestInbox(); inbox.batchConsume(l1ToL2Msgs, msg.sender); - IOutbox outbox = REGISTRY.getOutbox(); + // @todo: (issue #624) handle different versions + IOutbox outbox = REGISTRY.getLatestOutbox(); 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 d6b40e7d3dd..1ca00ddde47 100644 --- a/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol +++ b/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol @@ -7,11 +7,9 @@ import {IInbox} from "./IInbox.sol"; import {IOutbox} from "./IOutbox.sol"; interface IRegistry { - function getL1L2Addresses() external view returns (DataStructures.L1L2Addresses memory); + 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 getOutbox() external view returns (IOutbox); + function getLatestOutbox() external view returns (IOutbox); } diff --git a/l1-contracts/src/core/libraries/DataStructures.sol b/l1-contracts/src/core/libraries/DataStructures.sol index 8de6b40d8f0..5314aeeb1ee 100644 --- a/l1-contracts/src/core/libraries/DataStructures.sol +++ b/l1-contracts/src/core/libraries/DataStructures.sol @@ -65,14 +65,16 @@ library DataStructures { } /** - * @notice Struct for storing address of cross communication components + * @notice Struct for storing address of cross communication components and the block number when it was updated * @param rollup - The address of the rollup contract * @param inbox - The address of the inbox contract * @param outbox - The address of the outbox contract + * @param blockNumber - The block number of the snapshot */ - struct L1L2Addresses { + struct Snapshot { address rollup; address inbox; address outbox; + uint256 blockNumber; } } diff --git a/l1-contracts/src/core/messagebridge/Inbox.sol b/l1-contracts/src/core/messagebridge/Inbox.sol index f80ecf3aed9..e88b73395dd 100644 --- a/l1-contracts/src/core/messagebridge/Inbox.sol +++ b/l1-contracts/src/core/messagebridge/Inbox.sol @@ -24,7 +24,7 @@ contract Inbox is IInbox { mapping(address account => uint256 balance) public feesAccrued; modifier onlyRollup() { - if (msg.sender != address(REGISTRY.getRollup())) revert Errors.Inbox__Unauthorized(); + if (msg.sender != address(REGISTRY.getLatestRollup())) revert Errors.Inbox__Unauthorized(); _; } diff --git a/l1-contracts/src/core/messagebridge/Outbox.sol b/l1-contracts/src/core/messagebridge/Outbox.sol index b590adf0fbf..fe2596c2dcd 100644 --- a/l1-contracts/src/core/messagebridge/Outbox.sol +++ b/l1-contracts/src/core/messagebridge/Outbox.sol @@ -24,7 +24,7 @@ contract Outbox is IOutbox { mapping(bytes32 entryKey => DataStructures.Entry entry) internal entries; modifier onlyRollup() { - if (msg.sender != address(REGISTRY.getRollup())) revert Errors.Outbox__Unauthorized(); + if (msg.sender != address(REGISTRY.getLatestRollup())) revert Errors.Outbox__Unauthorized(); _; } diff --git a/l1-contracts/src/core/messagebridge/Registry.sol b/l1-contracts/src/core/messagebridge/Registry.sol index 643947bc78e..128d2d03686 100644 --- a/l1-contracts/src/core/messagebridge/Registry.sol +++ b/l1-contracts/src/core/messagebridge/Registry.sol @@ -14,28 +14,24 @@ import {DataStructures} from "@aztec/core/libraries/DataStructures.sol"; * @notice Keeps track of important information for L1<>L2 communication. */ contract Registry is IRegistry { - // TODO(rahul) - https://github.com/AztecProtocol/aztec-packages/issues/526 - // Need to create a snashot of addresses per version! + uint256 public latestVersionNumber; + mapping(uint256 version => DataStructures.Snapshot snapshot) public snapshots; - DataStructures.L1L2Addresses public addresses; - - function setAddresses(address _rollup, address _inbox, address _outbox) public { - addresses = DataStructures.L1L2Addresses(_rollup, _inbox, _outbox); - } - - function getL1L2Addresses() external view override returns (DataStructures.L1L2Addresses memory) { - return addresses; + // 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); } - function getRollup() external view override returns (IRollup) { - return IRollup(addresses.rollup); + function getLatestRollup() external view override returns (IRollup) { + return IRollup(snapshots[latestVersionNumber].rollup); } - function getInbox() external view override returns (IInbox) { - return IInbox(addresses.inbox); + function getLatestInbox() external view override returns (IInbox) { + return IInbox(snapshots[latestVersionNumber].inbox); } - function getOutbox() external view override returns (IOutbox) { - return IOutbox(addresses.outbox); + function getLatestOutbox() external view override returns (IOutbox) { + return IOutbox(snapshots[latestVersionNumber].outbox); } } diff --git a/l1-contracts/test/Inbox.t.sol b/l1-contracts/test/Inbox.t.sol index 54acde05c57..9de6cbb8563 100644 --- a/l1-contracts/test/Inbox.t.sol +++ b/l1-contracts/test/Inbox.t.sol @@ -31,7 +31,7 @@ contract InboxTest is Test { address rollup = address(this); Registry registry = new Registry(); inbox = new Inbox(address(registry)); - registry.setAddresses(rollup, address(inbox), address(0x0)); + registry.upgrade(rollup, address(inbox), address(0x0)); } function _fakeMessage() internal view returns (DataStructures.L1ToL2Msg memory) { diff --git a/l1-contracts/test/Outbox.t.sol b/l1-contracts/test/Outbox.t.sol index 10bff3016e9..eccac632fdc 100644 --- a/l1-contracts/test/Outbox.t.sol +++ b/l1-contracts/test/Outbox.t.sol @@ -20,7 +20,7 @@ contract OutboxTest is Test { address rollup = address(this); Registry registry = new Registry(); outbox = new Outbox(address(registry)); - registry.setAddresses(rollup, address(0x0), address(outbox)); + registry.upgrade(rollup, address(0x0), address(outbox)); } function _fakeMessage() internal view returns (DataStructures.L2ToL1Msg memory) { diff --git a/l1-contracts/test/Rollup.t.sol b/l1-contracts/test/Rollup.t.sol index 5961818ae75..4fbbffc03c3 100644 --- a/l1-contracts/test/Rollup.t.sol +++ b/l1-contracts/test/Rollup.t.sol @@ -32,7 +32,7 @@ contract RollupTest is DecoderTest { outbox = new Outbox(address(registry)); rollup = new Rollup(registry); - registry.setAddresses(address(rollup), address(inbox), address(outbox)); + registry.upgrade(address(rollup), address(inbox), address(outbox)); } function testEmptyBlock() public override(DecoderTest) { diff --git a/l1-contracts/test/portals/RNA.t.sol b/l1-contracts/test/portals/RNA.t.sol index 77fc0965c4a..94335accd10 100644 --- a/l1-contracts/test/portals/RNA.t.sol +++ b/l1-contracts/test/portals/RNA.t.sol @@ -34,7 +34,7 @@ contract RNATest is Test { inbox = new Inbox(address(registry)); rollup = new Rollup(registry); - registry.setAddresses(address(rollup), address(inbox), address(outbox)); + registry.upgrade(address(rollup), address(inbox), address(outbox)); rna = new RollupNativeAsset(); // Essentially deploying the rna contract on the 0xbeef address to make matching entry easy. diff --git a/l1-contracts/test/portals/RollupNativeAsset.sol b/l1-contracts/test/portals/RollupNativeAsset.sol index 5b7d4217a0d..c22d9a904f1 100644 --- a/l1-contracts/test/portals/RollupNativeAsset.sol +++ b/l1-contracts/test/portals/RollupNativeAsset.sol @@ -27,7 +27,8 @@ contract RollupNativeAsset is ERC20 { ) }); - bytes32 entryKey = registry.getOutbox().consume(message); + // @todo: (issue #624) handle different versions + bytes32 entryKey = registry.getLatestOutbox().consume(message); _mint(_recipient, _amount); diff --git a/l1-contracts/test/portals/TokenPortal.sol b/l1-contracts/test/portals/TokenPortal.sol index 11d43a21c71..723035a3eca 100644 --- a/l1-contracts/test/portals/TokenPortal.sol +++ b/l1-contracts/test/portals/TokenPortal.sol @@ -36,7 +36,8 @@ contract TokenPortal { returns (bytes32) { // Preamble - IInbox inbox = registry.getInbox(); + // @todo: (issue #624) handle different versions + IInbox inbox = registry.getLatestInbox(); DataStructures.L2Actor memory actor = DataStructures.L2Actor(l2TokenAddress, 1); // Hash the message content to be reconstructed in the receiving contract diff --git a/l1-contracts/test/portals/TokenPortal.t.sol b/l1-contracts/test/portals/TokenPortal.t.sol index 620e6d9802a..4f4b5553f5b 100644 --- a/l1-contracts/test/portals/TokenPortal.t.sol +++ b/l1-contracts/test/portals/TokenPortal.t.sol @@ -45,7 +45,7 @@ contract TokenPortalTest is Test { outbox = new Outbox(address(registry)); rollup = new Rollup(registry); - registry.setAddresses(address(rollup), address(inbox), address(outbox)); + registry.upgrade(address(rollup), address(inbox), address(outbox)); portalERC20 = new PortalERC20(); tokenPortal = new TokenPortal(); diff --git a/yarn-project/end-to-end/src/deploy_l1_contracts.ts b/yarn-project/end-to-end/src/deploy_l1_contracts.ts index e77f471cf53..46a2df7df72 100644 --- a/yarn-project/end-to-end/src/deploy_l1_contracts.ts +++ b/yarn-project/end-to-end/src/deploy_l1_contracts.ts @@ -120,7 +120,7 @@ export const deployL1Contracts = async ( publicClient, walletClient, }); - await registryContract.write.setAddresses( + await registryContract.write.upgrade( [getAddress(rollupAddress.toString()), getAddress(inboxAddress.toString()), getAddress(outboxAddress.toString())], { account }, );