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 InvalidSubtreeDepth { subtree_depth: u8, tree_depth: u8 },
17 InvalidPath(MerklePath),
18 InvalidNumEntries(usize),
19 NodeNotInSet(NodeIndex),
20 NodeNotInStore(RpoDigest, NodeIndex),
21 NumLeavesNotPowerOfTwo(usize),
22 RootNotInStore(RpoDigest),
23}
24
25impl fmt::Display for MerkleError {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 use MerkleError::*;
28 match self {
29 ConflictingRoots(roots) => write!(f, "the merkle paths roots do not match {roots:?}"),
30 DepthTooSmall(depth) => write!(f, "the provided depth {depth} is too small"),
31 DepthTooBig(depth) => write!(f, "the provided depth {depth} is too big"),
32 DuplicateValuesForIndex(key) => write!(f, "multiple values provided for key {key}"),
33 DuplicateValuesForKey(key) => write!(f, "multiple values provided for key {key}"),
34 InvalidIndex { depth, value } => {
35 write!(f, "the index value {value} is not valid for the depth {depth}")
36 }
37 InvalidDepth { expected, provided } => {
38 write!(f, "the provided depth {provided} is not valid for {expected}")
39 }
40 InvalidSubtreeDepth { subtree_depth, tree_depth } => {
41 write!(f, "tried inserting a subtree of depth {subtree_depth} into a tree of depth {tree_depth}")
42 }
43 InvalidPath(_path) => write!(f, "the provided path is not valid"),
44 InvalidNumEntries(max) => write!(f, "number of entries exceeded the maximum: {max}"),
45 NodeNotInSet(index) => write!(f, "the node with index ({index}) is not in the set"),
46 NodeNotInStore(hash, index) => {
47 write!(f, "the node {hash:?} with index ({index}) is not in the store")
48 }
49 NumLeavesNotPowerOfTwo(leaves) => {
50 write!(f, "the leaves count {leaves} is not a power of 2")
51 }
52 RootNotInStore(root) => write!(f, "the root {:?} is not in the store", root),
53 }
54 }
55}
56
57#[cfg(feature = "std")]
58impl std::error::Error for MerkleError {}