Merkle trees are collision resistant
ProvedCityMD.tree_extractOne oracle program, making at most node calls, turns two distinct leaf vectors of a depth- Merkle tree with the same root into a collision of the node function.
Preamble
import Mathlib import Definitions.Def_CityMD open Cryptography.MerkleDamgard CityMD
Formal statement
/-- Merkle trees are collision resistant: one oracle program, making at most
`2 (2 ^ d - 1)` node calls, turns two different leaf vectors with the same root
into a collision of the node function. -/
theorem CityMD.tree_extract {S : Type} [DecidableEq S] :
∃ E : (d : ℕ) → (Fin (2 ^ d) → S) → (Fin (2 ^ d) → S) →
OComp (S × S) S (Option ((S × S) × (S × S))),
∀ (g : S → S → S) (d : ℕ) (x y : Fin (2 ^ d) → S),
(E d x y).queries (uncurried g) ≤ 2 * (2 ^ d - 1) ∧
(x ≠ y → tree g d x = tree g d y →
∃ p q, (E d x y).run (uncurried g) = some (p, q) ∧ p ≠ q ∧
uncurried g p = uncurried g q) := by sorryRead-back
What the Lean code literally says, in plain math · claude-opus-5-5
CityMD.tree_extract (file Thm_CityMD_tree.lean)
Read-back
Let S have decidable equality. There is a family of oracle programs E(d, x, y), for x, y : Fin 2^d → S, with oracle (S×S) → S, returning an Option of a pair of (S×S) points. E is fixed before g. For every node function g : S → S → S, every depth d, and all leaf vectors x and y, both of the following hold:
- E makes at most 2(2^d − 1) calls to (a,b) ↦ g a b.
- If x ≠ y and tree_g(d, x) = tree_g(d, y), then E returns
some (p,q)with p ≠ q and g(p) = g(q).
Audit notes
- True. Each tree has 2^d − 1 internal nodes, so computing all of them for both trees takes 2(2^d−1) queries. Descend from the root: at each level, either the two child pairs differ, which gives a collision, or they are equal, in which case you recurse into a child subtree whose leaves differ. Such a child must exist because x ≠ y.
- d = 0: Fin 1 forces x = y, so the claim is vacuous, and E needs 0 queries. That is consistent.
- The index split in
treeis left = indices [0, 2^d) and right = indices [2^d, 2^{d+1}), which is correct. - The docstring matches the code. Only the theorem name (
tree_extract) differs from the file name (Thm_CityMD_tree), which is cosmetic. Likeextract, this is an extraction lemma rather than a probability statement. That is fine.