forked from scroll-tech/scroll-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScrollChainMockBlob.sol
109 lines (92 loc) · 3.77 KB
/
ScrollChainMockBlob.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// SPDX-License-Identifier: MIT
pragma solidity =0.8.24;
import {BatchHeaderV0Codec} from "../libraries/codec/BatchHeaderV0Codec.sol";
import {BatchHeaderV1Codec} from "../libraries/codec/BatchHeaderV1Codec.sol";
import {BatchHeaderV3Codec} from "../libraries/codec/BatchHeaderV3Codec.sol";
import {ScrollChain} from "../L1/rollup/ScrollChain.sol";
contract ScrollChainMockBlob is ScrollChain {
bytes32 blobVersionedHash;
bool overrideBatchHashCheck;
/***************
* Constructor *
***************/
/// @notice Constructor for `ScrollChain` implementation contract.
///
/// @param _chainId The chain id of L2.
/// @param _messageQueue The address of `L1MessageQueue` contract.
/// @param _verifier The address of zkevm verifier contract.
constructor(
uint64 _chainId,
address _messageQueue,
address _verifier
) ScrollChain(_chainId, _messageQueue, _verifier) {}
/**********************
* Internal Functions *
**********************/
function setBlobVersionedHash(bytes32 _blobVersionedHash) external {
blobVersionedHash = _blobVersionedHash;
}
function setLastFinalizedBatchIndex(uint256 index) external {
lastFinalizedBatchIndex = index;
}
function setFinalizedStateRoots(uint256 index, bytes32 value) external {
finalizedStateRoots[index] = value;
}
function setCommittedBatches(uint256 index, bytes32 value) external {
committedBatches[index] = value;
}
function setOverrideBatchHashCheck(bool status) external {
overrideBatchHashCheck = status;
}
function _getBlobVersionedHash() internal virtual override returns (bytes32 _blobVersionedHash) {
_blobVersionedHash = blobVersionedHash;
}
/// @dev Internal function to load batch header from calldata to memory.
/// @param _batchHeader The batch header in calldata.
/// @return batchPtr The start memory offset of loaded batch header.
/// @return _batchHash The hash of the loaded batch header.
/// @return _batchIndex The index of this batch.
/// @param _totalL1MessagesPoppedOverall The number of L1 messages popped after this batch.
function _loadBatchHeader(bytes calldata _batchHeader)
internal
view
virtual
override
returns (
uint256 batchPtr,
bytes32 _batchHash,
uint256 _batchIndex,
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();
}
if (overrideBatchHashCheck) {
_batchHash = committedBatches[_batchIndex];
}
}
}