8
8
import
9
9
std/ os,
10
10
unittest2,
11
- stew/ byteutils,
12
11
web3/ eth_api,
13
- nimcrypto/ [keccak, hash],
14
- eth/ common/ [keys, eth_types_rlp],
15
- eth/ [rlp, trie/ hexary_proof_verification],
16
12
../ execution_chain/ db/ [ledger, core_db],
17
13
../ execution_chain/ common/ chain_config,
18
- ../ execution_chain/ rpc/ server_api
14
+ ../ execution_chain/ rpc/ server_api,
15
+ ./ proof_helpers
19
16
20
17
type
21
18
Hash32 = eth_types.Hash32
22
19
Address = primitives.Address
23
20
24
- template toHash32 (hash: untyped ): Hash32 =
25
- fromHex (Hash32 , hash.toHex ())
26
-
27
- proc verifyAccountProof (trustedStateRoot: Hash32 , res: ProofResponse ): MptProofVerificationResult =
28
- let
29
- key = keccak256 (res.address.data)
30
- value = rlp.encode (Account (
31
- nonce: res.nonce.uint64 ,
32
- balance: res.balance,
33
- storageRoot: res.storageHash.toHash32 (),
34
- codeHash: res.codeHash.toHash32 ()))
35
-
36
- verifyMptProof (
37
- seq [seq [byte ]](res.accountProof),
38
- trustedStateRoot,
39
- key.data,
40
- value)
41
-
42
- proc verifySlotProof (trustedStorageRoot: Hash32 , slot: StorageProof ): MptProofVerificationResult =
43
- let
44
- key = keccak256 (toBytesBE (slot.key))
45
- value = rlp.encode (slot.value)
46
-
47
- verifyMptProof (
48
- seq [seq [byte ]](slot.proof),
49
- trustedStorageRoot,
50
- key.data,
51
- value)
52
-
53
21
proc getGenesisAlloc (filePath: string ): GenesisAlloc =
54
22
var cn: NetworkParams
55
23
if not loadNetworkParams (filePath, cn):
@@ -89,14 +57,14 @@ proc checkProofsForExistingLeafs(
89
57
proofResponse.balance == account.balance
90
58
proofResponse.codeHash.toHash32 () == accDB.getCodeHash (address)
91
59
proofResponse.storageHash.toHash32 () == accDB.getStorageRoot (address)
92
- verifyAccountProof (stateRoot, proofResponse). isValid ( )
60
+ verifyAccountLeafExists (stateRoot, proofResponse)
93
61
slotProofs.len () == account.storage.len ()
94
62
95
63
for i, slotProof in slotProofs:
96
64
check:
97
65
slotProof.key == slots[i]
98
66
slotProof.value == account.storage[slotProof.key]
99
- verifySlotProof (proofResponse.storageHash.toHash32 (), slotProof). isValid ( )
67
+ verifySlotLeafExists (proofResponse.storageHash.toHash32 (), slotProof)
100
68
101
69
proc checkProofsForMissingLeafs (
102
70
genAccounts: GenesisAlloc ,
@@ -106,7 +74,7 @@ proc checkProofsForMissingLeafs(
106
74
let
107
75
missingAddress = Address .fromHex (" 0x999999cf1046e68e36E1aA2E0E07105eDDD1f08E" )
108
76
proofResponse = getProof (accDB, missingAddress, @ [])
109
- check verifyAccountProof (stateRoot, proofResponse). isMissing ( )
77
+ check verifyAccountLeafMissing (stateRoot, proofResponse)
110
78
111
79
for address, account in genAccounts:
112
80
let
@@ -116,12 +84,19 @@ proc checkProofsForMissingLeafs(
116
84
117
85
check slotProofs.len () == 1
118
86
if account.storage.len () > 0 :
119
- check verifySlotProof (proofResponse2.storageHash.toHash32 (), slotProofs[0 ]).isMissing ()
120
-
87
+ check verifySlotLeafMissing (proofResponse2.storageHash.toHash32 (), slotProofs[0 ])
121
88
122
89
suite " Get proof json tests" :
123
90
124
- let genesisFiles = [" berlin2000.json" , " chainid1.json" , " chainid7.json" , " merge.json" , " devnet4.json" , " devnet5.json" , " holesky.json" ]
91
+ let genesisFiles = [
92
+ " berlin2000.json" ,
93
+ " chainid1.json" ,
94
+ " chainid7.json" ,
95
+ " merge.json" ,
96
+ " devnet4.json" ,
97
+ " devnet5.json" ,
98
+ " holesky.json"
99
+ ]
125
100
126
101
test " Get proofs for existing leafs" :
127
102
for file in genesisFiles:
0 commit comments