miden-crypto/src/merkle/tiered_smt/error.rs
src/merkle/tiered_smt/error.rsRaw
1use core::fmt::Display;
2
3#[derive(Debug, PartialEq, Eq)]
4pub enum TieredSmtProofError {
5 EntriesEmpty,
6 EmptyValueNotAllowed,
7 MismatchedPrefixes(u64, u64),
8 MultipleEntriesOutsideLastTier,
9 NotATierPath(u8),
10 PathTooLong,
11}
12
13impl Display for TieredSmtProofError {
14 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
15 match self {
16 TieredSmtProofError::EntriesEmpty => {
17 write!(f, "Missing entries for tiered sparse merkle tree proof")
18 }
19 TieredSmtProofError::EmptyValueNotAllowed => {
20 write!(
21 f,
22 "The empty value [0, 0, 0, 0] is not allowed inside a tiered sparse merkle tree"
23 )
24 }
25 TieredSmtProofError::MismatchedPrefixes(first, second) => {
26 write!(f, "Not all leaves have the same prefix. First {first} second {second}")
27 }
28 TieredSmtProofError::MultipleEntriesOutsideLastTier => {
29 write!(f, "Multiple entries are only allowed for the last tier (depth 64)")
30 }
31 TieredSmtProofError::NotATierPath(got) => {
32 write!(
33 f,
34 "Path length does not correspond to a tier. Got {got} Expected one of 16, 32, 48, 64"
35 )
36 }
37 TieredSmtProofError::PathTooLong => {
38 write!(
39 f,
40 "Path longer than maximum depth of 64 for tiered sparse merkle tree proof"
41 )
42 }
43 }
44 }
45}
46
47#[cfg(feature = "std")]
48impl std::error::Error for TieredSmtProofError {}