Epoch ledger
Purpose
Each epoch, operators commit their chips' reports to a Merkle tree whose leaves are sorted by key, and the global root is anchored on Bitcoin. Sorting is what makes absence provable: anyone can show that a registered chip is missing from an epoch. That proof is the paper's "omission" slashing predicate. This module builds those trees, proves inclusion and non-membership against a committed root, and produces the epoch records that are anchored.
Data formats
All hashes are SHA-256 from @noble/hashes. Domain separation uses a one-byte prefix on every hash input (the RFC 6962 style), not BIP340 tagged hashes.
| Object | Definition |
|---|---|
| entry | (key: 32 bytes, value: bytes). Keys are unique; the tree sorts them lexicographically. |
| leaf | H(0x00 || key || H(value)) |
| interior node | H(0x01 || left || right) |
| odd node | promoted to the next level unchanged, never paired with a copy of itself |
| empty Merkle root | H("Firebreak/ledger/empty"), a fixed tag |
| committed root | H(0x02 || u64le(size) || merkleRoot). This is the value proofs are checked against and epochs commit to. |
| epoch record | { epoch, prevRoot, root, size } |
| epoch commitment | H(0x03 || u64le(epoch) || prevRoot || root || u64le(size)) |
| anchor payload | "FBK1" || epochCommitment, 36 bytes, carried in an OP_RETURN output |
prevRoot is the previous record's commitment (32 zero bytes for epoch 0), so the anchored commitments form a hash chain. linksTo(prev, next) checks one link. parseAnchorPayload reads the commitment back out of OP_RETURN data.
Proofs
Inclusion:
{ index, siblings[] }. The verifier walks from the leaf to the root. At each level, the size decides whether the node has a sibling (left if the index is odd, right if a right neighbor exists) or was promoted. The proof must contain exactly the expected number of siblings.Non-membership of key
k, one of:empty: the size is 0 and the root is the empty committed root;before-first: an inclusion proof of leaf 0, withk <its key;after-last: an inclusion proof of leafsize-1, withk >its key;between: inclusion proofs of leavesiandi+1, withleft.key < k < right.key.
A neighbor carries its key, the hash of its value and its path, so the value itself need not be revealed. The verifier checks adjacency (indices
iandi+1) and the boundary indices against the committed size.
Flow
- Collect entries, then
buildTree(entries)(throws on a key that is not 32 bytes or appears twice). nextEpoch(prev, tree)makes the record;anchorPayload(record)gives the OP_RETURN data.proveInclusion/proveAbsencereturnnullwhen the request is impossible (an absent key has no inclusion proof; a present key has no absence proof).verifyInclusion(root, size, key, value, proof)/verifyAbsence(root, size, key, proof).
Security properties and the tests that check them
The tests are in test/ledger/. Trees are generated by fast-check with sizes 0 to 300, weighted toward 0, 1, 2, 3 and powers of two plus or minus one.
| Property | Test |
|---|---|
| The hash layout is exactly as documented (known answers built from raw SHA-256) | "matches the documented hash layout", "gives the empty tree a fixed committed root", "hashes the record in the documented layout" |
Odd nodes are promoted, so [a, b, c] and [a, b, c, c] have different roots |
"promotes an odd node instead of duplicating it" |
| Every leaf of every tree has a verifying inclusion proof | "every leaf of every tree has a proof that verifies" |
| Flipping any byte of any sibling, the root, the key or the value, or changing the index or the sibling count, makes verification fail | "flipping any byte of the proof, the root, the key or the value makes it fail" |
| An inclusion proof does not verify against any other size | "a proof does not verify against any other size" |
| Non-membership verifies for random absent keys and for keys at every boundary (just below the first, just above the last, between neighbors) | "verifies for absent keys at random and at every boundary" |
| Flipping any byte of an absence proof or the root makes it fail | "flipping any byte of an absence proof or the root makes it fail" |
No absence proof can be built for a present key, and every crafted one (each boundary form, non-adjacent neighbors, neighbors equal to the key, empty on a non-empty tree) is rejected |
"cannot be built for a present key, and every crafted one is rejected" |
| Every epoch record chains to the previous record's commitment, and changing any field breaks the commitment and the chain | "chains each record...", "commits to every field..." |
Interpretations
- Prefix bytes rather than tagged hashes for the tree, the RFC 6962 convention. Signed messages elsewhere in the protocol use BIP340 tagged hashes.
prevRootis the previous record's commitment, not the previous tree root. This makes the anchored values themselves a hash chain, matching the paper's "a later root also commits to the hash of the previous one".
Open questions for the paper's authors
- Sortedness is trusted. A non-membership proof is only as good as the guarantee that the committed tree really is sorted. An operator who commits an unsorted tree can prove a present chip absent. Archive nodes holding the full epoch data can check sortedness, and a sparse Merkle tree keyed by
chip_idwould remove the assumption. The paper should say which it relies on. - Two-level trees. The paper has operator roots combined into a global root. This module implements one level. The global combination (sorted by operator id, so an operator's absence is also provable) uses the same construction, but the paper does not fix its format.