Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
837dec9
refactor: tag delayed inbox explicitly as delayed in bridge variables
fredlacs Jun 15, 2022
641b2fd
refactor: move sequencer accumulator to bridge contract
fredlacs Jun 15, 2022
8195ef8
refactor: handle batch spending report in bridge contract after seque…
fredlacs Jun 15, 2022
7e4f471
cleanup and add affordances for handling sequencer inbox in bridge
fredlacs Jun 15, 2022
ab72ad6
reference only bridge contract for accumulators in OSP
fredlacs Jun 15, 2022
fe28a47
add rollup admin setter
fredlacs Jun 15, 2022
1bf907f
feat: emit delayed message delivered event in sequencer inbox
fredlacs Jun 15, 2022
420b95a
fix: don't submit batch spending when batch not submitted from origin
fredlacs Jun 15, 2022
e66dda7
fix: undo breaking change to delayed inbox event
fredlacs Jun 15, 2022
5e37723
update variable name references
fredlacs Jun 15, 2022
536639b
add useful misc contract addresses to rollup
fredlacs Jun 15, 2022
909f6bc
update go node smart contract references
fredlacs Jun 15, 2022
b735bea
fix hardhat tests
fredlacs Jun 15, 2022
95ac76b
Update bridge contract natspec
fredlacs Jun 15, 2022
5febfe1
Merge branch 'automatic-l1-gas-pricing' into refactor-accumulator-flow
PlasmaPower Jun 16, 2022
b8f66e1
Fix sequencer inbox reader test
PlasmaPower Jun 16, 2022
adfc003
Move address aliasing from L2 to L1
PlasmaPower Jun 16, 2022
2f5b441
refactor: avoid calldata to memory copy in sequencer inbox when not a…
fredlacs Jun 16, 2022
5dfc6f6
refactor: use modifier to validate batch correctness for das
fredlacs Jun 16, 2022
99a1371
refactor: track das keysets in struct
fredlacs Jun 16, 2022
be47f36
fix das byte check and add other batch validation logic to modifier
fredlacs Jun 16, 2022
9e9a313
add data length check
fredlacs Jun 16, 2022
aa4f18e
remove overflow check not needed in solc >=0.8
fredlacs Jun 16, 2022
d57e4a4
fix error name
fredlacs Jun 16, 2022
960ea5c
synchronize deletion of creation block
fredlacs Jun 16, 2022
07339b9
fix length check
fredlacs Jun 16, 2022
a1284d1
refactor das block creation to list every block a keyset was updated
fredlacs Jun 16, 2022
c03848c
docs: comment around 33 magic value
fredlacs Jun 16, 2022
a32123c
Revert "refactor das block creation to list every block a keyset was …
fredlacs Jun 16, 2022
6c84471
Revert "synchronize deletion of creation block"
fredlacs Jun 16, 2022
23e4530
add comments explaining code expectations
fredlacs Jun 16, 2022
9d956c0
use high level solidity for concat of bytes
fredlacs Jun 16, 2022
77923a0
clarify docs
fredlacs Jun 16, 2022
7d2e549
refactor inbox aliasing
fredlacs Jun 16, 2022
aa84e89
fix force inclusion test
fredlacs Jun 16, 2022
a7aff1f
Merge branch 'alias-on-l1' into refcactor-apply-alias
fredlacs Jun 16, 2022
77b0eef
Merge pull request #699 from OffchainLabs/refcactor-apply-alias
PlasmaPower Jun 16, 2022
2fe1374
Merge pull request #697 from OffchainLabs/alias-on-l1
PlasmaPower Jun 16, 2022
e7b3d85
Merge pull request #698 from OffchainLabs/refactor-sequencer-das
PlasmaPower Jun 16, 2022
b7cf8e9
Merge branch 'automatic-l1-gas-pricing' into refactor-accumulator-flow
PlasmaPower Jun 17, 2022
025636f
Merge branch 'automatic-l1-gas-pricing' into refactor-accumulator-flow
PlasmaPower Jun 17, 2022
72680ae
Fix sequencer inbox force include test from merge
PlasmaPower Jun 17, 2022
7ea1a9e
respond to pr comments
fredlacs Jun 20, 2022
6f6c340
Merge branch 'redo-devnet-reinit-1' into refactor-accumulator-flow
PlasmaPower Jun 20, 2022
1397c53
Fix geth submodule pin
PlasmaPower Jun 20, 2022
2851588
Add info to BadSequencerNumber error
PlasmaPower Jun 21, 2022
84542a0
Implement enqueueSequencerMessage in BridgeStub
PlasmaPower Jun 21, 2022
51e9b97
Merge branch 'redo-devnet-reinit-1' into refactor-accumulator-flow
PlasmaPower Jun 21, 2022
3e81710
Fix one step proof JS test with parameter changes
PlasmaPower Jun 21, 2022
52e0614
Merge branch 'redo-devnet-reinit-1' into refactor-accumulator-flow
hkalodner Jun 22, 2022
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
117 changes: 96 additions & 21 deletions contracts/src/bridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import "./IBridge.sol";
import "./Messages.sol";
import "../libraries/DelegateCallAware.sol";

