Skip to main content

Merkle Trees

An ALX Merkle tree combines one or more Block hashes into a single deterministic Merkle root hash. The Merkle root acts as a compact commitment to the complete leaf collection and can be stored, transmitted, or anchored on a blockchain without exposing Block content.

Merkle Tree Model

A single Merkle root represents an entire leaf collection. A verifier can prove that a specific Block hash is included in the collection committed by that Merkle root using a compact Merkle proof instead of retrieving or storing every Block hash.

Tree Construction

ALX constructs Merkle trees deterministically so every implementation produces the same Merkle root from the same leaf sequence after normalization and sorting.

The construction process:

  1. Normalize Block hashes to lowercase.
  2. Sort the leaf hashes.
  3. Group adjacent leaves into pairs.
  4. Order each pair deterministically.
  5. Hash each pair with Keccak-256.
  6. Promote an unpaired value to the next level unchanged.
  7. Repeat until one Merkle root remains.

The same normalized and sorted leaf sequence, including the same duplicate occurrences, produces the same Merkle root. Tree construction preserves duplicate leaves.

When to Use a Merkle Tree

Use a Merkle tree when one commitment must represent multiple Block hashes or when a verifier needs compact inclusion proofs.

If a commitment contains only one Block, use the Block's blockHash directly.