From b0a8039f5a09acb769c5cbf0cc27d96e8a5fc769 Mon Sep 17 00:00:00 2001 From: Rahul Kothari Date: Fri, 19 May 2023 10:08:06 +0000 Subject: [PATCH 1/4] 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 }, ); From 3dd75257f5fed2b334f722b1ec474fdb1ea1d741 Mon Sep 17 00:00:00 2001 From: Rahul Kothari Date: Mon, 22 May 2023 14:23:36 +0000 Subject: [PATCH 2/4] 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 From 4788aa4598fee250e635088a4fdb59c7585948ba Mon Sep 17 00:00:00 2001 From: Rahul Kothari Date: Mon, 22 May 2023 16:03:35 +0000 Subject: [PATCH 3/4] s/latest/current,add comments --- .../interfaces/messagebridge/IRegistry.sol | 2 +- .../src/core/messagebridge/Registry.sol | 53 ++++++++++++++----- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol b/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol index 44966dcbadd..2035d9d81cd 100644 --- a/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol +++ b/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol @@ -18,5 +18,5 @@ interface IRegistry { view returns (DataStructures.RegistrySnapshot memory); - function getLatestSnapshot() external view returns (DataStructures.RegistrySnapshot memory); + function getCurrentSnapshot() external view returns (DataStructures.RegistrySnapshot memory); } diff --git a/l1-contracts/src/core/messagebridge/Registry.sol b/l1-contracts/src/core/messagebridge/Registry.sol index 91204bcd047..183deb71d44 100644 --- a/l1-contracts/src/core/messagebridge/Registry.sol +++ b/l1-contracts/src/core/messagebridge/Registry.sol @@ -14,31 +14,56 @@ import {DataStructures} from "@aztec/core/libraries/DataStructures.sol"; * @notice Keeps track of important information for L1<>L2 communication. */ contract Registry is IRegistry { - uint256 public latestVersionNumber; - mapping(uint256 version => DataStructures.RegistrySnapshot snapshot) snapshots; - DataStructures.RegistrySnapshot latestSnapshot; + // starts with version 1. Incremented on each upgrade. + uint256 public currentVersion; + DataStructures.RegistrySnapshot internal currentSnapshot; + mapping(uint256 version => DataStructures.RegistrySnapshot snapshot) internal snapshots; // todo: this function has to be permissioned. - function upgrade(address _rollup, address _inbox, address _outbox) public { - latestVersionNumber++; + /** + * Creates a new snapshot of the registry + * @dev starts with version 1. + * @param _rollup - The address of the rollup contract + * @param _inbox - The address of the inbox contract + * @param _outbox - The address of the outbox contract + */ + function upgrade(address _rollup, address _inbox, address _outbox) external { + currentVersion++; DataStructures.RegistrySnapshot memory newSnapshot = DataStructures.RegistrySnapshot(_rollup, _inbox, _outbox, block.number); - latestSnapshot = newSnapshot; - snapshots[latestVersionNumber] = newSnapshot; + currentSnapshot = newSnapshot; + snapshots[currentVersion] = newSnapshot; } + /** + * @notice Returns the rollup contract + * @return The rollup contract (of type IRollup) + */ function getRollup() external view override returns (IRollup) { - return IRollup(latestSnapshot.rollup); + return IRollup(currentSnapshot.rollup); } + /** + * @notice Returns the inbox contract + * @return The inbox contract (of type IInbox) + */ function getInbox() external view override returns (IInbox) { - return IInbox(latestSnapshot.inbox); + return IInbox(currentSnapshot.inbox); } + /** + * @notice Returns the outbox contract + * @return The outbox contract (of type IOutbox) + */ function getOutbox() external view override returns (IOutbox) { - return IOutbox(latestSnapshot.outbox); + return IOutbox(currentSnapshot.outbox); } + /** + * Fetches a snapshot of the registry indicated by `version` + * @param _version - The version of the rollup to return (i.e. which snapshot) + * @return the snapshot + */ function getSnapshot(uint256 _version) external view @@ -48,12 +73,16 @@ contract Registry is IRegistry { return snapshots[_version]; } - function getLatestSnapshot() + /** + * @notice Returns the current snapshot of the registry + * @return The current snapshot + */ + function getCurrentSnapshot() external view override returns (DataStructures.RegistrySnapshot memory) { - return latestSnapshot; + return currentSnapshot; } } From 329e2d03e819171ec6a965a8b9bdf7543946a7e4 Mon Sep 17 00:00:00 2001 From: Rahul Kothari Date: Mon, 22 May 2023 16:26:34 +0000 Subject: [PATCH 4/4] change currentVersion to track numberOfVersions to behave like a counter. --- l1-contracts/src/core/messagebridge/Registry.sol | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/l1-contracts/src/core/messagebridge/Registry.sol b/l1-contracts/src/core/messagebridge/Registry.sol index 183deb71d44..818113648ee 100644 --- a/l1-contracts/src/core/messagebridge/Registry.sol +++ b/l1-contracts/src/core/messagebridge/Registry.sol @@ -14,25 +14,22 @@ import {DataStructures} from "@aztec/core/libraries/DataStructures.sol"; * @notice Keeps track of important information for L1<>L2 communication. */ contract Registry is IRegistry { - // starts with version 1. Incremented on each upgrade. - uint256 public currentVersion; + uint256 public numberOfVersions; DataStructures.RegistrySnapshot internal currentSnapshot; mapping(uint256 version => DataStructures.RegistrySnapshot snapshot) internal snapshots; // todo: this function has to be permissioned. /** - * Creates a new snapshot of the registry - * @dev starts with version 1. + * @notice Creates a new snapshot of the registry * @param _rollup - The address of the rollup contract * @param _inbox - The address of the inbox contract * @param _outbox - The address of the outbox contract */ function upgrade(address _rollup, address _inbox, address _outbox) external { - currentVersion++; DataStructures.RegistrySnapshot memory newSnapshot = DataStructures.RegistrySnapshot(_rollup, _inbox, _outbox, block.number); currentSnapshot = newSnapshot; - snapshots[currentVersion] = newSnapshot; + snapshots[numberOfVersions++] = newSnapshot; } /** @@ -60,7 +57,8 @@ contract Registry is IRegistry { } /** - * Fetches a snapshot of the registry indicated by `version` + * @notice Fetches a snapshot of the registry indicated by `version` + * @dev the version is 0 indexed, so the first snapshot is version 0. * @param _version - The version of the rollup to return (i.e. which snapshot) * @return the snapshot */