mssmt 0.0.5

A Rust implementation of the Merkle Sum Sparse Merkle Tree (MSSMT)
Documentation

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
  • Sum aggregation at each level
  • Cryptographic verification
  • Flexible storage backend through the Db trait

Features

  • Generic over hash size and hasher type
  • Thread-safe with optional multi-threading support
  • Memory-efficient storage with compact leaf nodes
  • Comprehensive test coverage
  • CI/CD pipeline with code coverage reporting

Usage

Add this to your Cargo.toml:

[dependencies]
merkle-sum-sparse-merkle-tree = "0.1.0"

Basic example:

use merkle_sum_sparse_merkle_tree::{MSSMT, MemoryDb};
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).unwrap();

// Insert a leaf
let leaf = Leaf::new(vec![1, 2, 3], 100);
tree.insert([1; 32], leaf).unwrap();

// Get the root hash
let root = tree.root().unwrap();

Development

Building

cargo build

Testing

cargo test

Code Coverage

cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info