arnaucube
arnaucube/miden-cryptoPublic Self-hosted repository
miden-crypto/src/merkle/error.rs
src/merkle/error.rsRaw
 1use crate::{
 2    merkle::{MerklePath, NodeIndex, RpoDigest},
 3    utils::collections::Vec,
 4};
 5use core::fmt;
 6
 7#[derive(Clone, Debug, PartialEq, Eq)]
 8pub enum MerkleError {
 9    ConflictingRoots(Vec<RpoDigest>),
10    DepthTooSmall(u8),
11    DepthTooBig(u64),
12    DuplicateValuesForIndex(u64),
13    DuplicateValuesForKey(RpoDigest),
14    InvalidIndex { depth: u8, value: u64 },
15    InvalidDepth { expected: u8, provided: u8 },
16    InvalidPath(MerklePath),
17    InvalidNumEntries(usize, usize),
18    NodeNotInSet(NodeIndex),
19    NodeNotInStore(RpoDigest, NodeIndex),
20    NumLeavesNotPowerOfTwo(usize),
21    RootNotInStore(RpoDigest),
22}
23
24impl fmt::Display for MerkleError {
25    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26        use MerkleError::*;
27        match self {
28            ConflictingRoots(roots) => write!(f, "the merkle paths roots do not match {roots:?}"),
29            DepthTooSmall(depth) => write!(f, "the provided depth {depth} is too small"),
30            DepthTooBig(depth) => write!(f, "the provided depth {depth} is too big"),
31            DuplicateValuesForIndex(key) => write!(f, "multiple values provided for key {key}"),
32            DuplicateValuesForKey(key) => write!(f, "multiple values provided for key {key}"),
33            InvalidIndex{ depth, value} => write!(
34                f,
35                "the index value {value} is not valid for the depth {depth}"
36            ),
37            InvalidDepth { expected, provided } => write!(
38                f,
39                "the provided depth {provided} is not valid for {expected}"
40            ),
41            InvalidPath(_path) => write!(f, "the provided path is not valid"),
42            InvalidNumEntries(max, provided) => write!(f, "the provided number of entries is {provided}, but the maximum for the given depth is {max}"),
43            NodeNotInSet(index) => write!(f, "the node with index ({index}) is not in the set"),
44            NodeNotInStore(hash, index) => write!(f, "the node {hash:?} with index ({index}) is not in the store"),
45            NumLeavesNotPowerOfTwo(leaves) => {
46                write!(f, "the leaves count {leaves} is not a power of 2")
47            }
48            RootNotInStore(root) => write!(f, "the root {:?} is not in the store", root),
49        }
50    }
51}
52
53#[cfg(feature = "std")]
54impl std::error::Error for MerkleError {}