diff --git a/l1-contracts/src/core/Rollup.sol b/l1-contracts/src/core/Rollup.sol index 74e542c5343..85571006e3e 100644 --- a/l1-contracts/src/core/Rollup.sol +++ b/l1-contracts/src/core/Rollup.sol @@ -61,9 +61,11 @@ contract Rollup is Decoder { rollupStateHash = newStateHash; // @todo (issue #605) handle fee collector + // @todo: (issue #624) handle different versions IInbox inbox = REGISTRY.getInbox(); inbox.batchConsume(l1ToL2Msgs, msg.sender); + // @todo: (issue #624) handle different versions IOutbox outbox = REGISTRY.getOutbox(); outbox.sendL1Messages(l2ToL1Msgs); diff --git a/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol b/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol index d6b40e7d3dd..2035d9d81cd 100644 --- a/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol +++ b/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol @@ -7,11 +7,16 @@ import {IInbox} from "./IInbox.sol"; import {IOutbox} from "./IOutbox.sol"; interface IRegistry { - function getL1L2Addresses() external view returns (DataStructures.L1L2Addresses memory); - function getRollup() external view returns (IRollup); function getInbox() external view returns (IInbox); function getOutbox() external view returns (IOutbox); + + function getSnapshot(uint256 _version) + external + view + returns (DataStructures.RegistrySnapshot memory); + + function getCurrentSnapshot() 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 8de6b40d8f0..2325f7a4e77 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 RegistrySnapshot { 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..45e328aabdb 100644 --- a/l1-contracts/src/core/messagebridge/Inbox.sol +++ b/l1-contracts/src/core/messagebridge/Inbox.sol @@ -24,6 +24,7 @@ contract Inbox is IInbox { mapping(address account => uint256 balance) public feesAccrued; modifier onlyRollup() { + // @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 b590adf0fbf..6249531e10b 100644 --- a/l1-contracts/src/core/messagebridge/Outbox.sol +++ b/l1-contracts/src/core/messagebridge/Outbox.sol @@ -24,6 +24,7 @@ contract Outbox is IOutbox { mapping(bytes32 entryKey => DataStructures.Entry entry) internal entries; modifier onlyRollup() { + // @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 643947bc78e..818113648ee 100644 --- a/l1-contracts/src/core/messagebridge/Registry.sol +++ b/l1-contracts/src/core/messagebridge/Registry.sol @@ -14,28 +14,73 @@ 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 numberOfVersions; + DataStructures.RegistrySnapshot internal currentSnapshot; + mapping(uint256 version => DataStructures.RegistrySnapshot snapshot) internal 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. + /** + * @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 { + DataStructures.RegistrySnapshot memory newSnapshot = + DataStructures.RegistrySnapshot(_rollup, _inbox, _outbox, block.number); + currentSnapshot = newSnapshot; + snapshots[numberOfVersions++] = newSnapshot; } + /** + * @notice Returns the rollup contract + * @return The rollup contract (of type IRollup) + */ function getRollup() external view override returns (IRollup) { - return IRollup(addresses.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(addresses.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(addresses.outbox); + return IOutbox(currentSnapshot.outbox); + } + + /** + * @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 + */ + function getSnapshot(uint256 _version) + external + view + override + returns (DataStructures.RegistrySnapshot memory) + { + return snapshots[_version]; + } + + /** + * @notice Returns the current snapshot of the registry + * @return The current snapshot + */ + function getCurrentSnapshot() + external + view + override + returns (DataStructures.RegistrySnapshot memory) + { + return currentSnapshot; } } 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..b9daf848a53 100644 --- a/l1-contracts/test/portals/RollupNativeAsset.sol +++ b/l1-contracts/test/portals/RollupNativeAsset.sol @@ -27,6 +27,7 @@ contract RollupNativeAsset is ERC20 { ) }); + // @todo: (issue #624) handle different versions 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 11d43a21c71..9e761ce1316 100644 --- a/l1-contracts/test/portals/TokenPortal.sol +++ b/l1-contracts/test/portals/TokenPortal.sol @@ -36,6 +36,7 @@ contract TokenPortal { returns (bytes32) { // Preamble + // @todo: (issue #624) handle different versions IInbox inbox = registry.getInbox(); DataStructures.L2Actor memory actor = DataStructures.L2Actor(l2TokenAddress, 1); 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 }, );