miden_crypto/merkle/smt/full/
error.rs

1use thiserror::Error;
2
3use crate::{
4    Word,
5    merkle::{LeafIndex, SMT_DEPTH},
6};
7
8// SMT LEAF ERROR
9// =================================================================================================
10
11/// Errors that can occur when constructing or validating SMT leaves.
12#[derive(Debug, Error)]
13pub enum SmtLeafError {
14    /// Keys map to different leaf indices in a multiple-leaf structure.
15    #[error(
16        "multiple leaf requires all keys to map to the same leaf index but key1 {key_1} and key2 {key_2} map to different indices"
17    )]
18    /// A single leaf key maps to a different index than expected.
19    InconsistentMultipleLeafKeys { key_1: Word, key_2: Word },
20    #[error(
21        "single leaf key {key} maps to leaf {actual_leaf_index} but was expected to map to leaf {expected_leaf_index}"
22    )]
23    InconsistentSingleLeafIndices {
24        key: Word,
25        expected_leaf_index: LeafIndex<SMT_DEPTH>,
26        actual_leaf_index: LeafIndex<SMT_DEPTH>,
27    },
28
29    /// Supplied leaf index does not match the expected index for the provided keys.
30    #[error(
31        "supplied leaf index {leaf_index_supplied:?} does not match {leaf_index_from_keys:?} for multiple leaf"
32    )]
33    InconsistentMultipleLeafIndices {
34        leaf_index_from_keys: LeafIndex<SMT_DEPTH>,
35        leaf_index_supplied: LeafIndex<SMT_DEPTH>,
36    },
37
38    /// Multiple leaf requires at least two entries, but fewer were provided.
39    #[error("multiple leaf requires at least two entries but only {0} were given")]
40    MultipleLeafRequiresTwoEntries(usize),
41}
42
43// SMT PROOF ERROR
44// =================================================================================================
45
46/// Errors that can occur when validating SMT proofs.
47#[derive(Debug, Error)]
48pub enum SmtProofError {
49    /// The length of the provided Merkle path is not [`SMT_DEPTH`].
50    #[error("merkle path length {0} does not match SMT depth {SMT_DEPTH}")]
51    InvalidMerklePathLength(usize),
52}