Skip to content

Commit

Permalink
feat: add addSequencerL2BatchDelayProof method
Browse files Browse the repository at this point in the history
  • Loading branch information
shotaronowhere committed Apr 12, 2024
1 parent 9bda58a commit e494578
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 50 deletions.
18 changes: 14 additions & 4 deletions src/bridge/ISequencerInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ interface ISequencerInbox is IDelayedMessageProvider {
) external;

/// @dev Proves message delays, updates delay buffers, and posts an L2 batch with blob data.
/// delayProof is used to prove the delay of the message and syncs the delay buffer.
/// If delayProof contains a zero InboxAccPreimage, the batch must read atleast one new delayed message.
/// DelayProof proves the delay of the message and syncs the delay buffer.
function addSequencerL2BatchFromBlobsDelayProof(
uint256 sequenceNumber,
uint256 afterDelayedMessagesRead,
Expand All @@ -216,10 +215,21 @@ interface ISequencerInbox is IDelayedMessageProvider {
DelayProof calldata delayProof
) external;

/// @dev Proves message delays, updates delay buffers, and posts an L2 batch with calldata posted from an EOA.
/// DelayProof proves the delay of the message and syncs the delay buffer.
function addSequencerL2BatchFromOriginDelayProof(
uint256 sequenceNumber,
bytes calldata data,
uint256 afterDelayedMessagesRead,
IGasRefunder gasRefunder,
uint256 prevMessageCount,
uint256 newMessageCount,
DelayProof calldata delayProof
) external;

/// @dev Proves message delays, updates delay buffers, and posts an L2 batch with calldata.
/// delayProof is used to prove the delay of the message and syncs the delay buffer.
/// If delayProof contains a zero InboxAccPreimage, the batch must read atleast one new delayed message.
function addSequencerL2BatchFromOriginDelayProof(
function addSequencerL2BatchDelayProof(
uint256 sequenceNumber,
bytes calldata data,
uint256 afterDelayedMessagesRead,
Expand Down
93 changes: 47 additions & 46 deletions src/bridge/SequencerInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,13 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
if (!isBatchPoster[msg.sender]) revert NotBatchPoster();
if (isDelayProofRequired(afterDelayedMessagesRead)) revert DelayProofRequired();

addSequencerL2BatchFromCalldataOriginImpl(
addSequencerL2BatchFromCalldataImpl(
sequenceNumber,
data,
afterDelayedMessagesRead,
prevMessageCount,
newMessageCount
newMessageCount,
true
);
}

Expand Down Expand Up @@ -443,12 +444,13 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
if (!isDelayBufferable) revert NotDelayBufferable();

delayProofImpl(afterDelayedMessagesRead, delayProof);
addSequencerL2BatchFromCalldataOriginImpl(
addSequencerL2BatchFromCalldataImpl(
sequenceNumber,
data,
afterDelayedMessagesRead,
prevMessageCount,
newMessageCount
newMessageCount,
true
);
}

Expand Down Expand Up @@ -509,12 +511,13 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
}
}

function addSequencerL2BatchFromCalldataOriginImpl(
function addSequencerL2BatchFromCalldataImpl(
uint256 sequenceNumber,
bytes calldata data,
uint256 afterDelayedMessagesRead,
uint256 prevMessageCount,
uint256 newMessageCount
uint256 newMessageCount,
bool isFromOrigin
) internal {
(bytes32 dataHash, IBridge.TimeBounds memory timeBounds) = formCallDataHash(
data,
Expand All @@ -528,7 +531,7 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
) = addSequencerL2BatchImpl(
dataHash,
afterDelayedMessagesRead,
data.length,
isFromOrigin ? data.length : 0,
prevMessageCount,
newMessageCount
);
Expand All @@ -545,10 +548,17 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
delayedAcc,
totalDelayedMessagesRead,
timeBounds,
IBridge.BatchDataLocation.TxInput
isFromOrigin
? IBridge.BatchDataLocation.TxInput
: IBridge.BatchDataLocation.SeparateBatchEvent
);

if (!isFromOrigin) {
emit SequencerBatchData(seqMessageIndex, data);
}
}

/// @inheritdoc ISequencerInbox
function addSequencerL2Batch(
uint256 sequenceNumber,
bytes calldata data,
Expand All @@ -559,48 +569,39 @@ contract SequencerInbox is DelegateCallAware, GasRefundEnabled, ISequencerInbox
) external override refundsGas(gasRefunder, IReader4844(address(0))) {
if (!isBatchPoster[msg.sender] && msg.sender != address(rollup)) revert NotBatchPoster();
if (isDelayProofRequired(afterDelayedMessagesRead)) revert DelayProofRequired();
(bytes32 dataHash, IBridge.TimeBounds memory timeBounds) = formCallDataHash(

addSequencerL2BatchFromCalldataImpl(
sequenceNumber,
data,
afterDelayedMessagesRead
afterDelayedMessagesRead,
prevMessageCount,
newMessageCount,
false
);
uint256 seqMessageIndex;
{
// Reformat the stack to prevent "Stack too deep"
uint256 sequenceNumber_ = sequenceNumber;
IBridge.TimeBounds memory timeBounds_ = timeBounds;
bytes32 dataHash_ = dataHash;
uint256 afterDelayedMessagesRead_ = afterDelayedMessagesRead;
uint256 prevMessageCount_ = prevMessageCount;
uint256 newMessageCount_ = newMessageCount;
// we set the calldata length posted to 0 here since the caller isn't the origin
// of the tx, so they might have not paid tx input cost for the calldata
bytes32 beforeAcc;
bytes32 delayedAcc;
bytes32 afterAcc;
(seqMessageIndex, beforeAcc, delayedAcc, afterAcc) = addSequencerL2BatchImpl(
dataHash_,
afterDelayedMessagesRead_,
0,
prevMessageCount_,
newMessageCount_
);
}

// ~uint256(0) is type(uint256).max, but ever so slightly cheaper
if (seqMessageIndex != sequenceNumber_ && sequenceNumber_ != ~uint256(0)) {
revert BadSequencerNumber(seqMessageIndex, sequenceNumber_);
}
/// @inheritdoc ISequencerInbox
function addSequencerL2BatchDelayProof(
uint256 sequenceNumber,
bytes calldata data,
uint256 afterDelayedMessagesRead,
IGasRefunder gasRefunder,
uint256 prevMessageCount,
uint256 newMessageCount,
DelayProof calldata delayProof
) external refundsGas(gasRefunder, IReader4844(address(0))) {
if (!isBatchPoster[msg.sender] && msg.sender != address(rollup)) revert NotBatchPoster();
if (!isDelayBufferable) revert NotDelayBufferable();

emit SequencerBatchDelivered(
seqMessageIndex,
beforeAcc,
afterAcc,
delayedAcc,
totalDelayedMessagesRead,
timeBounds_,
IBridge.BatchDataLocation.SeparateBatchEvent
);
}
emit SequencerBatchData(seqMessageIndex, data);
delayProofImpl(afterDelayedMessagesRead, delayProof);
addSequencerL2BatchFromCalldataImpl(
sequenceNumber,
data,
afterDelayedMessagesRead,
prevMessageCount,
newMessageCount,
false
);
}

function delayProofImpl(uint256 afterDelayedMessagesRead, DelayProof memory delayProof)
Expand Down
1 change: 1 addition & 0 deletions test/signatures/SequencerInbox
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"TREE_DAS_MESSAGE_HEADER_FLAG()": "6c890450",
"ZERO_HEAVY_MESSAGE_HEADER_FLAG()": "02c99275",
"addSequencerL2Batch(uint256,bytes,uint256,address,uint256,uint256)": "e0bc9729",
"addSequencerL2BatchDelayProof(uint256,bytes,uint256,address,uint256,uint256,(bytes32,(uint8,address,uint64,uint64,uint256,uint256,bytes32)))": "6e620055",
"addSequencerL2BatchFromBlobs(uint256,uint256,address,uint256,uint256)": "3e5aa082",
"addSequencerL2BatchFromBlobsDelayProof(uint256,uint256,address,uint256,uint256,(bytes32,(uint8,address,uint64,uint64,uint256,uint256,bytes32)))": "917cf8ac",
"addSequencerL2BatchFromOrigin(uint256,bytes,uint256,address)": "6f12b0c9",
Expand Down

0 comments on commit e494578

Please sign in to comment.