33use crate :: {
44 EMPTY_ROOT_HASH ,
55 nodes:: { BranchNode , CHILD_INDEX_RANGE , RlpNode , TrieNode } ,
6- proof:: ProofVerificationError ,
6+ proof:: { ProofVerificationError , RootMismatchError , ValueMismatchError } ,
77} ;
8- use alloc:: vec:: Vec ;
8+ use alloc:: { boxed :: Box , vec:: Vec } ;
99use alloy_primitives:: { B256 , Bytes } ;
1010use alloy_rlp:: { Decodable , EMPTY_STRING_CODE } ;
1111use core:: ops:: Deref ;
@@ -32,14 +32,17 @@ where
3232 if expected_value. is_none ( ) {
3333 Ok ( ( ) )
3434 } else {
35- Err ( ProofVerificationError :: ValueMismatch {
35+ Err ( ProofVerificationError :: ValueMismatch ( Box :: new ( ValueMismatchError {
3636 path : key,
3737 got : None ,
3838 expected : expected_value. map ( Bytes :: from) ,
39- } )
39+ } ) ) )
4040 }
4141 } else {
42- Err ( ProofVerificationError :: RootMismatch { got : EMPTY_ROOT_HASH , expected : root } )
42+ Err ( ProofVerificationError :: RootMismatch ( Box :: new ( RootMismatchError {
43+ got : EMPTY_ROOT_HASH ,
44+ expected : root,
45+ } ) ) )
4346 } ;
4447 }
4548
5154 if Some ( RlpNode :: from_rlp ( node) . as_slice ( ) ) != last_decoded_node. as_deref ( ) {
5255 let got = Some ( Bytes :: copy_from_slice ( node) ) ;
5356 let expected = last_decoded_node. as_deref ( ) . map ( Bytes :: copy_from_slice) ;
54- return Err ( ProofVerificationError :: ValueMismatch { path : walked_path, got, expected } ) ;
57+ return Err ( ProofVerificationError :: ValueMismatch ( Box :: new ( ValueMismatchError {
58+ path : walked_path,
59+ got,
60+ expected,
61+ } ) ) ) ;
5562 }
5663
5764 // Decode the next node from the proof.
@@ -64,11 +71,11 @@ where
6471 if last_decoded_node. as_deref ( ) == expected_value. as_deref ( ) {
6572 Ok ( ( ) )
6673 } else {
67- Err ( ProofVerificationError :: ValueMismatch {
74+ Err ( ProofVerificationError :: ValueMismatch ( Box :: new ( ValueMismatchError {
6875 path : key,
6976 got : last_decoded_node. as_deref ( ) . map ( Bytes :: copy_from_slice) ,
7077 expected : expected_value. map ( Bytes :: from) ,
71- } )
78+ } ) ) )
7279 }
7380}
7481
@@ -223,11 +230,11 @@ mod tests {
223230 BranchNode :: default ( ) . encode ( & mut dummy_proof) ;
224231 assert_eq ! (
225232 verify_proof( root, key, None , [ & Bytes :: from( dummy_proof. clone( ) ) ] ) ,
226- Err ( ProofVerificationError :: ValueMismatch {
233+ Err ( ProofVerificationError :: ValueMismatch ( Box :: new ( ValueMismatchError {
227234 path: Nibbles :: default ( ) ,
228235 got: Some ( Bytes :: from( dummy_proof) ) ,
229236 expected: Some ( Bytes :: from( RlpNode :: word_rlp( & EMPTY_ROOT_HASH ) [ ..] . to_vec( ) ) )
230- } )
237+ } ) ) )
231238 ) ;
232239 }
233240
@@ -254,21 +261,21 @@ mod tests {
254261 assert_eq ! ( verify_proof( root, first_key, Some ( first_value. clone( ) ) , & proof) , Ok ( ( ) ) ) ;
255262 assert_eq ! (
256263 verify_proof( root, first_key, None , & proof) ,
257- Err ( ProofVerificationError :: ValueMismatch {
264+ Err ( ProofVerificationError :: ValueMismatch ( Box :: new ( ValueMismatchError {
258265 path: first_key,
259266 got: Some ( first_value. into( ) ) ,
260267 expected: None ,
261- } )
268+ } ) ) )
262269 ) ;
263270
264271 assert_eq ! ( verify_proof( root, second_key, Some ( second_value. clone( ) ) , & proof) , Ok ( ( ) ) ) ;
265272 assert_eq ! (
266273 verify_proof( root, second_key, None , & proof) ,
267- Err ( ProofVerificationError :: ValueMismatch {
274+ Err ( ProofVerificationError :: ValueMismatch ( Box :: new ( ValueMismatchError {
268275 path: second_key,
269276 got: Some ( second_value. into( ) ) ,
270277 expected: None ,
271- } )
278+ } ) ) )
272279 ) ;
273280 }
274281
0 commit comments