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),
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 } => {
34                write!(f, "the index value {value} is not valid for the depth {depth}")
35            }
36            InvalidDepth { expected, provided } => {
37                write!(f, "the provided depth {provided} is not valid for {expected}")
38            }
39            InvalidPath(_path) => write!(f, "the provided path is not valid"),
40            InvalidNumEntries(max) => write!(f, "number of entries exceeded the maximum: {max}"),
41            NodeNotInSet(index) => write!(f, "the node with index ({index}) is not in the set"),
42            NodeNotInStore(hash, index) => {
43                write!(f, "the node {hash:?} with index ({index}) is not in the store")
44            }
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 {}