11use alloy_primitives:: { B256 , Bytes } ;
2- use core:: fmt;
32use nybbles:: Nibbles ;
43
54/// Error during proof verification.
6- #[ derive( PartialEq , Eq , Debug ) ]
5+ #[ derive( PartialEq , Eq , Debug , thiserror :: Error ) ]
76pub enum ProofVerificationError {
87 /// State root does not match the expected.
8+ #[ error( "root mismatch. got: {got}. expected: {expected}" ) ]
99 RootMismatch {
1010 /// Computed state root.
1111 got : B256 ,
1212 /// State root provided to verify function.
1313 expected : B256 ,
1414 } ,
1515 /// The node value does not match at specified path.
16+ #[ error( "value mismatch at path {path:?}. got: {got:?}. expected: {expected:?}" ) ]
1617 ValueMismatch {
1718 /// Path at which error occurred.
1819 path : Nibbles ,
@@ -22,45 +23,9 @@ pub enum ProofVerificationError {
2223 expected : Option < Bytes > ,
2324 } ,
2425 /// Encountered unexpected empty root node.
26+ #[ error( "unexpected empty root node" ) ]
2527 UnexpectedEmptyRoot ,
2628 /// Error during RLP decoding of trie node.
27- Rlp ( alloy_rlp:: Error ) ,
28- }
29-
30- /// Enable Error trait implementation when core is stabilized.
31- /// <https://github.com/rust-lang/rust/issues/103765>
32- #[ cfg( feature = "std" ) ]
33- impl std:: error:: Error for ProofVerificationError {
34- fn source ( & self ) -> :: core:: option:: Option < & ( dyn std:: error:: Error + ' static ) > {
35- #[ allow( deprecated) ]
36- match self {
37- Self :: Rlp { 0 : transparent } => {
38- std:: error:: Error :: source ( transparent as & dyn std:: error:: Error )
39- }
40- _ => None ,
41- }
42- }
43- }
44-
45- impl fmt:: Display for ProofVerificationError {
46- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
47- match self {
48- Self :: RootMismatch { got, expected } => {
49- write ! ( f, "root mismatch. got: {got}. expected: {expected}" )
50- }
51- Self :: ValueMismatch { path, got, expected } => {
52- write ! ( f, "value mismatch at path {path:?}. got: {got:?}. expected: {expected:?}" )
53- }
54- Self :: UnexpectedEmptyRoot => {
55- write ! ( f, "unexpected empty root node" )
56- }
57- Self :: Rlp ( error) => fmt:: Display :: fmt ( error, f) ,
58- }
59- }
60- }
61-
62- impl From < alloy_rlp:: Error > for ProofVerificationError {
63- fn from ( source : alloy_rlp:: Error ) -> Self {
64- Self :: Rlp ( source)
65- }
29+ #[ error( transparent) ]
30+ Rlp ( #[ from] alloy_rlp:: Error ) ,
6631}
0 commit comments