miden_crypto/merkle/smt/full/
error.rs1use alloc::string::String;
2
3use thiserror::Error;
4
5use crate::{
6 Word,
7 merkle::smt::{LeafIndex, MAX_LEAF_ENTRIES, SMT_DEPTH},
8};
9
10#[derive(Debug, Error)]
15pub enum SmtLeafError {
16 #[error(
18 "multiple leaf requires all keys to map to the same leaf index but key1 {key_1} and key2 {key_2} map to different indices"
19 )]
20 InconsistentMultipleLeafKeys { key_1: Word, key_2: Word },
22 #[error(
23 "single leaf key {key} maps to leaf {actual_leaf_index} but was expected to map to leaf {expected_leaf_index}"
24 )]
25 InconsistentSingleLeafIndices {
26 key: Word,
27 expected_leaf_index: LeafIndex<SMT_DEPTH>,
28 actual_leaf_index: LeafIndex<SMT_DEPTH>,
29 },
30
31 #[error(
33 "supplied leaf index {leaf_index_supplied:?} does not match {leaf_index_from_keys:?} for multiple leaf"
34 )]
35 InconsistentMultipleLeafIndices {
36 leaf_index_from_keys: LeafIndex<SMT_DEPTH>,
37 leaf_index_supplied: LeafIndex<SMT_DEPTH>,
38 },
39
40 #[error("multiple leaf requires at least two entries but only {0} were given")]
42 MultipleLeafRequiresTwoEntries(usize),
43
44 #[error(
46 "multiple leaf contains {actual} entries but the maximum allowed is {MAX_LEAF_ENTRIES}"
47 )]
48 TooManyLeafEntries { actual: usize },
49
50 #[error("decoding error: {0}")]
52 DecodingError(String),
53}
54
55#[derive(Debug, Error, PartialEq, Eq)]
60pub enum SmtProofError {
61 #[error("merkle path length {0} does not match SMT depth {SMT_DEPTH}")]
63 InvalidMerklePathLength(usize),
64
65 #[error("key maps to a different leaf index than the proof")]
67 InvalidKeyForProof,
68
69 #[error("value mismatch: expected {expected}, got {actual}")]
71 ValueMismatch { expected: Word, actual: Word },
72
73 #[error("expected merkle root {expected_root} found {actual_root}")]
75 ConflictingRoots { expected_root: Word, actual_root: Word },
76
77 #[error("key-value pair exists in the tree: key {key}, value {value}")]
79 ValuePresent { key: Word, value: Word },
80}