From 26a886da6327503f37395abaf48cd8298d932362 Mon Sep 17 00:00:00 2001 From: LHerskind Date: Tue, 13 Aug 2024 13:57:38 +0000 Subject: [PATCH] refactor: simplify registry --- .../portals/registry.md | 26 +------------ l1-contracts/src/core/interfaces/IRollup.sol | 7 ++++ .../interfaces/messagebridge/IRegistry.sol | 12 +----- .../src/core/libraries/DataStructures.sol | 4 -- .../src/core/messagebridge/Registry.sol | 37 +++---------------- l1-contracts/test/Registry.t.sol | 18 ++------- l1-contracts/test/Rollup.t.sol | 2 +- l1-contracts/test/portals/FeeJuicePortal.sol | 2 +- l1-contracts/test/portals/TokenPortal.sol | 6 +-- l1-contracts/test/portals/TokenPortal.t.sol | 2 +- l1-contracts/test/portals/UniswapPortal.sol | 4 +- l1-contracts/test/portals/UniswapPortal.t.sol | 10 ++--- l1-contracts/test/sparta/DevNet.t.sol | 2 +- l1-contracts/test/sparta/Sparta.t.sol | 2 +- .../ethereum/src/deploy_l1_contracts.ts | 5 +-- 15 files changed, 34 insertions(+), 105 deletions(-) diff --git a/docs/docs/reference/developer_references/smart_contract_reference/portals/registry.md b/docs/docs/reference/developer_references/smart_contract_reference/portals/registry.md index 7de03b9354f..337fd7e4bad 100644 --- a/docs/docs/reference/developer_references/smart_contract_reference/portals/registry.md +++ b/docs/docs/reference/developer_references/smart_contract_reference/portals/registry.md @@ -3,7 +3,7 @@ title: Registry tags: [portals, contracts] --- -The registry is a contract deployed on L1, that contains addresses for the `Rollup`, `Inbox` and `Outbox`. It also keeps track of the different versions that have been deployed and let you query prior deployments easily. +The registry is a contract deployed on L1, that contains addresses for the `Rollup`. It also keeps track of the different versions that have been deployed and let you query prior deployments easily. **Links**: [Interface (GitHub link)](https://github.com/AztecProtocol/aztec-packages/blob/master/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol), [Implementation (GitHub link)](https://github.com/AztecProtocol/aztec-packages/blob/master/l1-contracts/src/core/messagebridge/Registry.sol). @@ -26,26 +26,6 @@ Retrieves the current rollup contract. | -------------- | ----------- | | ReturnValue | The current rollup | -## `getInbox()` - -Retrieves the current inbox contract. - -#include_code registry_get_inbox l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol solidity - -| Name | Description | -| -------------- | ----------- | -| ReturnValue | The current Inbox | - -## `getOutbox()` - -Retrieves the current inbox contract. - -#include_code registry_get_outbox l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol solidity - -| Name | Description | -| -------------- | ----------- | -| ReturnValue | The current Outbox | - ## `getVersionFor(address _rollup)` Retrieve the version of a specific rollup contract. @@ -71,8 +51,6 @@ Retrieve the snapshot of a specific version. | -------------- | ----------- | | `_version` | The version number to fetch data for | | ReturnValue.rollup | The address of the `rollup` for the `_version` | -| ReturnValue.inbox | The address of the `inbox` for the `_version` | -| ReturnValue.outbox | The address of the `outbox` for the `_version` | | ReturnValue.blockNumber | The block number of the snapshot creation | @@ -85,7 +63,5 @@ Retrieves the snapshot for the current version. | Name | Description | | -------------- | ----------- | | ReturnValue.rollup | The address of the `rollup` for the current `_version` | -| ReturnValue.inbox | The address of the `inbox` for the current `_version` | -| ReturnValue.outbox | The address of the `outbox` for the current `_version` | | ReturnValue.blockNumber | The block number of the snapshot creation | diff --git a/l1-contracts/src/core/interfaces/IRollup.sol b/l1-contracts/src/core/interfaces/IRollup.sol index a8a9eb947bd..62d2cdd80b3 100644 --- a/l1-contracts/src/core/interfaces/IRollup.sol +++ b/l1-contracts/src/core/interfaces/IRollup.sol @@ -2,6 +2,9 @@ // Copyright 2023 Aztec Labs. pragma solidity >=0.8.18; +import {IInbox} from "../interfaces/messagebridge/IInbox.sol"; +import {IOutbox} from "../interfaces/messagebridge/IOutbox.sol"; + import {SignatureLib} from "../sequencer_selection/SignatureLib.sol"; interface ITestRollup { @@ -15,6 +18,10 @@ interface IRollup { event L2ProofVerified(uint256 indexed blockNumber, bytes32 indexed proverId); event ProgressedState(uint256 provenBlockCount, uint256 pendingBlockCount); + function INBOX() external view returns (IInbox); + + function OUTBOX() external view returns (IOutbox); + function publishAndProcess( bytes calldata _header, bytes32 _archive, diff --git a/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol b/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol index 0d184a521f2..3de70063340 100644 --- a/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol +++ b/l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol @@ -3,12 +3,10 @@ pragma solidity >=0.8.18; import {DataStructures} from "../../libraries/DataStructures.sol"; import {IRollup} from "../IRollup.sol"; -import {IInbox} from "./IInbox.sol"; -import {IOutbox} from "./IOutbox.sol"; interface IRegistry { // docs:start:registry_upgrade - function upgrade(address _rollup, address _inbox, address _outbox) external returns (uint256); + function upgrade(address _rollup) external returns (uint256); // docs:end:registry_upgrade // docs:start:registry_get_rollup @@ -19,14 +17,6 @@ interface IRegistry { function getVersionFor(address _rollup) external view returns (uint256); // docs:end:registry_get_version_for - // docs:start:registry_get_inbox - function getInbox() external view returns (IInbox); - // docs:end:registry_get_inbox - - // docs:start:registry_get_outbox - function getOutbox() external view returns (IOutbox); - // docs:end:registry_get_outbox - // docs:start:registry_get_snapshot function getSnapshot(uint256 _version) external diff --git a/l1-contracts/src/core/libraries/DataStructures.sol b/l1-contracts/src/core/libraries/DataStructures.sol index 00367bf0319..0bdc315b6de 100644 --- a/l1-contracts/src/core/libraries/DataStructures.sol +++ b/l1-contracts/src/core/libraries/DataStructures.sol @@ -67,14 +67,10 @@ library DataStructures { /** * @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 RegistrySnapshot { address rollup; - address inbox; - address outbox; uint256 blockNumber; } // docs:end:registry_snapshot diff --git a/l1-contracts/src/core/messagebridge/Registry.sol b/l1-contracts/src/core/messagebridge/Registry.sol index c24be6e5dd2..98cb60a4b89 100644 --- a/l1-contracts/src/core/messagebridge/Registry.sol +++ b/l1-contracts/src/core/messagebridge/Registry.sol @@ -7,8 +7,6 @@ import {Ownable} from "@oz/access/Ownable.sol"; // Interfaces import {IRegistry} from "../interfaces/messagebridge/IRegistry.sol"; import {IRollup} from "../interfaces/IRollup.sol"; -import {IInbox} from "../interfaces/messagebridge/IInbox.sol"; -import {IOutbox} from "../interfaces/messagebridge/IOutbox.sol"; // Libraries import {DataStructures} from "../libraries/DataStructures.sol"; @@ -17,9 +15,7 @@ import {Errors} from "../libraries/Errors.sol"; /** * @title Registry * @author Aztec Labs - * @notice Keeps track of addresses of rollup, inbox and outbox as well as historical addresses. - * Used as the source of truth for finding the "head" of the rollup chain. Very important information - * for L1<->L2 communication. + * @notice Keeps track of addresses of current rollup and historical addresses. */ contract Registry is IRegistry, Ownable { uint256 public override(IRegistry) numberOfVersions; @@ -29,9 +25,9 @@ contract Registry is IRegistry, Ownable { mapping(address rollup => uint256 version) internal rollupToVersion; constructor() Ownable(msg.sender) { - // Inserts a "dead" rollup and message boxes at version 0 + // Inserts a "dead" rollup at version 0 // This is simply done to make first version 1, which fits better with the rest of the system - upgrade(address(0xdead), address(0xdead), address(0xdead)); + upgrade(address(0xdead)); } /** @@ -53,22 +49,6 @@ contract Registry is IRegistry, Ownable { return version; } - /** - * @notice Returns the inbox contract - * @return The inbox contract (of type IInbox) - */ - function getInbox() external view override(IRegistry) returns (IInbox) { - return IInbox(currentSnapshot.inbox); - } - - /** - * @notice Returns the outbox contract - * @return The outbox contract (of type IOutbox) - */ - function getOutbox() external view override(IRegistry) returns (IOutbox) { - 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. @@ -104,21 +84,14 @@ contract Registry is IRegistry, Ownable { * @dev Reverts if the rollup is already registered * * @param _rollup - The address of the rollup contract - * @param _inbox - The address of the inbox contract - * @param _outbox - The address of the outbox contract * @return The version of the new snapshot */ - function upgrade(address _rollup, address _inbox, address _outbox) - public - override(IRegistry) - onlyOwner - returns (uint256) - { + function upgrade(address _rollup) public override(IRegistry) onlyOwner returns (uint256) { (, bool exists) = _getVersionFor(_rollup); if (exists) revert Errors.Registry__RollupAlreadyRegistered(_rollup); DataStructures.RegistrySnapshot memory newSnapshot = - DataStructures.RegistrySnapshot(_rollup, _inbox, _outbox, block.number); + DataStructures.RegistrySnapshot(_rollup, block.number); currentSnapshot = newSnapshot; uint256 version = numberOfVersions++; snapshots[version] = newSnapshot; diff --git a/l1-contracts/test/Registry.t.sol b/l1-contracts/test/Registry.t.sol index d6e70fd3349..df6b03e7eb3 100644 --- a/l1-contracts/test/Registry.t.sol +++ b/l1-contracts/test/Registry.t.sol @@ -22,11 +22,7 @@ contract RegistryTest is Test { assertEq(registry.numberOfVersions(), 1, "should have 1 version"); DataStructures.RegistrySnapshot memory snapshot = registry.getCurrentSnapshot(); assertEq(snapshot.rollup, DEAD, "should have dead rollup"); - assertEq(snapshot.inbox, DEAD, "should have dead inbox"); - assertEq(snapshot.outbox, DEAD, "should have dead outbox"); assertEq(address(registry.getRollup()), DEAD); - assertEq(address(registry.getInbox()), DEAD); - assertEq(address(registry.getOutbox()), DEAD); vm.expectRevert(abi.encodeWithSelector(Errors.Registry__RollupNotRegistered.selector, DEAD)); registry.getVersionFor(DEAD); @@ -34,28 +30,22 @@ contract RegistryTest is Test { function testUpgrade() public { address newRollup = address(0xbeef1); - address inbox = address(0xbeef2); - address newOutbox = address(0xbeef3); - uint256 newVersion = registry.upgrade(newRollup, inbox, newOutbox); + uint256 newVersion = registry.upgrade(newRollup); assertEq(registry.numberOfVersions(), 2, "should have 2 versions"); DataStructures.RegistrySnapshot memory snapshot = registry.getCurrentSnapshot(); assertEq(snapshot.rollup, newRollup, "should have newRollup"); - assertEq(snapshot.inbox, inbox, "should have inbox"); - assertEq(snapshot.outbox, newOutbox, "should have newOutbox"); assertEq(address(registry.getRollup()), newRollup); - assertEq(address(registry.getInbox()), inbox); - assertEq(address(registry.getOutbox()), newOutbox); assertEq( registry.getVersionFor(newRollup), newVersion, "should have version newVersion for newRollup" ); } function testRevertUpgradeToSame() public { - registry.upgrade(DEAD, DEAD, DEAD); + registry.upgrade(DEAD); vm.expectRevert(abi.encodeWithSelector(Errors.Registry__RollupAlreadyRegistered.selector, DEAD)); - registry.upgrade(DEAD, DEAD, DEAD); + registry.upgrade(DEAD); } function testRevertGetVersionForNonExistent() public { @@ -68,6 +58,6 @@ contract RegistryTest is Test { vm.assume(_owner != registry.owner()); vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, _owner)); vm.prank(_owner); - registry.upgrade(DEAD, DEAD, DEAD); + registry.upgrade(DEAD); } } diff --git a/l1-contracts/test/Rollup.t.sol b/l1-contracts/test/Rollup.t.sol index 72f555a30fb..4943e67a02a 100644 --- a/l1-contracts/test/Rollup.t.sol +++ b/l1-contracts/test/Rollup.t.sol @@ -57,7 +57,7 @@ contract RollupTest is DecoderBase { inbox = Inbox(address(rollup.INBOX())); outbox = Outbox(address(rollup.OUTBOX())); - registry.upgrade(address(rollup), address(inbox), address(outbox)); + registry.upgrade(address(rollup)); // mint some tokens to the rollup portalERC20.mint(address(rollup), 1000000); diff --git a/l1-contracts/test/portals/FeeJuicePortal.sol b/l1-contracts/test/portals/FeeJuicePortal.sol index da5e40b5e68..75518c743c8 100644 --- a/l1-contracts/test/portals/FeeJuicePortal.sol +++ b/l1-contracts/test/portals/FeeJuicePortal.sol @@ -39,7 +39,7 @@ contract FeeJuicePortal { returns (bytes32) { // Preamble - IInbox inbox = registry.getInbox(); + IInbox inbox = registry.getRollup().INBOX(); 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.sol b/l1-contracts/test/portals/TokenPortal.sol index 1553673d1ef..ce9f4408b52 100644 --- a/l1-contracts/test/portals/TokenPortal.sol +++ b/l1-contracts/test/portals/TokenPortal.sol @@ -40,7 +40,7 @@ contract TokenPortal { returns (bytes32) { // Preamble - IInbox inbox = registry.getInbox(); + IInbox inbox = registry.getRollup().INBOX(); DataStructures.L2Actor memory actor = DataStructures.L2Actor(l2Bridge, 1); // Hash the message content to be reconstructed in the receiving contract @@ -69,7 +69,7 @@ contract TokenPortal { bytes32 _secretHashForL2MessageConsumption ) external returns (bytes32) { // Preamble - IInbox inbox = registry.getInbox(); + IInbox inbox = registry.getRollup().INBOX(); DataStructures.L2Actor memory actor = DataStructures.L2Actor(l2Bridge, 1); // Hash the message content to be reconstructed in the receiving contract @@ -120,7 +120,7 @@ contract TokenPortal { ) }); - IOutbox outbox = registry.getOutbox(); + IOutbox outbox = registry.getRollup().OUTBOX(); outbox.consume(message, _l2BlockNumber, _leafIndex, _path); diff --git a/l1-contracts/test/portals/TokenPortal.t.sol b/l1-contracts/test/portals/TokenPortal.t.sol index ad48731f4ef..cff3b21f940 100644 --- a/l1-contracts/test/portals/TokenPortal.t.sol +++ b/l1-contracts/test/portals/TokenPortal.t.sol @@ -64,7 +64,7 @@ contract TokenPortalTest is Test { inbox = rollup.INBOX(); outbox = rollup.OUTBOX(); - registry.upgrade(address(rollup), address(inbox), address(outbox)); + registry.upgrade(address(rollup)); portalERC20.mint(address(rollup), 1000000); tokenPortal = new TokenPortal(); diff --git a/l1-contracts/test/portals/UniswapPortal.sol b/l1-contracts/test/portals/UniswapPortal.sol index 2fad905b7e9..26ba79b78dc 100644 --- a/l1-contracts/test/portals/UniswapPortal.sol +++ b/l1-contracts/test/portals/UniswapPortal.sol @@ -103,7 +103,7 @@ contract UniswapPortal { // Consume the message from the outbox { - IOutbox outbox = registry.getOutbox(); + IOutbox outbox = registry.getRollup().OUTBOX(); outbox.consume( DataStructures.L2ToL1Msg({ @@ -209,7 +209,7 @@ contract UniswapPortal { // Consume the message from the outbox { - IOutbox outbox = registry.getOutbox(); + IOutbox outbox = registry.getRollup().OUTBOX(); outbox.consume( DataStructures.L2ToL1Msg({ diff --git a/l1-contracts/test/portals/UniswapPortal.t.sol b/l1-contracts/test/portals/UniswapPortal.t.sol index df5fcf2e0cd..0e57a485586 100644 --- a/l1-contracts/test/portals/UniswapPortal.t.sol +++ b/l1-contracts/test/portals/UniswapPortal.t.sol @@ -31,6 +31,8 @@ contract UniswapPortalTest is Test { Rollup internal rollup; Registry internal registry; + + IOutbox internal outbox; bytes32 internal l2TokenAddress = bytes32(uint256(0x1)); bytes32 internal l2UniswapAddress = bytes32(uint256(0x2)); @@ -54,7 +56,7 @@ contract UniswapPortalTest is Test { PortalERC20 portalERC20 = new PortalERC20(); rollup = new Rollup(registry, new AvailabilityOracle(), IERC20(address(portalERC20)), bytes32(0)); - registry.upgrade(address(rollup), address(rollup.INBOX()), address(rollup.OUTBOX())); + registry.upgrade(address(rollup)); portalERC20.mint(address(rollup), 1000000); daiTokenPortal = new TokenPortal(); @@ -68,6 +70,8 @@ contract UniswapPortalTest is Test { // have DAI locked in portal that can be moved when funds are withdrawn deal(address(DAI), address(daiTokenPortal), amount); + + outbox = rollup.OUTBOX(); } /** @@ -169,8 +173,6 @@ contract UniswapPortalTest is Test { (bytes32[] memory withdrawSiblingPath,) = tree.computeSiblingPath(0); (bytes32[] memory swapSiblingPath,) = tree.computeSiblingPath(1); - IOutbox outbox = registry.getOutbox(); - vm.prank(address(rollup)); outbox.insert(_l2BlockNumber, treeRoot, treeHeight); @@ -392,7 +394,6 @@ contract UniswapPortalTest is Test { // there should be some weth in the weth portal assertGt(WETH9.balanceOf(address(wethTokenPortal)), 0); // there the message should be nullified at index 0 and 1 - IOutbox outbox = registry.getOutbox(); assertTrue(outbox.hasMessageBeenConsumedAtBlockAndIndex(l2BlockNumber, 0)); assertTrue(outbox.hasMessageBeenConsumedAtBlockAndIndex(l2BlockNumber, 1)); } @@ -440,7 +441,6 @@ contract UniswapPortalTest is Test { // there should be some weth in the weth portal assertGt(WETH9.balanceOf(address(wethTokenPortal)), 0); // there should be no message in the outbox: - IOutbox outbox = registry.getOutbox(); assertTrue(outbox.hasMessageBeenConsumedAtBlockAndIndex(l2BlockNumber, 0)); assertTrue(outbox.hasMessageBeenConsumedAtBlockAndIndex(l2BlockNumber, 1)); } diff --git a/l1-contracts/test/sparta/DevNet.t.sol b/l1-contracts/test/sparta/DevNet.t.sol index f9461f42af3..5f17191dc62 100644 --- a/l1-contracts/test/sparta/DevNet.t.sol +++ b/l1-contracts/test/sparta/DevNet.t.sol @@ -64,7 +64,7 @@ contract DevNetTest is DecoderBase { inbox = Inbox(address(rollup.INBOX())); outbox = Outbox(address(rollup.OUTBOX())); - registry.upgrade(address(rollup), address(inbox), address(outbox)); + registry.upgrade(address(rollup)); // mint some tokens to the rollup portalERC20.mint(address(rollup), 1000000); diff --git a/l1-contracts/test/sparta/Sparta.t.sol b/l1-contracts/test/sparta/Sparta.t.sol index a77651ad31e..20f8b60d8cb 100644 --- a/l1-contracts/test/sparta/Sparta.t.sol +++ b/l1-contracts/test/sparta/Sparta.t.sol @@ -67,7 +67,7 @@ contract SpartaTest is DecoderBase { inbox = Inbox(address(rollup.INBOX())); outbox = Outbox(address(rollup.OUTBOX())); - registry.upgrade(address(rollup), address(inbox), address(outbox)); + registry.upgrade(address(rollup)); // mint some tokens to the rollup portalERC20.mint(address(rollup), 1000000); diff --git a/yarn-project/ethereum/src/deploy_l1_contracts.ts b/yarn-project/ethereum/src/deploy_l1_contracts.ts index 218efe18178..00a5faff592 100644 --- a/yarn-project/ethereum/src/deploy_l1_contracts.ts +++ b/yarn-project/ethereum/src/deploy_l1_contracts.ts @@ -253,10 +253,7 @@ export const deployL1Contracts = async ( abi: contractsToDeploy.registry.contractAbi, client: walletClient, }); - await registryContract.write.upgrade( - [getAddress(rollupAddress.toString()), getAddress(inboxAddress.toString()), getAddress(outboxAddress.toString())], - { account }, - ); + await registryContract.write.upgrade([getAddress(rollupAddress.toString())], { account }); // this contract remains uninitialized because at this point we don't know the address of the Fee Juice on L2 const feeJuicePortalAddress = await deployL1Contract(