Skip to content

Commit

Permalink
address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-kothari committed May 22, 2023
1 parent b0a8039 commit 3dd7525
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 18 deletions.
4 changes: 2 additions & 2 deletions l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 10 additions & 3 deletions l1-contracts/src/core/interfaces/messagebridge/IRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion l1-contracts/src/core/libraries/DataStructures.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion l1-contracts/src/core/messagebridge/Inbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
_;
}

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

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

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

0 comments on commit 3dd7525

Please sign in to comment.