2
2
3
3
pragma solidity = 0.8.24 ;
4
4
5
- import {IScrollChain } from "./IScrollChain .sol " ;
5
+ import {ScrollChain } from "./ScrollChain .sol " ;
6
6
import {ZkTrieVerifier} from "../../libraries/verifier/ZkTrieVerifier.sol " ;
7
+ import {PatriciaMerkleTrieVerifier} from "../../libraries/verifier/PatriciaMerkleTrieVerifier.sol " ;
7
8
8
9
contract ScrollChainCommitmentVerifier {
9
10
/// @notice The address of poseidon hash contract
@@ -17,7 +18,7 @@ contract ScrollChainCommitmentVerifier {
17
18
rollup = _rollup;
18
19
}
19
20
20
- /// @notice Validates a proof from eth_getProof in l2geth.
21
+ /// @notice Validates a proof from eth_getProof in l2geth zktrie node .
21
22
/// @param account The address of the contract.
22
23
/// @param storageKey The storage slot to verify.
23
24
/// @param proof The rlp encoding result of eth_getProof.
@@ -37,6 +38,26 @@ contract ScrollChainCommitmentVerifier {
37
38
return ZkTrieVerifier.verifyZkTrieProof (poseidon, account, storageKey, proof);
38
39
}
39
40
41
+ /// @notice Validates a proof from eth_getProof in l2geth zktrie node.
42
+ /// @param account The address of the contract.
43
+ /// @param storageKey The storage slot to verify.
44
+ /// @param proof The rlp encoding result of eth_getProof.
45
+ /// @return stateRoot The computed state root. Must be checked by the caller.
46
+ /// @return storageValue The value of `storageKey`.
47
+ ///
48
+ /// The encoding order of `proof` is
49
+ /// ```text
50
+ /// | 1 byte | ... | 1 byte | ... |
51
+ /// | account proof length | account proof | storage proof length | storage proof |
52
+ /// ```
53
+ function verifyPatriciaMerkleTrieProof (
54
+ address account ,
55
+ bytes32 storageKey ,
56
+ bytes calldata proof
57
+ ) public pure returns (bytes32 stateRoot , bytes32 storageValue ) {
58
+ return PatriciaMerkleTrieVerifier.verifyPatriciaProof (account, storageKey, proof);
59
+ }
60
+
40
61
/// @notice Verifies a batch inclusion proof.
41
62
/// @param batchIndex The index of the batch.
42
63
/// @param account The address of the contract in L2.
@@ -49,11 +70,16 @@ contract ScrollChainCommitmentVerifier {
49
70
bytes32 storageKey ,
50
71
bytes calldata proof
51
72
) external view returns (bytes32 storageValue ) {
52
- require (IScrollChain (rollup).isBatchFinalized (batchIndex), "Batch not finalized " );
73
+ require (ScrollChain (rollup).isBatchFinalized (batchIndex), "Batch not finalized " );
53
74
54
75
bytes32 computedStateRoot;
55
- (computedStateRoot, storageValue) = verifyZkTrieProof (account, storageKey, proof);
56
- bytes32 expectedStateRoot = IScrollChain (rollup).finalizedStateRoots (batchIndex);
76
+ uint256 initialEuclidBatchIndex = ScrollChain (rollup).initialEuclidBatchIndex ();
77
+ if (batchIndex < initialEuclidBatchIndex) {
78
+ (computedStateRoot, storageValue) = verifyZkTrieProof (account, storageKey, proof);
79
+ } else {
80
+ (computedStateRoot, storageValue) = verifyPatriciaMerkleTrieProof (account, storageKey, proof);
81
+ }
82
+ bytes32 expectedStateRoot = ScrollChain (rollup).finalizedStateRoots (batchIndex);
57
83
require (computedStateRoot == expectedStateRoot, "Invalid inclusion proof " );
58
84
}
59
85
}
0 commit comments