Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion bindings/bin/rollup_deployed.hex

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bindings/bindings/rollup.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bindings/bindings/rollup_more.go

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions contracts/contracts/l1/rollup/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ contract Rollup is IRollup, OwnableUpgradeable, PausableUpgradeable {
uint256 _batchIndex = BatchHeaderCodecV0.getBatchIndex(memPtr);
bytes32 _postStateRoot = BatchHeaderCodecV0.getPostStateHash(memPtr);
require(_postStateRoot != bytes32(0), "zero state root");
// check all fields except `l1DataHash` and `lastBlockHash` are zero
// check all fields except `dataHash` and `lastBlockHash` are zero
require(BatchHeaderCodecV0.getL1MessagePopped(memPtr) == 0, "l1 message popped should be 0");
require(BatchHeaderCodecV0.getL1DataHash(memPtr) != bytes32(0), "zero data hash");
require(BatchHeaderCodecV0.getDataHash(memPtr) != bytes32(0), "zero data hash");
require(BatchHeaderCodecV0.getBlobVersionedHash(memPtr) == ZERO_VERSIONED_HASH, "invalid versioned hash");

committedBatches[_batchIndex] = _batchHash;
Expand Down Expand Up @@ -223,8 +223,8 @@ contract Rollup is IRollup, OwnableUpgradeable, PausableUpgradeable {
// compute the data hash for batch
uint256 _totalL1MessagesPoppedInBatch;
uint256 _totalNumL1Messages;
bytes32 _l1DataHash;
(_l1DataHash, _totalNumL1Messages) = _commitBatch(
bytes32 dataHash;
(dataHash, _totalNumL1Messages) = _commitBatch(
batchDataInput.blockContexts,
_totalL1MessagesPoppedInBatch,
_totalL1MessagesPoppedOverall,
Expand Down Expand Up @@ -258,7 +258,7 @@ contract Rollup is IRollup, OwnableUpgradeable, PausableUpgradeable {
BatchHeaderCodecV0.storeBatchIndex(_batchPtr, _batchIndex);
BatchHeaderCodecV0.storeL1MessagePopped(_batchPtr, _totalL1MessagesPoppedInBatch);
BatchHeaderCodecV0.storeTotalL1MessagePopped(_batchPtr, _totalL1MessagesPoppedOverall);
BatchHeaderCodecV0.storeDataHash(_batchPtr, _l1DataHash);
BatchHeaderCodecV0.storeDataHash(_batchPtr, dataHash);
BatchHeaderCodecV0.storePrevStateHash(_batchPtr, batchDataInput.prevStateRoot);
BatchHeaderCodecV0.storePostStateHash(_batchPtr, batchDataInput.postStateRoot);
BatchHeaderCodecV0.storeWithdrawRootHash(_batchPtr, batchDataInput.withdrawalRoot);
Expand Down Expand Up @@ -603,7 +603,7 @@ contract Rollup is IRollup, OwnableUpgradeable, PausableUpgradeable {
BatchHeaderCodecV0.getPostStateHash(memPtr),
BatchHeaderCodecV0.getWithdrawRootHash(memPtr),
BatchHeaderCodecV0.getSequencerSetVerifyHash(memPtr),
BatchHeaderCodecV0.getL1DataHash(memPtr),
BatchHeaderCodecV0.getDataHash(memPtr),
_kzgDataProof[0:64],
_blobVersionedHash
)
Expand Down Expand Up @@ -736,18 +736,20 @@ contract Rollup is IRollup, OwnableUpgradeable, PausableUpgradeable {
}

uint256 _numBlocks = BatchCodecV0.validateBatchLength(batchPtr, _blockContexts.length);
assembly {
batchPtr := add(batchPtr, 2) // skip numBlocks
}
// concatenate block contexts, use scope to avoid stack too deep
for (uint256 i = 0; i < _numBlocks; i++) {
dataPtr = BatchCodecV0.copyBlockContext(batchPtr, dataPtr, i);
uint256 blockPtr = batchPtr + 2 + i * BatchCodecV0.BLOCK_CONTEXT_LENGTH;
uint256 blockPtr = batchPtr + i * BatchCodecV0.BLOCK_CONTEXT_LENGTH;
uint256 _numL1MessagesInBlock = BatchCodecV0.getNumL1Messages(blockPtr);
unchecked {
_totalNumL1MessagesInBatch += _numL1MessagesInBlock;
}
}
assembly {
mstore(0x40, add(dataPtr, mul(_totalNumL1MessagesInBatch, 0x20))) // reserve memory for l1 message hashes
batchPtr := add(batchPtr, 2) // skip numBlocks
}

// concatenate tx hashes
Expand Down
10 changes: 5 additions & 5 deletions contracts/contracts/libraries/codec/BatchCodecV0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ library BatchCodecV0 {
}

/// @notice Copy the block context to another memory.
/// @param batchPtr The start memory offset of the batch in memory.
/// @param blockPtr The start memory offset of the first block context in memory.
/// @param dstPtr The destination memory offset to store the block context.
/// @param index The index of block context to copy.
/// @return uint256 The new destination memory offset after copy.
function copyBlockContext(uint256 batchPtr, uint256 dstPtr, uint256 index) internal pure returns (uint256) {
function copyBlockContext(uint256 blockPtr, uint256 dstPtr, uint256 index) internal pure returns (uint256) {
// only first 58 bytes is needed.
assembly {
batchPtr := add(batchPtr, add(1, mul(BLOCK_CONTEXT_LENGTH, index)))
mstore(dstPtr, mload(batchPtr)) // first 32 bytes
blockPtr := add(blockPtr, mul(BLOCK_CONTEXT_LENGTH, index))
mstore(dstPtr, mload(blockPtr)) // first 32 bytes
mstore(
add(dstPtr, 0x20),
and(mload(add(batchPtr, 0x20)), 0xffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000)
and(mload(add(blockPtr, 0x20)), 0xffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000)
) // next 26 bytes

dstPtr := add(dstPtr, 58)
Expand Down
2 changes: 1 addition & 1 deletion contracts/contracts/libraries/codec/BatchHeaderCodecV0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ library BatchHeaderCodecV0 {
/// @notice Get the data hash of the batch header.
/// @param batchPtr The start memory offset of the batch header in memory.
/// @return _dataHash The data hash of the batch header.
function getL1DataHash(uint256 batchPtr) internal pure returns (bytes32 _dataHash) {
function getDataHash(uint256 batchPtr) internal pure returns (bytes32 _dataHash) {
assembly {
_dataHash := mload(add(batchPtr, 25))
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/contracts/mock/BatchHeaderCodecTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ contract BatchHeaderCodecTest {
return BatchHeaderCodecV0.getTotalL1MessagePopped(batchPtr);
}

function getL1DataHash(bytes calldata _batchHeader) public pure returns (bytes32 _dataHash) {
function getDataHash(bytes calldata _batchHeader) public pure returns (bytes32 _dataHash) {
(uint256 batchPtr, ) = BatchHeaderCodecV0.loadAndValidate(_batchHeader);
return BatchHeaderCodecV0.getL1DataHash(batchPtr);
return BatchHeaderCodecV0.getDataHash(batchPtr);
}

function getBlobVersionedHash(bytes calldata _batchHeader) public pure returns (bytes32 _blobVersionedHash) {
Expand Down
20 changes: 10 additions & 10 deletions contracts/contracts/test/Rollup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ contract RollupCommitBatchTest is L1MessageBaseTest {

// commit batch1, one batch with one block, 1 tx, 1 L1 message, no skip
// => l1 data hash for batch
// 0xf1f131b7336b7621026325f6b5519cebcdf42a1fcb520bec47af5a9bd54848af
// 0x9ef1e5694bdb014a1eea42be756a8f63bfd8781d6332e9ef3b5126d90c62f110
// => payload for batch header
// 00
// 0000000000000001
// 0000000000000001
// 0000000000000001
// f1f131b7336b7621026325f6b5519cebcdf42a1fcb520bec47af5a9bd54848af
// 9ef1e5694bdb014a1eea42be756a8f63bfd8781d6332e9ef3b5126d90c62f110
// 010657f37554c781402a22917dee2f75def7ab966d7b770905398eba3c444014
// 0000000000000000000000000000000000000000000000000000000000000001
// 0000000000000000000000000000000000000000000000000000000000000002
Expand All @@ -82,7 +82,7 @@ contract RollupCommitBatchTest is L1MessageBaseTest {
mstore(add(batchHeader1, add(0x20, 1)), shl(192, 1)) // batchIndex = 1
mstore(add(batchHeader1, add(0x20, 9)), shl(192, 1)) // l1MessagePopped = 1
mstore(add(batchHeader1, add(0x20, 17)), shl(192, 1)) // totalL1MessagePopped = 1
mstore(add(batchHeader1, add(0x20, 25)), 0xf1f131b7336b7621026325f6b5519cebcdf42a1fcb520bec47af5a9bd54848af) // l1dataHash
mstore(add(batchHeader1, add(0x20, 25)), 0x9ef1e5694bdb014a1eea42be756a8f63bfd8781d6332e9ef3b5126d90c62f110) // dataHash
mstore(add(batchHeader1, add(0x20, 57)), 0x010657f37554c781402a22917dee2f75def7ab966d7b770905398eba3c444014) // l2 tx blob versioned hash
mstore(add(batchHeader1, add(0x20, 89)), bytesData1) // prevStateHash
mstore(add(batchHeader1, add(0x20, 121)), bytesData1) // postStateHash
Expand Down Expand Up @@ -113,14 +113,14 @@ contract RollupCommitBatchTest is L1MessageBaseTest {
);
hevm.startPrank(address(0));
hevm.expectEmit(true, true, false, true);
emit IRollup.CommitBatch(1, bytes32(0x936ca0be1c54c890ff243f3b4aea6aa8aefd1292fecae5da57f9f60f66a78bdb));
emit IRollup.CommitBatch(1, bytes32(0x135ab7153517794b38566492dee2a60426285da9764f8ad07da93cf7dd560a59));
batchDataInput = IRollup.BatchDataInput(0, batchHeader0, batch, bitmap, bytesData1, bytesData1, bytesData3);
rollup.commitBatch(batchDataInput, batchSignatureInput);
hevm.stopPrank();

assertFalse(rollup.isBatchFinalized(1));
bytes32 batchHash1 = rollup.committedBatches(1);
assertEq(batchHash1, bytes32(0x936ca0be1c54c890ff243f3b4aea6aa8aefd1292fecae5da57f9f60f66a78bdb));
assertEq(batchHash1, bytes32(0x135ab7153517794b38566492dee2a60426285da9764f8ad07da93cf7dd560a59));

emit log_bytes32(batchHash0);
// finalize batch1
Expand All @@ -144,7 +144,7 @@ contract RollupCommitBatchTest is L1MessageBaseTest {
mstore(add(batchHeader2, add(0x20, 1)), shl(192, 2)) // batchIndex = 2
mstore(add(batchHeader2, add(0x20, 9)), shl(192, 264)) // l1MessagePopped = 264
mstore(add(batchHeader2, add(0x20, 17)), shl(192, 265)) // totalL1MessagePopped = 265
mstore(add(batchHeader2, add(0x20, 25)), 0x1fd1f1462d3818d690c872d065fa1196321a153a22f017d593e0cf774b5ad405) // dataHash
mstore(add(batchHeader2, add(0x20, 25)), 0xc67045fcf768071021f5acec08a921553fdae4c33a675d38e4c4a25589c91120) // dataHash
mstore(add(batchHeader2, add(0x20, 57)), 0x010657f37554c781402a22917dee2f75def7ab966d7b770905398eba3c444014) // l2 tx blob versioned hash
mstore(add(batchHeader2, add(0x20, 89)), bytesData1) // prevStateHash
mstore(add(batchHeader2, add(0x20, 121)), bytesData1) // postStateHash
Expand Down Expand Up @@ -195,15 +195,15 @@ contract RollupCommitBatchTest is L1MessageBaseTest {
);
hevm.startPrank(address(0));
hevm.expectEmit(true, true, false, true);
emit IRollup.CommitBatch(2, bytes32(0xbf4a9c9cafaa1979143075687a43a464e05c8a2723ed41d12c7c6a58a4b04cd1));
emit IRollup.CommitBatch(2, bytes32(0x71259c7573b1db248381cef917270058e2ca20620c6eae975a1aa76b9858392a));

batchDataInput = IRollup.BatchDataInput(0, batchHeader1, batch, bitmap, bytesData1, bytesData1, bytesData4);
rollup.commitBatch(batchDataInput, batchSignatureInput);

hevm.stopPrank();
assertFalse(rollup.isBatchFinalized(2));
bytes32 batchHash2 = rollup.committedBatches(2);
assertEq(batchHash2, bytes32(0xbf4a9c9cafaa1979143075687a43a464e05c8a2723ed41d12c7c6a58a4b04cd1));
assertEq(batchHash2, bytes32(0x71259c7573b1db248381cef917270058e2ca20620c6eae975a1aa76b9858392a));

// verify committed batch correctly
hevm.startPrank(address(0));
Expand Down Expand Up @@ -537,14 +537,14 @@ contract RollupTest is L1MessageBaseTest {
);
rollup.commitBatch(batchDataInput, batchSignatureInput); // first chunk with too many txs
hevm.stopPrank();
assertEq(rollup.committedBatches(1), 0x5c84f469c62cd712c33f1b15b538fa771c7a223aefc911089978d8de5cf4bc5c);
assertEq(rollup.committedBatches(1), 0xb7cb76cf9e9f5878136c1d14e095f5d5b435fe8252cad6eb100e51110033b6ed);
bytes memory batchHeader1 = new bytes(249);
assembly {
mstore(add(batchHeader1, 0x20), 0) // version
mstore(add(batchHeader1, add(0x20, 1)), shl(192, 1)) // batchIndex
mstore(add(batchHeader1, add(0x20, 9)), 0) // l1MessagePopped
mstore(add(batchHeader1, add(0x20, 17)), 0) // totalL1MessagePopped
mstore(add(batchHeader1, add(0x20, 25)), 0x5cc7985ff03945d904d4e5a8376ef8371d42c22395eab1b3e227583388adc3a1) // l1dataHash
mstore(add(batchHeader1, add(0x20, 25)), 0x7cdb9d7f02ea58dfeb797ed6b4f7ea68846e4f2b0e30ed1535fc98b60c4ec809) // dataHash
mstore(add(batchHeader1, add(0x20, 57)), 0x010657f37554c781402a22917dee2f75def7ab966d7b770905398eba3c444014) // l2 tx blob versioned hash
mstore(add(batchHeader1, add(0x20, 89)), bytesData1) // prevStateHash
mstore(add(batchHeader1, add(0x20, 121)), bytesData1) // postStateHash
Expand Down
12 changes: 6 additions & 6 deletions contracts/contracts/test/base/BatchHeaderCodeV0.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract BatchHeaderCodeV0Test is DSTestPlus {
mstore(add(batchHeader0, add(0x20, 1)), shl(192, 1)) // batchIndex = 1
mstore(add(batchHeader0, add(0x20, 9)), shl(192, 1)) // l1MessagePopped = 1
mstore(add(batchHeader0, add(0x20, 17)), shl(192, 1)) // totalL1MessagePopped = 1
mstore(add(batchHeader0, add(0x20, 25)), ZERO_VERSIONED_HASH) // l1dataHash
mstore(add(batchHeader0, add(0x20, 25)), ZERO_VERSIONED_HASH) // dataHash
mstore(add(batchHeader0, add(0x20, 57)), ZERO_VERSIONED_HASH) // l2 tx blob versioned hash
mstore(add(batchHeader0, add(0x20, 89)), ZERO_VERSIONED_HASH) // prevStateHash
mstore(add(batchHeader0, add(0x20, 121)), ZERO_VERSIONED_HASH) // postStateHash
Expand All @@ -36,7 +36,7 @@ contract BatchHeaderCodeV0Test is DSTestPlus {
uint256 version = codecTest.getVersion(batchHeader0);
uint256 index = codecTest.getBatchIndex(batchHeader0);
uint256 l1MessagePopped = codecTest.getL1MessagePopped(batchHeader0);
bytes32 l1dataHash = codecTest.getL1DataHash(batchHeader0);
bytes32 dataHash = codecTest.getDataHash(batchHeader0);
bytes32 blobVersionedHash = codecTest.getBlobVersionedHash(batchHeader0);
bytes32 prevStateHash = codecTest.getPrevStateHash(batchHeader0);
bytes32 postStateHash = codecTest.getPostStateHash(batchHeader0);
Expand All @@ -47,7 +47,7 @@ contract BatchHeaderCodeV0Test is DSTestPlus {
assertEq(version, 1);
assertEq(index, 1);
assertEq(l1MessagePopped, 1);
assertEq(l1dataHash, ZERO_VERSIONED_HASH);
assertEq(dataHash, ZERO_VERSIONED_HASH);
assertEq(blobVersionedHash, ZERO_VERSIONED_HASH);
assertEq(prevStateHash, ZERO_VERSIONED_HASH);
assertEq(postStateHash, ZERO_VERSIONED_HASH);
Expand All @@ -65,7 +65,7 @@ contract BatchHeaderCodeV0Test is DSTestPlus {
mstore(add(batchHeader0, add(0x20, 1)), shl(192, 1)) // batchIndex
mstore(add(batchHeader0, add(0x20, 9)), 0) // l1MessagePopped
mstore(add(batchHeader0, add(0x20, 17)), 0) // totalL1MessagePopped
mstore(add(batchHeader0, add(0x20, 25)), 0x246394445f4fe64ed5598554d55d1682d6fb3fe04bf58eb54ef81d1189fafb51) // l1dataHash
mstore(add(batchHeader0, add(0x20, 25)), 0x246394445f4fe64ed5598554d55d1682d6fb3fe04bf58eb54ef81d1189fafb51) // dataHash
mstore(add(batchHeader0, add(0x20, 57)), 0x010657f37554c781402a22917dee2f75def7ab966d7b770905398eba3c444014) // l2 tx blob versioned hash
mstore(add(batchHeader0, add(0x20, 89)), bytesData1) // prevStateHash
mstore(add(batchHeader0, add(0x20, 121)), bytesData1) // postStateHash
Expand All @@ -84,7 +84,7 @@ contract BatchHeaderCodeV0Test is DSTestPlus {
uint256 version = codecTest.getVersion(batchHeader0);
uint256 index = codecTest.getBatchIndex(batchHeader0);
uint256 l1MessagePopped = codecTest.getL1MessagePopped(batchHeader0);
bytes32 l1dataHash = codecTest.getL1DataHash(batchHeader0);
bytes32 dataHash = codecTest.getDataHash(batchHeader0);
bytes32 blobVersionedHash = codecTest.getBlobVersionedHash(batchHeader0);
bytes32 prevStateHash = codecTest.getPrevStateHash(batchHeader0);
bytes32 postStateHash = codecTest.getPostStateHash(batchHeader0);
Expand All @@ -97,7 +97,7 @@ contract BatchHeaderCodeV0Test is DSTestPlus {
assertEq(version, 0);
assertEq(index, 1);
assertEq(l1MessagePopped, 0);
assertEq(l1dataHash, 0x246394445f4fe64ed5598554d55d1682d6fb3fe04bf58eb54ef81d1189fafb51);
assertEq(dataHash, 0x246394445f4fe64ed5598554d55d1682d6fb3fe04bf58eb54ef81d1189fafb51);
assertEq(blobVersionedHash, 0x010657f37554c781402a22917dee2f75def7ab966d7b770905398eba3c444014);
assertEq(prevStateHash, bytesData1);
assertEq(postStateHash, bytesData1);
Expand Down