V2 development draft · Source at 00505898

Header History Merkle Tree (HEADER_HISTORY)

Status: the consensus commitment is implemented in lotusd (src/lotus_v2/header_history.{h,cpp}) and specified in P02. The proof RPCs are not implemented. The tree and its verifier exist in the node, but nothing serves a proof, and the proof format can't yet be tied to a block header. Section 3.5 describes what is missing and the open anchor question. The light-client flow described in section 1 is the goal this enables, not something available today.


1. Why: Trustless Historical Finality in Kilobytes

<div class="lens-grid"> <div class="lens-card lens-consumer">

In Practice

When you open a wallet on your phone or browser, or verify an older payment or cross-chain proof, how does your app know that a block from six months ago really happened on the canonical Lotus blockchain—without downloading tens of gigabytes of history?

In legacy blockchains, each block header only points to the immediately previous block (prev_block_hash). Proving that Block #100,000 is part of the chain at Block #1,000,000 requires downloading all 900,000 headers in between (~72–120 MB of linear chain links).

With the Header History Merkle Tree, every Lotus V2 block header cryptographically seals a compact fingerprint (history_root) of every block hash from Genesis up to its parent. Any device only needs the latest 134-byte header (confirmed by Avalanche/PoW) plus a ~1 KB cryptographic proof (HeaderInclusionProof) to verify any historical block in less than a millisecond.

</div> <div class="lens-card lens-engineer">

Under the Hood

Linear hash chains ($H_{n} \to H_{n-1} \to \dots \to H_0$) require $O(N)$ bandwidth and $O(N)$ verification work to prove historical ancestry across $N$ blocks. FlyClient / MMR constructions solve this with logarithmic peaks, but naive MMR bagging either changes tree topology across heights or requires separate peak-bagging proofs.

