lean_imt/lib.rs
1//! # Lean IMT
2//!
3//! LeanIMT provides an optimized incremental Merkle tree (IMT) implementation tailored for efficient, binary-based hashing without relying on zero values for incomplete nodes. It dynamically adjusts its depth based on leaf insertions, significantly reducing computational overhead.
4//!
5//! ## Quick Start
6//!
7//! Add the crate to your Cargo.toml:
8//!
9//! ```toml
10//! zk-kit-lean-imt = { git = "https://github.com/privacy-scaling-explorations/zk-kit.rust", package = "zk-kit-lean-imt" }
11//! ```
12//!
13//! ## Example
14//! ```rust
15//! use lean_imt::hashed_tree::{HashedLeanIMT, LeanIMTHasher};
16//! use std::collections::hash_map::DefaultHasher;
17//! use std::hash::{Hash, Hasher};
18//!
19//! struct SampleHasher;
20//!
21//! impl LeanIMTHasher<32> for SampleHasher {
22//! fn hash(input: &[u8]) -> [u8; 32] {
23//! let mut hasher = DefaultHasher::new();
24//! input.hash(&mut hasher);
25//! let h = hasher.finish();
26//!
27//! let mut result = [0u8; 32];
28//! result[..8].copy_from_slice(&h.to_le_bytes());
29//! result
30//! }
31//! }
32//!
33//! fn main() {
34//! let mut tree = HashedLeanIMT::<32, SampleHasher>::new(&[], SampleHasher).unwrap();
35//!
36//! tree.insert(&[1; 32]);
37//! tree.insert(&[2; 32]);
38//! tree.insert_many(&[[3; 32], [4; 32], [5; 32]]);
39//!
40//! println!("Tree root: {:?}", tree.root().unwrap());
41//! println!("Tree depth: {}", tree.depth());
42//!
43//! let proof = tree.generate_proof(3).unwrap();
44//! assert!(HashedLeanIMT::<32, SampleHasher>::verify_proof(&proof));
45//! }
46//! ```
47
48pub mod hashed_tree;
49pub mod lean_imt;
50
51#[cfg(feature = "stateless")]
52pub mod stateless;