Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #526 - add upgrade mechanism to registry #625

Merged
merged 4 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
rahul-kothari marked this conversation as resolved.
Show resolved Hide resolved
IOutbox outbox = REGISTRY.getOutbox();
outbox.sendL1Messages(l2ToL1Msgs);

Expand Down
9 changes: 7 additions & 2 deletions l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 getLatestSnapshot() external view returns (DataStructures.RegistrySnapshot memory);
}
6 changes: 4 additions & 2 deletions l1-contracts/src/core/libraries/DataStructures.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions l1-contracts/src/core/messagebridge/Inbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
_;
}
Expand Down
1 change: 1 addition & 0 deletions l1-contracts/src/core/messagebridge/Outbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
_;
}
Expand Down
46 changes: 32 additions & 14 deletions l1-contracts/src/core/messagebridge/Registry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,46 @@ 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!

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;
uint256 public latestVersionNumber;
mapping(uint256 version => DataStructures.RegistrySnapshot snapshot) snapshots;
rahul-kothari marked this conversation as resolved.
Show resolved Hide resolved
DataStructures.RegistrySnapshot latestSnapshot;

// todo: this function has to be permissioned.
function upgrade(address _rollup, address _inbox, address _outbox) public {
rahul-kothari marked this conversation as resolved.
Show resolved Hide resolved
latestVersionNumber++;
DataStructures.RegistrySnapshot memory newSnapshot =
DataStructures.RegistrySnapshot(_rollup, _inbox, _outbox, block.number);
latestSnapshot = newSnapshot;
snapshots[latestVersionNumber] = newSnapshot;
rahul-kothari marked this conversation as resolved.
Show resolved Hide resolved
}

function getRollup() external view override returns (IRollup) {
return IRollup(addresses.rollup);
return IRollup(latestSnapshot.rollup);
}

function getInbox() external view override returns (IInbox) {
return IInbox(addresses.inbox);
return IInbox(latestSnapshot.inbox);
}

function getOutbox() external view override returns (IOutbox) {
return IOutbox(addresses.outbox);
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;
}
}
2 changes: 1 addition & 1 deletion l1-contracts/test/Inbox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/test/Outbox.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/test/Rollup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/test/portals/RNA.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions l1-contracts/test/portals/RollupNativeAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ contract RollupNativeAsset is ERC20 {
)
});

// @todo: (issue #624) handle different versions
bytes32 entryKey = registry.getOutbox().consume(message);

_mint(_recipient, _amount);
Expand Down
1 change: 1 addition & 0 deletions l1-contracts/test/portals/TokenPortal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/test/portals/TokenPortal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/deploy_l1_contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
);
Expand Down