import {L1MessageType_batchPostingReport} from "../libraries/MessageTypes.sol";

/**
* @title Staging ground for incoming and outgoing messages
* @notice Holds the inbox accumulator for delayed messages, and is the ETH escrow
Expand All @@ -26,16 +28,21 @@ contract Bridge is OwnableUpgradeable, DelegateCallAware, IBridge {
bool allowed;
}

mapping(address => InOutInfo) private allowedInboxesMap;
mapping(address => InOutInfo) private allowedDelayedInboxesMap;
mapping(address => InOutInfo) private allowedOutboxesMap;

address[] public allowedInboxList;
address[] public allowedDelayedInboxList;
address[] public allowedOutboxList;

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 inboxAccs;
bytes32[] public override 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;

address public sequencerInbox;

address private constant EMPTY_ACTIVEOUTBOX = address(type(uint160).max);

Expand All @@ -55,14 +62,71 @@ contract Bridge is OwnableUpgradeable, DelegateCallAware, IBridge {
return outbox;
}

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

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

/// @param batchPoster sequencer that included the batch, or zero if not a sequencer
function enqueueSequencerMessage(
bytes32 dataHash,
uint256 afterDelayedMessagesRead,
address batchPoster
)
external
override
returns (
uint256 seqMessageCount,
Comment thread
PlasmaPower marked this conversation as resolved.
Outdated
bytes32 beforeAcc,
bytes32 delayedAcc,
bytes32 acc
)
{
if (msg.sender != sequencerInbox) revert NotSequencerInbox(msg.sender);
seqMessageCount = sequencerInboxAccs.length;
if (sequencerInboxAccs.length > 0) {
beforeAcc = sequencerInboxAccs[sequencerInboxAccs.length - 1];
}
if (afterDelayedMessagesRead > 0) {
delayedAcc = delayedInboxAccs[afterDelayedMessagesRead - 1];
}
acc = keccak256(abi.encodePacked(beforeAcc, dataHash, delayedAcc));
sequencerInboxAccs.push(acc);

if (batchPoster != address(0)) {
// we ignore the return value as we don't need the updated delayed inbox count
// as this msg isn't included in the current sequencer batch
submitBatchSpendingReport(batchPoster, dataHash, seqMessageCount);
}
}

function submitBatchSpendingReport(
address batchPoster,
bytes32 dataHash,
uint256 seqMessageCount
) internal returns (uint256) {
bytes memory messageData = abi.encodePacked(
block.timestamp,
batchPoster,
dataHash,
seqMessageCount,
block.basefee
);

return
addMessageToDelayedAccumulator(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to emit the message data in an inbox-like event somehow. Maybe it'd be better for the sequencer inbox to still submit the batch spending report?

@fredlacs fredlacs Jun 15, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed a change for the sequencer inbox to do so

@fredlacs fredlacs Jun 15, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chose to add a different entrypoint instead of allowing the sequencer inbox to call enqueueDelayedMessage to avoid gas overhead of an extra sload in either every delayed inbox or every sequencer inbox call

L1MessageType_batchPostingReport,
batchPoster,
uint64(block.number),
uint64(block.timestamp), // solhint-disable-line not-rely-on-time,
block.basefee,
keccak256(messageData)
);
}

/**
* @dev Enqueue a message in the delayed inbox accumulator.
* These messages are later sequenced in the SequencerInbox, either by the sequencer as
Expand All @@ -73,9 +137,9 @@ contract Bridge is OwnableUpgradeable, DelegateCallAware, IBridge {
address sender,
bytes32 messageDataHash
) external payable override returns (uint256) {
if (!allowedInboxesMap[msg.sender].allowed) revert NotInbox(msg.sender);
if (!allowedDelayedInboxesMap[msg.sender].allowed) revert NotDelayedInbox(msg.sender);
return
addMessageToAccumulator(
addMessageToDelayedAccumulator(
kind,
sender,
uint64(block.number),
Expand All @@ -85,15 +149,15 @@ contract Bridge is OwnableUpgradeable, DelegateCallAware, IBridge {
);
}

function addMessageToAccumulator(
function addMessageToDelayedAccumulator(
uint8 kind,
address sender,
uint64 blockNumber,
uint64 blockTimestamp,
uint256 baseFeeL1,
bytes32 messageDataHash
) internal returns (uint256) {
uint256 count = inboxAccs.length;
uint256 count = delayedInboxAccs.length;
bytes32 messageHash = Messages.messageHash(
kind,
sender,
Expand All @@ -105,9 +169,9 @@ contract Bridge is OwnableUpgradeable, DelegateCallAware, IBridge {
);
bytes32 prevAcc = 0;
if (count > 0) {
prevAcc = inboxAccs[count - 1];
prevAcc = delayedInboxAccs[count - 1];
}
inboxAccs.push(Messages.accumulateInboxMessage(prevAcc, messageHash));
delayedInboxAccs.push(Messages.accumulateInboxMessage(prevAcc, messageHash));
emit MessageDelivered(
count,
prevAcc,
Expand Down Expand Up @@ -140,21 +204,28 @@ contract Bridge is OwnableUpgradeable, DelegateCallAware, IBridge {
emit BridgeCallTriggered(msg.sender, to, value, data);
}

function setInbox(address inbox, bool enabled) external override onlyOwner {
InOutInfo storage info = allowedInboxesMap[inbox];
function setSequencerInbox(address _sequencerInbox) external override onlyOwner {
sequencerInbox = _sequencerInbox;
emit SequencerInboxUpdated(_sequencerInbox);
}

function setDelayedInbox(address inbox, bool enabled) external override onlyOwner {
InOutInfo storage info = allowedDelayedInboxesMap[inbox];
bool alreadyEnabled = info.allowed;
emit InboxToggle(inbox, enabled);
if ((alreadyEnabled && enabled) || (!alreadyEnabled && !enabled)) {
return;
}
if (enabled) {
allowedInboxesMap[inbox] = InOutInfo(allowedInboxList.length, true);
allowedInboxList.push(inbox);
allowedDelayedInboxesMap[inbox] = InOutInfo(allowedDelayedInboxList.length, true);
allowedDelayedInboxList.push(inbox);
} else {
allowedInboxList[info.index] = allowedInboxList[allowedInboxList.length - 1];
allowedInboxesMap[allowedInboxList[info.index]].index = info.index;
allowedInboxList.pop();
delete allowedInboxesMap[inbox];
allowedDelayedInboxList[info.index] = allowedDelayedInboxList[
allowedDelayedInboxList.length - 1
];
allowedDelayedInboxesMap[allowedDelayedInboxList[info.index]].index = info.index;
allowedDelayedInboxList.pop();
delete allowedDelayedInboxesMap[inbox];
}
}

Expand All @@ -178,7 +249,11 @@ contract Bridge is OwnableUpgradeable, DelegateCallAware, IBridge {
}
}

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

function sequencerMessageCount() external view override returns (uint256) {
return sequencerInboxAccs.length;
}
}
37 changes: 32 additions & 5 deletions contracts/src/bridge/IBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {NotContract} from "../libraries/Error.sol";

/// @dev Thrown when an un-authorized address tries to access an only-inbox function
/// @param sender The un-authorized sender
error NotInbox(address sender);
error NotDelayedInbox(address sender);

/// @dev Thrown when an un-authorized address tries to access an only-sequencer-inbox function
/// @param sender The un-authorized sender
error NotSequencerInbox(address sender);

/// @dev Thrown when an un-authorized address tries to access an only-outbox function
/// @param sender The un-authorized sender
Expand Down Expand Up @@ -41,32 +45,55 @@ interface IBridge {

event OutboxToggle(address indexed outbox, bool enabled);

event SequencerInboxUpdated(address newSequencerInbox);

function enqueueDelayedMessage(
uint8 kind,
address sender,
bytes32 messageDataHash
) external payable returns (uint256);

function enqueueSequencerMessage(
bytes32 dataHash,
uint256 afterDelayedMessagesRead,
address batchPoster
)
external
returns (
uint256 sequencerMessageCount,
bytes32 beforeAcc,
bytes32 delayedAcc,
bytes32 acc
);

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

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

function setOutbox(address inbox, bool enabled) external;

function setSequencerInbox(address _sequencerInbox) external;

// View functions

function sequencerInbox() external view returns (address);

function activeOutbox() external view returns (address);

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

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

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

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

function delayedMessageCount() external view returns (uint256);

function messageCount() external view returns (uint256);
function sequencerMessageCount() external view returns (uint256);
}
6 changes: 0 additions & 6 deletions contracts/src/bridge/IInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ interface IInbox is IMessageProvider {
bytes calldata data
) external payable returns (uint256);

function submitBatchSpendingReportTransaction(
address batchPosterAddr,
bytes32 dataHash,
uint256 batchNumber
) external returns (uint256);

/// @dev Gas limit and maxFeePerGas should not be set to 1 as that is used to trigger the RetryableData error
function createRetryableTicket(
address to,
Expand Down
21 changes: 0 additions & 21 deletions contracts/src/bridge/Inbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
L1MessageType_L2FundedByL1,
L1MessageType_submitRetryableTx,
L1MessageType_ethDeposit,
L1MessageType_batchPostingReport,
L2MessageType_unsignedEOATx,
L2MessageType_unsignedContractTx
} from "../libraries/MessageTypes.sol";
Expand Down Expand Up @@ -198,26 +197,6 @@ contract Inbox is DelegateCallAware, PausableUpgradeable, IInbox {
);
}

function submitBatchSpendingReportTransaction(
address batchPosterAddr,
bytes32 dataHash,
uint256 batchNumber
) external virtual override whenNotPaused returns (uint256) {
require(ISequencerInbox(msg.sender) == sequencerInbox, "unauthorized");
return
_deliverMessage(
L1MessageType_batchPostingReport,
batchPosterAddr,
abi.encodePacked(
block.timestamp,
batchPosterAddr,
dataHash,
batchNumber,
block.basefee
)
);
}

/**
* @notice Get the L1 fee for submitting a retryable
* @dev This fee can be paid by funds already in the L2 aliased address or by the current message value
Expand Down
Loading