Skip to content

Commit

Permalink
fix _loadBatchHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
zimpha committed Jan 24, 2025
1 parent 1934e40 commit 42cc20e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 46 deletions.
19 changes: 2 additions & 17 deletions src/L1/rollup/ScrollChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {

// update storage
lastFinalizedBatchIndex = batchIndex;
// batch is guaranteed to contain a single empty block, so withdraw root does not change
bytes32 withdrawRoot = withdrawRoots[batchIndex - 1];
finalizedStateRoots[batchIndex] = postStateRoot;
withdrawRoots[batchIndex] = withdrawRoot;
Expand Down Expand Up @@ -607,21 +608,6 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
emit FinalizeBatch(batchIndex, batchHash, postStateRoot, withdrawRoot);
}

/// @dev Internal function to check blob versioned hash.
/// @param _blobVersionedHash The blob versioned hash to check.
/// @param _blobDataProof The blob data proof used to verify the blob versioned hash.
function _checkBlobVersionedHash(bytes32 _blobVersionedHash, bytes calldata _blobDataProof) internal view {
// Calls the point evaluation precompile and verifies the output
(bool success, bytes memory data) = POINT_EVALUATION_PRECOMPILE_ADDR.staticcall(
abi.encodePacked(_blobVersionedHash, _blobDataProof)
);
// We verify that the point evaluation precompile call was successful by testing the latter 32 bytes of the
// response is equal to BLS_MODULUS as defined in https://eips.ethereum.org/EIPS/eip-4844#point-evaluation-precompile
if (!success) revert ErrorCallPointEvaluationPrecompileFailed();
(, uint256 result) = abi.decode(data, (uint256, uint256));
if (result != BLS_MODULUS) revert ErrorUnexpectedPointEvaluationPrecompileOutput();
}

/// @dev Internal function to check the `SkippedL1MessageBitmap`.
/// @param _totalL1MessagesPoppedOverall The total number of L1 messages popped after current batch.
/// @param _totalL1MessagesPoppedInBatch The total number of L1 messages popped in current batch.
Expand Down Expand Up @@ -840,8 +826,7 @@ contract ScrollChain is OwnableUpgradeable, PausableUpgradeable, IScrollChain {
}

uint256 _length;
// V0 and V5 share the same codec
if (version == 0 || version == 5) {
if (version == 0) {
(batchPtr, _length) = BatchHeaderV0Codec.loadAndValidate(_batchHeader);
} else if (version <= 2) {
(batchPtr, _length) = BatchHeaderV1Codec.loadAndValidate(_batchHeader);
Expand Down
30 changes: 1 addition & 29 deletions src/mocks/ScrollChainMockBlob.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,35 +72,7 @@ contract ScrollChainMockBlob is ScrollChain {
uint256 _totalL1MessagesPoppedOverall
)
{
// load version from batch header, it is always the first byte.
uint256 version;
assembly {
version := shr(248, calldataload(_batchHeader.offset))
}

uint256 _length;
if (version == 0) {
(batchPtr, _length) = BatchHeaderV0Codec.loadAndValidate(_batchHeader);
} else if (version <= 2) {
(batchPtr, _length) = BatchHeaderV1Codec.loadAndValidate(_batchHeader);
} else if (version >= 3) {
(batchPtr, _length) = BatchHeaderV3Codec.loadAndValidate(_batchHeader);
}

// the code for compute batch hash is the same for V0, V1, V2, V3
// also the `_batchIndex` and `_totalL1MessagesPoppedOverall`.
_batchHash = BatchHeaderV0Codec.computeBatchHash(batchPtr, _length);
_batchIndex = BatchHeaderV0Codec.getBatchIndex(batchPtr);
_totalL1MessagesPoppedOverall = BatchHeaderV0Codec.getTotalL1MessagePopped(batchPtr);

// only check when genesis is imported
if (
!overrideBatchHashCheck &&
committedBatches[_batchIndex] != _batchHash &&
finalizedStateRoots[0] != bytes32(0)
) {
revert ErrorIncorrectBatchHash();
}
(batchPtr, _batchHash, _batchIndex, _totalL1MessagesPoppedOverall) = ScrollChain._loadBatchHeader(_batchHeader);

if (overrideBatchHashCheck) {
_batchHash = committedBatches[_batchIndex];
Expand Down
1 change: 1 addition & 0 deletions src/test/ScrollChain.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ contract ScrollChainTest is DSTestPlus {

// commit 3 v6 batches
bytes memory v6Header1 = _commitBatch(6, v5Header, 1, 1);
//revert();
bytes memory v6Header2 = _commitBatch(6, v6Header1, 2, 1);
bytes memory v6Header3 = _commitBatch(6, v6Header2, 3, 1);

Expand Down

0 comments on commit 42cc20e

Please sign in to comment.