| Crates.io | mssmt |
| lib.rs | mssmt |
| version | 0.0.7 |
| created_at | 2024-10-25 16:21:16.08227+00 |
| updated_at | 2025-03-12 17:37:06.08453+00 |
| description | A Rust implementation of the Merkle Sum Sparse Merkle Tree (MSSMT) |
| homepage | |
| repository | https://github.com/keep-starknet-strange/mssmt-rs |
| max_upload_size | |
| id | 1422702 |
| size | 6,598,402 |
A Rust implementation of the Merkle Sum Sparse Merkle Tree (MSSMT) based on Lightning Labs' implementation.
The Merkle Sum Sparse Merkle Tree combines the properties of both Merkle Sum Trees and Sparse Merkle Trees, providing:
Db traitAdd this to your Cargo.toml:
[dependencies]
merkle-sum-sparse-merkle-tree = "0.6.0"
Basic example using regular tree:
use merkle_sum_sparse_merkle_tree::{MSSMT, MemoryDb, Leaf};
use sha2::Sha256;
// Create a new tree with 32-byte hashes using SHA256
let db = Box::new(MemoryDb::<32, Sha256>::new());
let mut tree = MSSMT::<32, Sha256, ()>::new(db);
// Insert a leaf
let leaf = Leaf::new(vec![1, 2, 3], 100);
tree.insert(&[1; 32], leaf).unwrap();
// Get and verify a merkle proof
let proof = tree.merkle_proof(&[1; 32]).unwrap();
let root = tree.root().unwrap();
proof.verify_merkle_proof(&[1; 32], leaf, root.hash()).unwrap();
Example using compact tree for better memory efficiency:
use merkle_sum_sparse_merkle_tree::{CompactMSSMT, MemoryDb, Leaf};
use sha2::Sha256;
// Create a new compact tree
let db = Box::new(MemoryDb::<32, Sha256>::new());
let mut tree = CompactMSSMT::<32, Sha256, ()>::new(db);
// Insert leaves
let leaf = Leaf::new(vec![1, 2, 3], 100);
tree.insert(&[1; 32], leaf.clone()).unwrap();
// Get and verify compressed proofs
let proof = tree.merkle_proof(&[1; 32]).unwrap();
let compressed = proof.compress();
let decompressed = compressed.decompress().unwrap();
cargo build
cargo test
cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
cargo bench