mirror of
https://github.com/arnaucube/miden-crypto.git
synced 2026-01-29 07:16:41 +01:00
* add conversion for `SmtLeaf` * introduce `SmtProof` scaffolding * implement `verify_membership()` * SmtLeaf: knows its index * `SmtLeaf::index` * `SmtLeaf::get_value()` returns an Option * fix `verify_membership()` * impl `SmtProof::get` * impl `into_parts()` * `SmtProof::compute_root` * use `SmtProof` in `Smt::open` * `SmtLeaf` constructors * Vec * impl `Error` for `SmtLeafError` * fix std Error * move Word/Digest conversions to LeafIndex * `SmtProof::new()` returns an error * `SparseMerkleTree::path_and_leaf_to_opening` * `SmtLeaf`: serializable/deserializable * `SmtProof`: serializable/deserializable * add tests for SmtLeaf serialization * move `SmtLeaf` to submodule * use constructors internally * fix docs * Add `Vec` * add `Vec` to tests * no_std use statements * fmt * `Errors`: make heading * use `SMT_DEPTH` * SmtLeaf single case: check leaf index * Multiple case: check consistency with leaf index * use `pub(super)` instead of `pub(crate)` * use `pub(super)` * `SmtLeaf`: add `num_entries()` accessor * Fix `SmtLeaf` serialization * improve leaf serialization tests
69 lines
2.7 KiB
Rust
69 lines
2.7 KiB
Rust
use crate::{
|
|
merkle::{MerklePath, NodeIndex, RpoDigest},
|
|
utils::collections::Vec,
|
|
};
|
|
use core::fmt;
|
|
|
|
use super::smt::SmtLeafError;
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub enum MerkleError {
|
|
ConflictingRoots(Vec<RpoDigest>),
|
|
DepthTooSmall(u8),
|
|
DepthTooBig(u64),
|
|
DuplicateValuesForIndex(u64),
|
|
DuplicateValuesForKey(RpoDigest),
|
|
InvalidIndex { depth: u8, value: u64 },
|
|
InvalidDepth { expected: u8, provided: u8 },
|
|
InvalidSubtreeDepth { subtree_depth: u8, tree_depth: u8 },
|
|
InvalidPath(MerklePath),
|
|
InvalidNumEntries(usize),
|
|
NodeNotInSet(NodeIndex),
|
|
NodeNotInStore(RpoDigest, NodeIndex),
|
|
NumLeavesNotPowerOfTwo(usize),
|
|
RootNotInStore(RpoDigest),
|
|
SmtLeaf(SmtLeafError),
|
|
}
|
|
|
|
impl fmt::Display for MerkleError {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
use MerkleError::*;
|
|
match self {
|
|
ConflictingRoots(roots) => write!(f, "the merkle paths roots do not match {roots:?}"),
|
|
DepthTooSmall(depth) => write!(f, "the provided depth {depth} is too small"),
|
|
DepthTooBig(depth) => write!(f, "the provided depth {depth} is too big"),
|
|
DuplicateValuesForIndex(key) => write!(f, "multiple values provided for key {key}"),
|
|
DuplicateValuesForKey(key) => write!(f, "multiple values provided for key {key}"),
|
|
InvalidIndex { depth, value } => {
|
|
write!(f, "the index value {value} is not valid for the depth {depth}")
|
|
}
|
|
InvalidDepth { expected, provided } => {
|
|
write!(f, "the provided depth {provided} is not valid for {expected}")
|
|
}
|
|
InvalidSubtreeDepth { subtree_depth, tree_depth } => {
|
|
write!(f, "tried inserting a subtree of depth {subtree_depth} into a tree of depth {tree_depth}")
|
|
}
|
|
InvalidPath(_path) => write!(f, "the provided path is not valid"),
|
|
InvalidNumEntries(max) => write!(f, "number of entries exceeded the maximum: {max}"),
|
|
NodeNotInSet(index) => write!(f, "the node with index ({index}) is not in the set"),
|
|
NodeNotInStore(hash, index) => {
|
|
write!(f, "the node {hash:?} with index ({index}) is not in the store")
|
|
}
|
|
NumLeavesNotPowerOfTwo(leaves) => {
|
|
write!(f, "the leaves count {leaves} is not a power of 2")
|
|
}
|
|
RootNotInStore(root) => write!(f, "the root {:?} is not in the store", root),
|
|
SmtLeaf(smt_leaf_error) => write!(f, "smt leaf error: {smt_leaf_error}"),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "std")]
|
|
impl std::error::Error for MerkleError {}
|
|
|
|
impl From<SmtLeafError> for MerkleError {
|
|
fn from(value: SmtLeafError) -> Self {
|
|
Self::SmtLeaf(value)
|
|
}
|
|
}
|