Skip to content

Commit 159df24

Browse files
Thegaram0xmountaintopzimpha
authored
feat(contracts): accept batches with version > 1 (#1317)
Co-authored-by: HAOYUatHZ <[email protected]> Co-authored-by: Xi Lin <[email protected]>
1 parent 67217f3 commit 159df24

File tree

4 files changed

+8
-42
lines changed

4 files changed

+8
-42
lines changed

docs/apis/ScrollChain.md

-11
Original file line numberDiff line numberDiff line change
@@ -882,17 +882,6 @@ error ErrorIncorrectPreviousStateRoot()
882882
*Thrown when the previous state root doesn&#39;t match stored one.*
883883

884884

885-
### ErrorInvalidBatchHeaderVersion
886-
887-
```solidity
888-
error ErrorInvalidBatchHeaderVersion()
889-
```
890-
891-
892-
893-
*Thrown when the batch header version is invalid.*
894-
895-
896885
### ErrorLastL1MessageSkipped
897886

898887
```solidity

integration-test/ScrollChain.blob.spec.ts

-13
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,6 @@ describe("ScrollChain.blob", async () => {
9898
batchHeader0[25] = 1;
9999
});
100100

101-
it("should revert when ErrorInvalidBatchHeaderVersion", async () => {
102-
const header = new Uint8Array(121);
103-
header[0] = 2;
104-
await expect(chain.commitBatch(1, header, ["0x"], "0x")).to.revertedWithCustomError(
105-
chain,
106-
"ErrorInvalidBatchHeaderVersion"
107-
);
108-
await expect(chain.commitBatch(2, batchHeader0, ["0x"], "0x")).to.revertedWithCustomError(
109-
chain,
110-
"ErrorInvalidBatchHeaderVersion"
111-
);
112-
});
113-
114101
it("should revert when ErrorNoBlobFound", async () => {
115102
await expect(chain.commitBatch(1, batchHeader0, ["0x"], "0x")).to.revertedWithCustomError(
116103
chain,

src/L1/rollup/ScrollChain.sol

+8-12
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
7474
/// @dev Thrown when the previous state root doesn't match stored one.
7575
error ErrorIncorrectPreviousStateRoot();
7676

77-
/// @dev Thrown when the batch header version is invalid.
78-
error ErrorInvalidBatchHeaderVersion();
79-
8077
/// @dev Thrown when the last message is skipped.
8178
error ErrorLastL1MessageSkipped();
8279

@@ -119,7 +116,8 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
119116

120117
/// @dev BLS Modulus value defined in EIP-4844 and the magic value returned from a successful call to the
121118
/// point evaluation precompile
122-
uint256 private constant BLS_MODULUS = 52435875175126190479447740508185965837690552500527637822603658699938581184513;
119+
uint256 private constant BLS_MODULUS =
120+
52435875175126190479447740508185965837690552500527637822603658699938581184513;
123121

124122
/// @notice The chain id of the corresponding layer 2 chain.
125123
uint64 public immutable layer2ChainId;
@@ -310,7 +308,10 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
310308
batchPtr,
311309
BatchHeaderV0Codec.BATCH_HEADER_FIXED_LENGTH + _skippedL1MessageBitmap.length
312310
);
313-
} else if (_version == 1) {
311+
} else if (_version >= 1) {
312+
// versions 1 and 2 both use ChunkCodecV1 and BatchHeaderV1Codec,
313+
// but they use different blob encoding and different verifiers.
314+
314315
bytes32 blobVersionedHash;
315316
(blobVersionedHash, _dataHash, _totalL1MessagesPoppedInBatch) = _commitChunksV1(
316317
_totalL1MessagesPoppedOverall,
@@ -322,7 +323,7 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
322323
_totalL1MessagesPoppedOverall := add(_totalL1MessagesPoppedOverall, _totalL1MessagesPoppedInBatch)
323324
}
324325
// store entries, the order matters
325-
BatchHeaderV1Codec.storeVersion(batchPtr, 1);
326+
BatchHeaderV1Codec.storeVersion(batchPtr, _version);
326327
BatchHeaderV1Codec.storeBatchIndex(batchPtr, _batchIndex);
327328
BatchHeaderV1Codec.storeL1MessagePopped(batchPtr, _totalL1MessagesPoppedInBatch);
328329
BatchHeaderV1Codec.storeTotalL1MessagePopped(batchPtr, _totalL1MessagesPoppedOverall);
@@ -335,8 +336,6 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
335336
batchPtr,
336337
BatchHeaderV1Codec.BATCH_HEADER_FIXED_LENGTH + _skippedL1MessageBitmap.length
337338
);
338-
} else {
339-
revert ErrorInvalidBatchHeaderVersion();
340339
}
341340

342341
// check the length of bitmap
@@ -711,18 +710,15 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
711710
version := shr(248, calldataload(_batchHeader.offset))
712711
}
713712

714-
// version should be always 0 or 1 in current code
715713
uint256 _length;
716714
if (version == 0) {
717715
(batchPtr, _length) = BatchHeaderV0Codec.loadAndValidate(_batchHeader);
718716
_batchHash = BatchHeaderV0Codec.computeBatchHash(batchPtr, _length);
719717
_batchIndex = BatchHeaderV0Codec.getBatchIndex(batchPtr);
720-
} else if (version == 1) {
718+
} else if (version >= 1) {
721719
(batchPtr, _length) = BatchHeaderV1Codec.loadAndValidate(_batchHeader);
722720
_batchHash = BatchHeaderV1Codec.computeBatchHash(batchPtr, _length);
723721
_batchIndex = BatchHeaderV1Codec.getBatchIndex(batchPtr);
724-
} else {
725-
revert ErrorInvalidBatchHeaderVersion();
726722
}
727723
// only check when genesis is imported
728724
if (committedBatches[_batchIndex] != _batchHash && finalizedStateRoots[0] != bytes32(0)) {

src/test/ScrollChain.t.sol

-6
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@ contract ScrollChainTest is DSTestPlus {
8989
rollup.commitBatch(0, batchHeader0, new bytes[](0), new bytes(0));
9090
hevm.stopPrank();
9191

92-
// invalid version, revert
93-
hevm.startPrank(address(0));
94-
hevm.expectRevert(ScrollChain.ErrorInvalidBatchHeaderVersion.selector);
95-
rollup.commitBatch(2, batchHeader0, new bytes[](1), new bytes(0));
96-
hevm.stopPrank();
97-
9892
// batch header length too small, revert
9993
hevm.startPrank(address(0));
10094
hevm.expectRevert(BatchHeaderV0Codec.ErrorBatchHeaderLengthTooSmall.selector);

0 commit comments

Comments
 (0)