Design a Verifiable Audit Log (Merkle Tree)
Build a tamper-evident Certificate Transparency log with append-only Merkle trees, signed tree heads, log(N) proofs, and witness gossip.
In this lesson (4 bite-sized sections)
Why an append-only database is not tamper-evident
Certificate Authorities (Certificate Transparency, RFC 6962), software supply chains (Sigstore Rekor), and financial compliance ledgers share a harsh threat model: what if the log operator itself is compromised and silently edits or deletes a past record? Revoking SQL DELETE privileges does not stop a rogue DBA or stolen root key.
A linear hash chain (H_i = Hash(H_{i-1} || entry_i)) detects tampering, yet verifying a single entry forces an auditor to download and hash all O(N) preceding records. A verifiable transparency log replaces the chain with an append-only Merkle tree, shrinking both membership verification and append-only audits to O(log N) hashes.
Append-only Merkle trees and O(log N) proofs
Every accepted log entry is hashed as a leaf, and adjacent hashes combine pairwise upward to a single root hash. Crucially, production trees apply domain separation (RFC 6962 prefixes leaf hashes with 0x00 and internal parent hashes with 0x01) to prevent second-preimage attacks where an attacker submits two concatenated child hashes disguised as a leaf. Periodically, the log signs the root hash, tree size, and timestamp into a Signed Tree Head (STH).

Two logarithmic proofs power public auditing:
- Inclusion proof (audit path): to prove entry
kis in a tree of sizeN, the server sends only the ~log2(N)sibling hashes along the path to the root (at most 30 hashes for one billion entries). The verifier recomputes the root locally and checks it against the STH. - Consistency proof: to prove a newer STH (size
M) strictly extends an older STH (sizeN < M) with zero altered or dropped leaves, the server returnsO(log M)subtree hashes that reconstruct both the old root and the new root simultaneously.
Split-view attacks and witness cosigning
Merkle proofs catch retroactive edits against a single root, yet they cannot stop a split-view (equivocation) attack by themselves. A malicious operator can maintain two completely valid, append-only trees simultaneously: Tree A served to public monitors, and Tree B containing a fraudulent certificate served only to one victim. Both trees pass every inclusion and consistency check on their own.
Stop split-view attacks with gossip and witness cosigning. Independent external witnesses receive each new STH, verify a consistency proof against the last STH they observed, and attach their own cryptographic cosignature to form a checkpoint. Clients reject any STH lacking a threshold quorum of independent witness signatures (such as 3 of 5 organizations). Trying to serve two divergent trees either fails to gather quorum or leaves two signed conflicting checkpoints as undeniable cryptographic evidence of equivocation.
Classify each mechanism by whether it is a core Merkle cryptographic proof or an operational split-view and scale control.
Sort 5 more items to check
Batch sequencing throughput and static tiles
Computing and signing a new root synchronously on every single write limits throughput to a few hundred ops/sec. Systems like Google Trillian and Sunlight / C2SP tlog-tiles decouple ingestion from tree sequencing. Submissions land in a durable queue (optionally returning a signed promise with a Maximum Merge Delay, or waiting for a tight ~1-second batch). A single-leader sequencer (fenced via leader lease) pulls batches of thousands of entries, assigns contiguous leaf indices, hashes the updated frontier in memory, and emits one STH per batch.
Persisting completed tree levels as immutable fixed-size tiles (commonly 256 leaves per tile, 2^8) turns every inclusion and consistency query into cacheable static HTTP GET requests behind a CDN, allowing global monitors to audit billions of entries with minimal database load.
High-throughput verifiable transparency log: an architecture diagram of 7 components and 7 connections. Full description follows.
- Submitters: client.
- Ingest API: service.
- Durable Queue: queue or log.
- Leader Sequencer (Batch): service.
- Static Tiles (S3 + CDN): CDN.
- Witness Quorum (Cosign): external system.
- Auditors & Clients: client.
- Submitters calls synchronously Ingest API.
- Ingest API sends asynchronously to Durable Queue (enqueue leaf).
- Durable Queue sends asynchronously to Leader Sequencer (Batch) (batch pull).
- Leader Sequencer (Batch) calls synchronously Static Tiles (S3 + CDN) (write immutable tiles).
- Leader Sequencer (Batch) calls synchronously Witness Quorum (Cosign) (consistency proof + STH).
- Witness Quorum (Cosign) sends asynchronously to Auditors & Clients (cosigned checkpoint).
- Static Tiles (S3 + CDN) calls synchronously Auditors & Clients (CDN tile reads).
Sources: RFC 6962, Certificate Transparency · Google Trillian verifiable data structures · C2SP tlog-tiles static log spec · Sigstore Rekor architecture
import hashlib
def leaf_hash(data: bytes) -> bytes:
return hashlib.sha256(b"\x00" + data).digest()
def node_hash(left: bytes, right: bytes) -> bytes:
return hashlib.sha256(b"\x01" + left + right).digest()
def verify_inclusion(entry: bytes, proof: list[tuple[str, bytes]], root: bytes) -> bool:
cur = leaf_hash(entry)
for side, sibling in proof:
cur = node_hash(sibling, cur) if side == "L" else node_hash(cur, sibling)
return cur == root
entries = [b"cert:api.example.com", b"cert:auth.example.com", b"cert:pay.example.com", b"cert:cdn.example.com"]
leaves = [leaf_hash(e) for e in entries]
left_branch = node_hash(leaves[0], leaves[1])
right_branch = node_hash(leaves[2], leaves[3])
signed_root = node_hash(left_branch, right_branch)
# O(log N) inclusion proof for Entry 2: only 2 sibling hashes needed
proof_entry_2 = [("R", leaves[3]), ("L", left_branch)]
valid_ok = verify_inclusion(entries[2], proof_entry_2, signed_root)
# Mutate 1 byte of Entry 2 ("pay" -> "paz") and re-verify against the signed root
tampered = entries[2].replace(b"pay", b"paz")
tampered_ok = verify_inclusion(tampered, proof_entry_2, signed_root)
assert valid_ok and not tampered_ok
print(f"Signed Merkle root: {signed_root.hex()[:24]}...")
print(f"Entry 2 proof ({len(proof_entry_2)} sibling hashes) verified: {valid_ok}")
print(f"Entry 2 after 1-byte tamper verified: {tampered_ok}")Apply
Your turn
The task this lesson builds to.
Architect a tamper-evident audit and transparency log handling 5,000 events per second with O(log N) inclusion proofs, consistency verification, and split-view protection.
Think about
- How do domain-separated Merkle hashes, STHs, inclusion proofs, and consistency proofs guarantee append-only integrity?
- Why can a rogue operator still mount a split-view attack without external witnesses?
- How do decoupled batch sequencing and static tree tiles hit 5,000 events/sec and scale verification reads?
Draft your design answer here Save your draft, compare against the model answer, and track progress.
Practice
Make it stick
A second problem on the same idea, so it survives past today.
Specify how to support GDPR right-to-erasure requests in an enterprise compliance system whose audit log is backed by an immutable Merkle transparency tree without breaking historical consistency proofs.
Think about
- Why does deleting raw PII directly from a Merkle leaf invalidate every historical root and consistency proof?
- How do cryptographic shredding (per-subject key deletion) or salted commitments keep proofs intact after erasure?
- What metadata must stay out of the committed leaf payload so deletion is legally complete?
Draft your design answer here Save your draft, compare against the model answer, and track progress.