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 requires strictly increasing keys but key {next} does not follow key {previous}"
47 )]
48 UnsortedMultipleLeafKeys { previous: Word, next: Word },
49
50 #[error(
52 "multiple leaf contains {actual} entries but the maximum allowed is {MAX_LEAF_ENTRIES}"
53 )]
54 TooManyLeafEntries { actual: usize },
55
56 #[error("decoding error: {0}")]
58 DecodingError(String),
59}
60
61#[derive(Debug, Error, PartialEq, Eq)]
66pub enum SmtProofError {
67 #[error("merkle path length {0} does not match SMT depth {SMT_DEPTH}")]
69 InvalidMerklePathLength(usize),
70
71 #[error("key maps to a different leaf index than the proof")]
73 InvalidKeyForProof,
74
75 #[error("value mismatch: expected {expected}, got {actual}")]
77 ValueMismatch { expected: Word, actual: Word },
78
79 #[error("expected merkle root {expected_root} found {actual_root}")]
81 ConflictingRoots { expected_root: Word, actual_root: Word },
82
83 #[error("key-value pair exists in the tree: key {key}, value {value}")]
85 ValuePresent { key: Word, value: Word },
86}