Merkle Sum Sparse Merkle Tree
A Rust implementation of the Merkle Sum Sparse Merkle Tree (MSSMT) based on Lightning Labs' implementation.
Overview
The Merkle Sum Sparse Merkle Tree combines the properties of both Merkle Sum Trees and Sparse Merkle Trees, providing:
- Efficient sparse storage with compact proofs
- Sum aggregation at each level
- Cryptographic verification
- Flexible storage backend through the
Dbtrait - Support for both regular and compact tree implementations
Features
- Generic over hash size and hasher type
- Thread-safe with optional multi-threading support
- Memory-efficient storage with compact leaf nodes
- Proof compression and decompression
- Comprehensive test coverage including BIP test vectors
- CI/CD pipeline with code coverage reporting
Usage
Add this to your Cargo.toml:
[]
= "0.6.0"
Basic example using regular tree:
use ;
use Sha256;
// Create a new tree with 32-byte hashes using SHA256
let db = Boxnew;
let mut tree = MSSMT::new;
// Insert a leaf
let leaf = new;
tree.insert.unwrap;
// Get and verify a merkle proof
let proof = tree.merkle_proof.unwrap;
let root = tree.root.unwrap;
proof.verify_merkle_proof.unwrap;
Example using compact tree for better memory efficiency:
use ;
use Sha256;
// Create a new compact tree
let db = Boxnew;
let mut tree = new;
// Insert leaves
let leaf = new;
tree.insert.unwrap;
// Get and verify compressed proofs
let proof = tree.merkle_proof.unwrap;
let compressed = proof.compress;
let decompressed = compressed.decompress.unwrap;
Development
Building
Testing
Code Coverage
Benchmarking