Skip to main content

Crate moloch_mmr

Crate moloch_mmr 

Source
Expand description

Merkle Mountain Range (MMR) implementation.

An MMR is an append-only data structure that provides:

  • O(1) amortized append
  • O(log n) inclusion proofs
  • O(log n) consistency proofs

The structure consists of a series of perfect binary trees (“mountains”) of decreasing height. When a new leaf is appended, it may trigger merging of equal-height trees.

§Example

use moloch_mmr::{Mmr, MemStore};
use moloch_core::hash;

let mut mmr = Mmr::new(MemStore::new());

// Append some leaves
let pos1 = mmr.append(hash(b"event1")).unwrap();
let pos2 = mmr.append(hash(b"event2")).unwrap();
let pos3 = mmr.append(hash(b"event3")).unwrap();

// Get inclusion proof
let proof = mmr.proof(pos1).unwrap();
assert!(mmr.verify(&proof).unwrap());

// Get the root
let root = mmr.root();

Structs§

MemStore
In-memory MMR store (for testing and small datasets).
Mmr
Merkle Mountain Range.
MmrProof
MMR inclusion proof.

Traits§

MmrStore
Trait for MMR node storage.