Skip to content

Commit

Permalink
fix #526
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-kothari committed May 22, 2023
1 parent 9d3ea2c commit b0a8039
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 35 deletions.
6 changes: 4 additions & 2 deletions l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
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 Snapshot {
address rollup;
address inbox;
address outbox;
uint256 blockNumber;
}
}
2 changes: 1 addition & 1 deletion l1-contracts/src/core/messagebridge/Inbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
_;
}

Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/src/core/messagebridge/Outbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
_;
}

Expand Down
28 changes: 12 additions & 16 deletions l1-contracts/src/core/messagebridge/Registry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
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
3 changes: 2 additions & 1 deletion l1-contracts/test/portals/RollupNativeAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion l1-contracts/test/portals/TokenPortal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

0 comments on commit b0a8039

Please sign in to comment.