Skip to content

Commit cf64395

Browse files
committed
fix unit tests
1 parent d851e8e commit cf64395

File tree

5 files changed

+410
-123
lines changed

5 files changed

+410
-123
lines changed

src/L1/rollup/IScrollChain.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,11 @@ interface IScrollChain {
124124
/// @param postStateRoot The state root after current batch.
125125
/// @param withdrawRoot The withdraw trie root after current batch.
126126
/// @param zkProof The zk proof for current batch (single-batch bundle).
127-
/// @param teeProof The tee proof for current batch (single-batch bundle).
128127
struct FinalizeStruct {
129128
bytes batchHeader;
130129
bytes32 postStateRoot;
131130
bytes32 withdrawRoot;
132131
bytes zkProof;
133-
bytes teeProof;
134132
}
135133

136134
/// @notice Commit a batch of transactions on layer 1 with blob data proof and finalize it.

src/L1/rollup/ScrollChain.sol

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
257257
step <<= 1;
258258
}
259259
step >>= 1;
260-
while (step > 1) {
260+
while (step > 0) {
261261
if (committedBatches[index + step] != bytes32(0)) {
262262
index += step;
263263
}
@@ -363,6 +363,11 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
363363
_totalL1MessagesPoppedOverallFirstBatch - l1MessagePoppedFirstBatch
364364
);
365365
}
366+
367+
// update lastCommittedBatchIndex
368+
unchecked {
369+
enforcedBatchParameters.lastCommittedBatchIndex = uint64(_firstBatchIndex - 1);
370+
}
366371
}
367372

368373
/// @inheritdoc IScrollChain
@@ -556,21 +561,14 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
556561
}
557562
}
558563

