diff --git a/contracts/contracts/l1/rollup/Rollup.sol b/contracts/contracts/l1/rollup/Rollup.sol index 4a6567619..905913f94 100644 --- a/contracts/contracts/l1/rollup/Rollup.sol +++ b/contracts/contracts/l1/rollup/Rollup.sol @@ -194,6 +194,8 @@ contract Rollup is IRollup, OwnableUpgradeable, PausableUpgradeable { (uint256 memPtr, bytes32 _batchHash) = _loadBatchHeader(_batchHeader); uint256 _batchIndex = BatchHeaderCodecV0.getBatchIndex(memPtr); + // check batch index is 0 + require(_batchIndex == 0, "invalid batch index"); bytes32 _postStateRoot = BatchHeaderCodecV0.getPostStateHash(memPtr); require(_postStateRoot != bytes32(0), "zero state root"); // check all fields except `dataHash` and `lastBlockHash` are zero diff --git a/contracts/contracts/test/Rollup.t.sol b/contracts/contracts/test/Rollup.t.sol index 95d49eda1..d29606ad9 100644 --- a/contracts/contracts/test/Rollup.t.sol +++ b/contracts/contracts/test/Rollup.t.sol @@ -546,6 +546,15 @@ contract RollupTest is L1MessageBaseTest { function test_importGenesisBlock_succeeds() public { bytes memory batchHeader; bytes32 bytesData1 = bytes32(uint256(1)); + // invalid batch index, revert + batchHeader = new bytes(249); + assembly { + mstore(add(batchHeader, add(0x20, 1)), shl(192, 1)) // batchIndex = 1 + } + hevm.expectRevert("invalid batch index"); + hevm.prank(multisig); + rollup.importGenesisBatch(batchHeader); + // zero state root, revert batchHeader = new bytes(249); hevm.expectRevert("zero state root");