alloy_trie/proof/
error.rs1use alloy_primitives::{Bytes, B256};
2use core::fmt;
3use nybbles::Nibbles;
4
5#[derive(PartialEq, Eq, Debug)]
7pub enum ProofVerificationError {
8 RootMismatch {
10 got: B256,
12 expected: B256,
14 },
15 ValueMismatch {
17 path: Nibbles,
19 got: Option<Bytes>,
21 expected: Option<Bytes>,
23 },
24 UnexpectedEmptyRoot,
26 Rlp(alloy_rlp::Error),
28}
29
30#[cfg(feature = "std")]
33impl 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
45impl 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
62impl From<alloy_rlp::Error> for ProofVerificationError {
63 fn from(source: alloy_rlp::Error) -> Self {
64 Self::Rlp(source)
65 }
66}