miden_crypto/merkle/
error.rs

1use alloc::string::{String, ToString};
2
3use thiserror::Error;
4
5use super::{NodeIndex, Word, smt::MAX_LEAF_ENTRIES};
6
7#[derive(Debug, Error)]
8pub enum MerkleError {
9    #[error("expected merkle root {expected_root} found {actual_root}")]
10    ConflictingRoots { expected_root: Word, actual_root: Word },
11    #[error("provided merkle tree depth {0} is too small")]
12    DepthTooSmall(u8),
13    #[error("provided merkle tree depth {0} is too big")]
14    DepthTooBig(u64),
15    #[error("multiple values provided for merkle tree index {0}")]
16    DuplicateValuesForIndex(u64),
17    #[error("node index value {value} is not valid for depth {depth}")]
18    InvalidNodeIndex { depth: u8, value: u64 },
19    #[error("provided node index depth {provided} does not match expected depth {expected}")]
20    InvalidNodeIndexDepth { expected: u8, provided: u8 },
21    #[error("provided node list should have a minimum length of {0}")]
22    InvalidPathLength(usize),
23    #[error("merkle subtree depth {subtree_depth} exceeds merkle tree depth {tree_depth}")]
24    SubtreeDepthExceedsDepth { subtree_depth: u8, tree_depth: u8 },
25    #[error("number of entries in the merkle tree exceeds the maximum of 2^{0}")]
26    TooManyEntries(u8),
27    #[error("number of entries in a leaf ({actual}) exceeds the maximum of ({MAX_LEAF_ENTRIES})")]
28    TooManyLeafEntries { actual: usize },
29    #[error("node index `{0}` not found in the tree")]
30    NodeIndexNotFoundInTree(NodeIndex),
31    #[error("node {0:?} with index `{1}` not found in the store")]
32    NodeIndexNotFoundInStore(Word, NodeIndex),
33    #[error("number of provided merkle tree leaves {0} is not a power of two")]
34    NumLeavesNotPowerOfTwo(usize),
35    #[error("root {0:?} is not in the store")]
36    RootNotInStore(Word),
37    #[error("partial smt does not track the merkle path for key {0}")]
38    UntrackedKey(Word),
39    #[error("internal error: {0}")]
40    InternalError(String),
41}
42
43#[cfg(feature = "concurrent")]
44impl From<crate::merkle::smt::LargeSmtError> for MerkleError {
45    fn from(err: crate::merkle::smt::LargeSmtError) -> Self {
46        match err {
47            crate::merkle::smt::LargeSmtError::Merkle(me) => me,
48            crate::merkle::smt::LargeSmtError::Storage(se) => {
49                MerkleError::InternalError(se.to_string())
50            },
51        }
52    }
53}