Skip to content

Commit

Permalink
Merge pull request #848 from OffchainLabs/refactor-contract-interfaces
Browse files Browse the repository at this point in the history
Refactor contract interfaces
  • Loading branch information
gzeoneth authored Aug 17, 2022
2 parents 4bb41c0 + 2989b06 commit 1fcb844
Show file tree
Hide file tree
Showing 12 changed files with 376 additions and 266 deletions.
2 changes: 1 addition & 1 deletion contracts/deploy/InboxStubCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = async (hre) => {

if (inboxDeployResult.newlyDeployed) {
await bridge.setDelayedInbox(inbox.address, true);
await inbox.initialize(bridge.address);
await inbox.initialize(bridge.address, ethers.constants.AddressZero);
}
};

Expand Down
43 changes: 16 additions & 27 deletions contracts/src/bridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ contract Bridge is Initializable, DelegateCallAware, IBridge {

address private _activeOutbox;

/// @dev Accumulator for delayed inbox messages; tail represents hash of the current state; each element represents the inclusion of a new message.
bytes32[] public override delayedInboxAccs;
/// @inheritdoc IBridge
bytes32[] public delayedInboxAccs;

/// @dev Accumulator for sequencer inbox messages; tail represents hash of the current state; each element represents the inclusion of a new message.
bytes32[] public override sequencerInboxAccs;
/// @inheritdoc IBridge
bytes32[] public sequencerInboxAccs;

IOwnable public override rollup;
IOwnable public rollup;
address public sequencerInbox;

address private constant EMPTY_ACTIVEOUTBOX = address(type(uint160).max);
Expand Down Expand Up @@ -81,11 +81,11 @@ contract Bridge is Initializable, DelegateCallAware, IBridge {
return outbox;
}

function allowedDelayedInboxes(address inbox) external view override returns (bool) {
function allowedDelayedInboxes(address inbox) external view returns (bool) {
return allowedDelayedInboxesMap[inbox].allowed;
}

function allowedOutboxes(address outbox) external view override returns (bool) {
function allowedOutboxes(address outbox) external view returns (bool) {
return allowedOutboxesMap[outbox].allowed;
}

Expand All @@ -96,7 +96,6 @@ contract Bridge is Initializable, DelegateCallAware, IBridge {

function enqueueSequencerMessage(bytes32 dataHash, uint256 afterDelayedMessagesRead)
external
override
onlySequencerInbox
returns (
uint256 seqMessageIndex,
Expand All @@ -116,15 +115,9 @@ contract Bridge is Initializable, DelegateCallAware, IBridge {
sequencerInboxAccs.push(acc);
}

/**
* @dev allows the sequencer inbox to submit a delayed message of the batchPostingReport type
* This is done through a separate function entrypoint instead of allowing the sequencer inbox
* to call `enqueueDelayedMessage` to avoid the gas overhead of an extra SLOAD in either
* every delayed inbox or every sequencer inbox call.
*/
/// @inheritdoc IBridge
function submitBatchSpendingReport(address sender, bytes32 messageDataHash)
external
override
onlySequencerInbox
returns (uint256)
{
Expand All @@ -139,16 +132,12 @@ contract Bridge is Initializable, DelegateCallAware, IBridge {
);
}

/**
* @dev Enqueue a message in the delayed inbox accumulator.
* These messages are later sequenced in the SequencerInbox, either by the sequencer as
* part of a normal batch, or by force inclusion.
*/
/// @inheritdoc IBridge
function enqueueDelayedMessage(
uint8 kind,
address sender,
bytes32 messageDataHash
) external payable override returns (uint256) {
) external payable returns (uint256) {
if (!allowedDelayedInboxesMap[msg.sender].allowed) revert NotDelayedInbox(msg.sender);
return
addMessageToDelayedAccumulator(
Expand Down Expand Up @@ -201,7 +190,7 @@ contract Bridge is Initializable, DelegateCallAware, IBridge {
address to,
uint256 value,
bytes calldata data
) external override returns (bool success, bytes memory returnData) {
) external returns (bool success, bytes memory returnData) {
if (!allowedOutboxesMap[msg.sender].allowed) revert NotOutbox(msg.sender);
if (data.length > 0 && !to.isContract()) revert NotContract(to);
address prevOutbox = _activeOutbox;
Expand All @@ -216,12 +205,12 @@ contract Bridge is Initializable, DelegateCallAware, IBridge {
emit BridgeCallTriggered(msg.sender, to, value, data);
}

function setSequencerInbox(address _sequencerInbox) external override onlyRollupOrOwner {
function setSequencerInbox(address _sequencerInbox) external onlyRollupOrOwner {
sequencerInbox = _sequencerInbox;
emit SequencerInboxUpdated(_sequencerInbox);
}

function setDelayedInbox(address inbox, bool enabled) external override onlyRollupOrOwner {
function setDelayedInbox(address inbox, bool enabled) external onlyRollupOrOwner {
InOutInfo storage info = allowedDelayedInboxesMap[inbox];
bool alreadyEnabled = info.allowed;
emit InboxToggle(inbox, enabled);
Expand All @@ -241,7 +230,7 @@ contract Bridge is Initializable, DelegateCallAware, IBridge {
}
}

function setOutbox(address outbox, bool enabled) external override onlyRollupOrOwner {
function setOutbox(address outbox, bool enabled) external onlyRollupOrOwner {
if (outbox == EMPTY_ACTIVEOUTBOX) revert InvalidOutboxSet(outbox);

InOutInfo storage info = allowedOutboxesMap[outbox];
Expand All @@ -261,11 +250,11 @@ contract Bridge is Initializable, DelegateCallAware, IBridge {
}
}

function delayedMessageCount() external view override returns (uint256) {
function delayedMessageCount() external view returns (uint256) {
return delayedInboxAccs.length;
}

function sequencerMessageCount() external view override returns (uint256) {
function sequencerMessageCount() external view returns (uint256) {
return sequencerInboxAccs.length;
}

Expand Down
76 changes: 48 additions & 28 deletions contracts/src/bridge/IBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,49 @@ interface IBridge {

event SequencerInboxUpdated(address newSequencerInbox);

function allowedDelayedInboxList(uint256) external returns (address);

function allowedOutboxList(uint256) external returns (address);

/// @dev Accumulator for delayed inbox messages; tail represents hash of the current state; each element represents the inclusion of a new message.
function delayedInboxAccs(uint256) external view returns (bytes32);

/// @dev Accumulator for sequencer inbox messages; tail represents hash of the current state; each element represents the inclusion of a new message.
function sequencerInboxAccs(uint256) external view returns (bytes32);

function rollup() external view returns (IOwnable);

function sequencerInbox() external view returns (address);

function activeOutbox() external view returns (address);

function allowedDelayedInboxes(address inbox) external view returns (bool);

function allowedOutboxes(address outbox) external view returns (bool);

/**
* @dev Enqueue a message in the delayed inbox accumulator.
* These messages are later sequenced in the SequencerInbox, either
* by the sequencer as part of a normal batch, or by force inclusion.
*/
function enqueueDelayedMessage(
uint8 kind,
address sender,
bytes32 messageDataHash
) external payable returns (uint256);

function executeCall(
address to,
uint256 value,
bytes calldata data
) external returns (bool success, bytes memory returnData);

function delayedMessageCount() external view returns (uint256);

function sequencerMessageCount() external view returns (uint256);

// ---------- onlySequencerInbox functions ----------

function enqueueSequencerMessage(bytes32 dataHash, uint256 afterDelayedMessagesRead)
external
returns (
Expand All @@ -47,42 +84,25 @@ interface IBridge {
bytes32 acc
);

/**
* @dev Allows the sequencer inbox to submit a delayed message of the batchPostingReport type
* This is done through a separate function entrypoint instead of allowing the sequencer inbox
* to call `enqueueDelayedMessage` to avoid the gas overhead of an extra SLOAD in either
* every delayed inbox or every sequencer inbox call.
*/
function submitBatchSpendingReport(address batchPoster, bytes32 dataHash)
external
returns (uint256 msgNum);

function executeCall(
address to,
uint256 value,
bytes calldata data
) external returns (bool success, bytes memory returnData);

// These are only callable by the admin
function setDelayedInbox(address inbox, bool enabled) external;

function setOutbox(address inbox, bool enabled) external;
// ---------- onlyRollupOrOwner functions ----------

function setSequencerInbox(address _sequencerInbox) external;

// View functions

function sequencerInbox() external view returns (address);

function activeOutbox() external view returns (address);

function allowedDelayedInboxes(address inbox) external view returns (bool);

function allowedOutboxes(address outbox) external view returns (bool);

function delayedInboxAccs(uint256 index) external view returns (bytes32);

function sequencerInboxAccs(uint256 index) external view returns (bytes32);

function delayedMessageCount() external view returns (uint256);
function setDelayedInbox(address inbox, bool enabled) external;

function sequencerMessageCount() external view returns (uint256);
function setOutbox(address inbox, bool enabled) external;

function rollup() external view returns (IOwnable);
// ---------- initializer ----------

function acceptFundsFromOldBridge() external payable;
function initialize(IOwnable rollup_) external;
}
Loading

0 comments on commit 1fcb844

Please sign in to comment.