Lotus V2 embeds a canonical Binary Carry-Chain Mountain Frontier (HeaderHistoryFrontier) directly into MonetaryState::history_root (committed inside the 134-byte header's hashStateRoot):

</div> </div>


2. HOW: The Binary Carry-Chain Frontier

Every block at height $H \ge 1$ commits to the ordered sequence of all $H$ prior canonical block hashes:

$$\big(0,, \text{BlockID}_0\big),; \big(1,, \text{BlockID}1\big),; \dots,; \big(H-1,, \text{BlockID}{H-1}\big)$$

How Binary Carry Addition Builds the Tree

Think of the block count $H$ written in binary. Each set bit $k$ where ((H >> k) & 1) == 1 represents one complete, immutable binary subtree of exactly $2^k$ headers (peaks[k]):

flowchart TD
    subgraph Peaks["Active Frontier at count = 6 (binary 110₂: peaks[2] and peaks[1])"]
        P2["peaks[2]: Level 2 Subtree Root<br/>(Heights 0..3, 4 leaves)"]
        P1["peaks[1]: Level 1 Subtree Root<br/>(Heights 4..5, 2 leaves)"]
    end
    subgraph RootFold["HeaderHistoryRoot(count = 6)"]
        R1["acc₁ = InternalHash(level=1, peaks[1], NULL_HASH)"]
        R2["tree_root = InternalHash(level=2, peaks[2], acc₁)"]
        R3["history_root = CountBinding(count=6, tree_root)"]
    end
    P1 --> R1
    P2 --> R2
    R1 --> R2
    R2 --> R3

When block $H$ is appended (AppendHeaderToFrontier):

  1. Compute carry = HeaderLeafHash(ChainID, H, BlockID_H).
  2. Walk bit positions $k = 0, 1, \dots, 63$:
    • Bit $k$ is 0: Slot $k$ is empty! Place peaks[k] = carry, increment count = H + 1, and stop immediately.
    • Bit $k$ is 1: Slot $k$ already holds a complete $2^k$-leaf subtree peaks[k]. Merge it with our carry to form a complete $2^{k+1}$-leaf subtree (carry = HeaderInternalHash(ChainID, k, peaks[k], carry)), clear peaks[k] = 0x00^32, and carry into level $k + 1$.

Because half of all integers have bit $0 = 0$, 50% of blocks require zero internal node hashes, 25% require 1 internal hash, 12.5% require 2, and the average number of internal hashes per block as $H \to \infty$ is less than 1.


3. WHAT: Exact Cryptographic Specification

3.1 Domain-Separated Leaf and Internal Hashes

All hashes use unkeyed 32-byte BLAKE3 (C08, C26) with domain tag "Lotus/v2/header/history" (H_header_history(x) = BLAKE3("Lotus/v2/header/history" || 0x00 || x) in src/lotus_v2/tagged_hash.cpp):

NULL_HASH = 0x00^32

HeaderLeafHash(ChainID, height: u64, block_hash: h32) -> h32:
  H_header_history(ChainID || 0x00 || u64_le(height) || block_hash)

HeaderInternalHash(ChainID, level: u8, left: h32, right: h32) -> h32:
  H_header_history(ChainID || 0x01 || u8(level) || left || right)

HeaderCountBinding(ChainID, count: u64, tree_root: h32) -> h32:
  H_header_history(ChainID || 0x02 || u64_le(count) || tree_root)

3.2 Computing HeaderHistoryRoot from HeaderHistoryFrontier

Given frontier with count committed prior headers:

3.3 Canonical Inclusion Proofs (HeaderInclusionProof)

A proof that block_hash was the canonical block at leaf_height inside a chain of total_count committed headers (leaf_height < total_count) is serialized as:

HeaderInclusionProof =
    u64_le(leaf_height)
 || u64_le(total_count)
 || block_hash:h32
 || u8(num_siblings)
 || siblings: h32[num_siblings]

Verification Algorithm (VerifyHeaderInclusionProof)

  1. Bounds check: Require total_count > 0 and leaf_height < total_count.
  2. Exact depth check: Let tree depth $D$ be: $$D = \begin{cases} \text{ctz}(\text{total_count}) & \text{if } (\text{total_count} \mathbin{&} (\text{total_count} - 1)) = 0 \ 64 - \text{clz}(\text{total_count}) & \text{otherwise} \end{cases}$$ Require siblings.size() == D.
  3. Bottom-up fold with canonical null-sibling check: Initialize cur = HeaderLeafHash(ChainID, leaf_height, block_hash). For $k = 0, 1, \dots, D - 1$:
    • Let idx = leaf_height >> k.
    • If (idx & 1) == 0 (left child):
      • Let right_subtree_start = (idx + 1) << k.
      • Canonical null-sibling rule: If right_subtree_start >= total_count (no leaves exist in the right child subtree at level $k$), require siblings[k] == NULL_HASH.
      • Set cur = HeaderInternalHash(ChainID, k, cur, siblings[k]).
    • Else ((idx & 1) == 1, right child):
      • Set cur = HeaderInternalHash(ChainID, k, siblings[k], cur).
  4. Root comparison: Return HeaderCountBinding(ChainID, total_count, cur) == expected_root.

lotus_v2_header_history_tests has known-answer vectors for these hashes, computed independently of the node from the formulas above.

3.4 Node Storage

3.5 Not Implemented: Proof RPCs

No RPC serves or checks these proofs. An earlier draft defined getheaderhistoryproof and verifyheaderhistoryproof; they were left out because a proof built that way can't be tied to a chain header, so valid: true would only show that a hash chain is internally consistent.

Before proofs can be offered, a design has to settle:

  1. What the anchor is (open question). Block $H$ commits only the $H$ blocks below it, so the root over blocks $0..H$ is committed by block $H + 1$. Either the anchor is "the highest block covered", in which case its root is committed by the next block and the root for the current tip isn't committed by anything yet, or the anchor is "the block whose header commits the root", in which case the count equals the anchor's height, height 0 can't be an anchor, and the tip can't prove itself.
  2. How to open state_root. history_root sits inside StateRoot(chain, height, utxo_root, monetary || history_root). A client holding only a header needs utxo_root and the 56-byte monetary state as well, so the proof must carry them. The roughly 1 KB size in section 1 assumes this is solved and doesn't include them.
  3. What the verifier takes. It should resolve an anchor block and compare against its header, rather than accept a root from the caller.

References

  1. [Merkle 1987] Ralph C. Merkle, "A Digital Signature Based on a Conventional Encryption Function", in Advances in Cryptology — CRYPTO '87, Lecture Notes in Computer Science, vol. 293, pp. 369–378, Springer, 1988.
  2. [Crosby & Wallach 2009] Scott A. Crosby and Dan S. Wallach, "Efficient Data Structures for Tamper-Evident Logging", in Proceedings of the 18th USENIX Security Symposium, pp. 317–334, August 2009.
  3. [Todd 2012/2016] Peter Todd, "Merkle Mountain Ranges", OpenTimestamps / Bitcoin Core developer notes, 2012–2016.
  4. [Bünz, Kiffer, Luu, & Zamani 2020] Benedikt Bünz, Lucianna Kiffer, Loi Luu, and Mahdi Zamani, "FlyClient: Super-Light Clients for Cryptocurrencies", in 2020 IEEE Symposium on Security and Privacy (SP), pp. 928–946, May 2020.
  5. [O'Connor, Aumasson, Neves, & Wilcox-O'Hearn 2020] Jack O'Connor, Jean-Philippe Aumasson, Samuel Neves, and Zooko Wilcox-O'Hearn, "BLAKE3: One Function, Fast Everywhere", January 2020 (https://github.com/BLAKE3-team/BLAKE3-specs).
  6. [Nakamoto 2008] Satoshi Nakamoto, "Bitcoin: A Peer-to-Peer Electronic Cash System", October 2008 (https://bitcoin.org/bitcoin.pdf).