@@ -14,11 +14,12 @@ const ProofError = {
1414 INVALID_INTERNAL_NODE_HASH : 5 ,
1515 EMPTY_VALUE : 6 ,
1616 INVALID_EXTRA_PROOF_ELEMENT : 7 ,
17- INVALID_PATH_REMAINDER : 8 ,
18- INVALID_KEY_REMAINDER : 9 ,
19- UNKNOWN_NODE_PREFIX : 10 ,
20- UNPARSEABLE_NODE : 11 ,
21- INVALID_PROOF : 12 ,
17+ MISMATCH_LEAF_PATH_KEY_REMAINDERS : 8 ,
18+ INVALID_PATH_REMAINDER : 9 ,
19+ INVALID_KEY_REMAINDER : 10 ,
20+ UNKNOWN_NODE_PREFIX : 11 ,
21+ UNPARSEABLE_NODE : 12 ,
22+ INVALID_PROOF : 13 ,
2223} ;
2324
2425// Method eth_getProof is not supported with default Hardhat Network, so Anvil is used for that.
@@ -80,7 +81,7 @@ describe('TrieProof', function () {
8081 const slot = ethers . ZeroHash ;
8182 const tx = await call ( this . storage , 'setUint256Slot' , [ slot , 42 ] ) ;
8283 const { key, value, proof, storageHash } = await this . getProof ( this . storage , slot , tx ) ;
83- const result = await this . mock . $verify ( key , value , proof , storageHash ) ;
84+ const result = await this . mock . $verify ( ethers . keccak256 ( key ) , value , proof , storageHash ) ;
8485 expect ( result ) . is . true ;
8586 } ) ;
8687
@@ -90,7 +91,7 @@ describe('TrieProof', function () {
9091 await call ( this . storage , 'setUint256Slot' , [ slot0 , 42 ] ) ;
9192 const tx = await call ( this . storage , 'setUint256Slot' , [ slot1 , 43 ] ) ;
9293 const { key, value, proof, storageHash } = await this . getProof ( this . storage , slot1 , tx ) ;
93- const result = await this . mock . $verify ( key , value , proof , storageHash ) ;
94+ const result = await this . mock . $verify ( ethers . keccak256 ( key ) , value , proof , storageHash ) ;
9495 expect ( result ) . is . true ;
9596 } ) ;
9697
@@ -126,7 +127,7 @@ describe('TrieProof', function () {
126127 it . skip ( 'fails to process proof with invalid internal short node' , async function ( ) { } ) ; // TODO: INVALID_INTERNAL_NODE_HASH
127128
128129 it ( 'fails to process proof with empty value' , async function ( ) {
129- const proof = [ ethers . encodeRlp ( [ '0x20 ' , '0x' ] ) ] ; // Corrupt proof to yield empty value
130+ const proof = [ ethers . encodeRlp ( [ '0x2000 ' , '0x' ] ) ] ; // Corrupt proof to yield empty value
130131 const [ processedValue , error ] = await this . mock . $processProof ( '0x00' , proof , ethers . keccak256 ( proof [ 0 ] ) ) ;
131132 expect ( processedValue ) . to . equal ( '0x' ) ;
132133 expect ( error ) . to . equal ( ProofError . EMPTY_VALUE ) ;
@@ -137,11 +138,26 @@ describe('TrieProof', function () {
137138 const tx = await call ( this . storage , 'setUint256Slot' , [ slot0 , 42 ] ) ;
138139 const { key, proof, storageHash } = await this . getProof ( this . storage , slot0 , tx ) ;
139140 proof [ 1 ] = ethers . encodeRlp ( [ ] ) ; // extra proof element
140- const [ processedValue , error ] = await this . mock . $processProof ( key , proof , storageHash ) ;
141+ const [ processedValue , error ] = await this . mock . $processProof ( ethers . keccak256 ( key ) , proof , storageHash ) ;
141142 expect ( processedValue ) . to . equal ( '0x' ) ;
142143 expect ( error ) . to . equal ( ProofError . INVALID_EXTRA_PROOF_ELEMENT ) ;
143144 } ) ;
144145
146+ it ( 'fails to process proof with mismatched leaf path and key remainders' , async function ( ) {
147+ const slot = ethers . ZeroHash ;
148+ const key = ethers . keccak256 ( slot ) ;
149+ const value = '0x2a' ;
150+ const proof = [
151+ ethers . encodeRlp ( [
152+ '0x20' + ethers . toBeHex ( BigInt ( key ) + 1n ) . replace ( '0x' , '' ) , // corrupt end of leaf path
153+ value ,
154+ ] ) ,
155+ ] ;
156+ const [ processedValue , error ] = await this . mock . $processProof ( key , proof , ethers . keccak256 ( proof [ 0 ] ) ) ;
157+ expect ( processedValue ) . to . equal ( '0x' ) ;
158+ expect ( error ) . to . equal ( ProofError . MISMATCH_LEAF_PATH_KEY_REMAINDERS ) ;
159+ } ) ;
160+
145161 it ( 'fails to process proof with invalid path remainder' , async function ( ) {
146162 const proof = [ ethers . encodeRlp ( [ '0x0011' , '0x' ] ) ] ; // Corrupt proof to yield invalid path remainder
147163 const [ processedValue , error ] = await this . mock . $processProof ( ethers . ZeroHash , proof , ethers . keccak256 ( proof [ 0 ] ) ) ;
0 commit comments