| Crates.io | merkle-tree-accumulator |
| lib.rs | merkle-tree-accumulator |
| version | 0.3.0 |
| created_at | 2021-08-30 07:33:43.86004+00 |
| updated_at | 2026-01-01 00:31:19.189513+00 |
| description | A simple, append-only Merkle tree-based cryptographic accumulator |
| homepage | |
| repository | https://github.com/kobby-pentangeli/merkle-tree-accumulator |
| max_upload_size | |
| id | 444057 |
| size | 90,032 |
A simple, append-only Merkle tree-based cryptographic accumulator.
Add this to your Cargo.toml:
[dependencies]
merkle-tree-accumulator = "0.3"
use merkle_tree_accumulator::{Hash, Sha3Accumulator};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a new accumulator
let mut acc = Sha3Accumulator::new();
// Add some data
let data = b"Hello, World!";
let hash = Hash::from_data(data);
acc.add(hash)?;
// Generate a proof of membership
let proof = acc.prove(&[0])?;
// Verify the proof
acc.verify(&proof, &[hash])?;
println!("Proof verified!");
Ok(())
}
use merkle_tree_accumulator::{Hash, Sha3Accumulator};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut acc = Sha3Accumulator::new();
// Add multiple items
let items = vec![b"item1", b"item2", b"item3", b"item4"];
let hashes: Vec<_> = items.iter()
.map(|data| Hash::from_data(data))
.collect();
for hash in &hashes {
acc.add(*hash)?;
}
// Generate a compact batch proof for indices [0, 2]
let batch_proof = acc.prove(&[0, 2])?;
// Verify the batch proof
let batch_leaves = vec![hashes[0], hashes[2]];
acc.verify(&batch_proof, &batch_leaves)?;
println!("Batch proof verified!");
Ok(())
}
The library supports three hash functions, each optimized for different use cases:
| Hasher | Domain | Performance | Use Case |
|---|---|---|---|
| SHA3-256 (default) | General Purpose | Standard | Compliance, broad compatibility, NIST standardized |
| BLAKE3 | High Performance | Faster than SHA3 | Blockchains, distributed systems, throughput-critical |
| Poseidon | Arithmetic Circuits | Optimized for circuits | ZK proofs, field arithmetic operations |
Enable the blake3 feature:
[dependencies]
merkle-tree-accumulator = { version = "0.3", features = ["blake3"] }
use merkle_tree_accumulator::{Hash, Blake3Accumulator};
let mut acc = Blake3Accumulator::new();
acc.add(Hash::from_data(b"high-performance data"))?;
Enable the poseidon feature:
[dependencies]
merkle-tree-accumulator = { version = "0.3", features = ["poseidon"] }
use merkle_tree_accumulator::{Hash, PoseidonAccumulator};
let mut acc = PoseidonAccumulator::new();
acc.add(Hash::from_data(b"zk-friendly data"))?;
Note:
Hash::from_data()uses SHA3-256 to create leaf hashes. The accumulator's hasher (BLAKE3, Poseidon) is used for internal tree operations. This design allows consistent leaf creation across different tree types. For end-to-end usage of a specific hasher, use thers_merkle::Hashertrait directly:Hash::new(Blake3H::hash(data)).
Run examples with:
cargo run --example hello_world
cargo run --example hasher_comparison --all-features
std (default): Enable standard library supportblake3: Enable BLAKE3 hasher for high-performance applicationsposeidon: Enable Poseidon hasher for algebraic hash operationsThe library works in no_std environments:
[dependencies]
merkle-tree-accumulator = { version = "0.3", default-features = false }
Contributions are welcome! Please read our Contributing Guidelines and Code of Conduct.
Licensed under either of
at your option.