Skip to main content

Crate malt

Crate malt 

Source
Expand description

§MALT

Merkle Append-Only Log Tree conforming to RFC 9162 §2.1.

This crate provides a generic, append-only Merkle tree parameterized by a TreeHasher trait. It supports incremental construction, root extraction, inclusion proofs, and consistency proofs.

The tree has zero external dependencies — callers provide their own hash implementation via TreeHasher.

§Usage

use malt::{Log, TreeHasher};

// Implement TreeHasher for your hash function, then:
let mut log = Log::new(my_hasher);
log.append(b"first entry");
log.append(b"second entry");
let root = log.root();

§Panic Policy

This crate uses expect() in two locations where the stack state is guaranteed by structural invariants:

  • Log::append — merge pops are bounded by count_trailing_ones(size), which guarantees sufficient stack depth by construction (A-STACK).
  • Log::root — fold over a non-empty stack (guarded by size > 0).

These are not input-validation panics. They guard invariants proven correct by the formal model (§3.4 A-STACK, A-EQUIV). Converting them to Result would impose API ergonomic cost for genuinely impossible errors.

Structs§

ConsistencyProof
Consistency proof — proves a tree of old_size is a prefix of new_size.
InclusionProof
Inclusion proof — proves a leaf at index exists in a tree of tree_size.
Log
A dense, append-only, left-filled Merkle tree (RFC 9162 §2.1).

Enums§

Error
Errors produced by MALT operations.

Traits§

TreeHasher
Hash abstraction for the Merkle tree.

Functions§

verify_consistency
Verify a consistency proof (formal model §5.3).
verify_inclusion
Verify an inclusion proof (formal model §4.3).