559-
/// @dev Internal function to get the blob versioned hash.
564+
/// @dev Internal function to get and check the blob versioned hash.
565+
/// @param _blobDataProof The blob data proof passing to point evaluation precompile.
560566
/// @return _blobVersionedHash The retrieved blob versioned hash.
561-
function _checkAndGetBlobVersionedHash(bytes calldata _blobDataProof)
567+
function _getAndCheckBlobVersionedHash(bytes calldata _blobDataProof)
562568
internal
563-
virtual
564569
returns (bytes32 _blobVersionedHash)
565570
{
566-
bytes32 _secondBlob;
567-
// Get blob's versioned hash
568-
assembly {
569-
_blobVersionedHash := blobhash(0)
570-
_secondBlob := blobhash(1)
571-
}
572-
if (_blobVersionedHash == bytes32(0)) revert ErrorNoBlobFound();
573-
if (_secondBlob != bytes32(0)) revert ErrorFoundMultipleBlobs();
571+
_blobVersionedHash = _getBlobVersionedHash();
574572

575573
// Calls the point evaluation precompile and verifies the output
576574
(bool success, bytes memory data) = POINT_EVALUATION_PRECOMPILE_ADDR.staticcall(
@@ -583,6 +581,19 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
583581
if (result != BLS_MODULUS) revert ErrorUnexpectedPointEvaluationPrecompileOutput();
584582
}
585583

584+
/// @dev Internal function to get the blob versioned hash.
585+
/// @return _blobVersionedHash The retrieved blob versioned hash.
586+
function _getBlobVersionedHash() internal virtual returns (bytes32 _blobVersionedHash) {
587+
bytes32 _secondBlob;
588+
// Get blob's versioned hash
589+
assembly {
590+
_blobVersionedHash := blobhash(0)
591+
_secondBlob := blobhash(1)
592+
}
593+
if (_blobVersionedHash == bytes32(0)) revert ErrorNoBlobFound();
594+
if (_secondBlob != bytes32(0)) revert ErrorFoundMultipleBlobs();
595+
}
596+
586597
/// @dev Internal function to commit a batch.
587598
function _commitBatch(
588599
uint8 _version,
@@ -639,7 +650,7 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
639650
BatchHeaderV0Codec.storeDataHash(batchPtr, _dataHash);
640651

641652
// verify blob versioned hash
642-
BatchHeaderV1Codec.storeBlobVersionedHash(batchPtr, _checkAndGetBlobVersionedHash(_blobDataProof));
653+
BatchHeaderV1Codec.storeBlobVersionedHash(batchPtr, _getAndCheckBlobVersionedHash(_blobDataProof));
643654
BatchHeaderV1Codec.storeParentBatchHash(batchPtr, _parentBatchHash);
644655

645656
uint256 lastBlockTimestamp;

src/mocks/ScrollChainMockBlob.sol

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,7 @@ contract ScrollChainMockBlob is ScrollChain {
5050
overrideBatchHashCheck = status;
5151
}
5252

53-
function _checkAndGetBlobVersionedHash(bytes calldata)
54-
internal
55-
virtual
56-
override
57-
returns (bytes32 _blobVersionedHash)
58-
{
53+
function _getBlobVersionedHash() internal virtual override returns (bytes32 _blobVersionedHash) {
5954
_blobVersionedHash = blobVersionedHash;
6055
}
6156

src/test/L1GatewayTestBase.t.sol

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,29 +161,26 @@ abstract contract L1GatewayTestBase is ScrollTestBase {
161161
chunk0[0] = bytes1(uint8(1)); // one block in this chunk
162162
chunks[0] = chunk0;
163163
hevm.startPrank(address(0));
164-
// rollup.commitBatch(1, batchHeader0, chunks, new bytes(0));
164+
rollup.commitBatchWithBlobProof(3, batchHeader0, chunks, new bytes(0), blobDataProof);
165165
hevm.stopPrank();
166166

167-
bytes memory batchHeader1 = new bytes(121);
167+
bytes memory batchHeader1 = new bytes(193);
168168
assembly {
169-
mstore8(add(batchHeader1, 0x20), 1) // version
169+
mstore8(add(batchHeader1, 0x20), 3) // version
170170
mstore(add(batchHeader1, add(0x20, 1)), shl(192, 1)) // batchIndex
171-
mstore(add(batchHeader1, add(0x20, 9)), 0) // l1MessagePopped
172-
mstore(add(batchHeader1, add(0x20, 17)), 0) // totalL1MessagePopped
171+
mstore(add(batchHeader1, add(0x20, 9)), shl(192, 0)) // l1MessagePopped
172+
mstore(add(batchHeader1, add(0x20, 17)), shl(192, 0)) // totalL1MessagePopped
173173
mstore(add(batchHeader1, add(0x20, 25)), 0x246394445f4fe64ed5598554d55d1682d6fb3fe04bf58eb54ef81d1189fafb51) // dataHash
174-
mstore(add(batchHeader1, add(0x20, 57)), blobVersionedHash) // blobVersionedHash
174+
mstore(add(batchHeader1, add(0x20, 57)), 0x013590dc3544d56629ba81bb14d4d31248f825001653aa575eb8e3a719046757) // blobVersionedHash
175175
mstore(add(batchHeader1, add(0x20, 89)), batchHash0) // parentBatchHash
176+
mstore(add(batchHeader1, add(0x20, 121)), 0) // lastBlockTimestamp
177+
mcopy(add(batchHeader1, add(0x20, 129)), add(blobDataProof, 0x20), 64) // blobDataProof
176178
}
177179

178180
hevm.startPrank(address(0));
179-
/*rollup.finalizeBatchWithProof4844(
180-
batchHeader1,
181-
bytes32(uint256(1)),
182-
bytes32(uint256(2)),
183-
messageHash,
184-
blobDataProof,
185-
new bytes(0)
186-
);*/
181+
rollup.finalizeBundleWithProof(batchHeader1, bytes32(uint256(2)), messageHash, new bytes(0));
187182
hevm.stopPrank();
183+
184+
rollup.lastFinalizedBatchIndex();
188185
}
189186
}

0 commit comments

Comments
 (0)