Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Merkle root of two hashes

Proved
BitcoinMerkle.root_pair

by pitimespi · Oct 26, 2026 · Mathlib 0df444a (Lean v4.33.1)

bitcoinbitcoin-mainnetconsensuscve-2012-2459formal-verificationmerkle-tree

For every ccc, zzz and hashes a,ba, ba,b, computeMerkleRootc,z([a,b])=(c(a,b), [a=b])\mathrm{computeMerkleRoot}_{c,z}([a, b]) = (c(a, b),\ [a = b])computeMerkleRootc,z​([a,b])=(c(a,b), [a=b]): one level is processed, producing c(a,b)c(a,b)c(a,b), and the flag is set exactly when the two leaves are equal. This is the smallest instance of the mutation check.

Preamble
import Definitions.Def_BitcoinMerkle
Formal statement
theorem BitcoinMerkle.root_pair {H : Type} [DecidableEq H] (c : H → H → H) (z : H) (a b : H) :
    BitcoinMerkle.computeMerkleRoot c z [a, b] = (c a b, decide (a = b)) := by sorry
Source
Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48, ComputeMerkleRoot, src/consensus/merkle.cpp lines 51-73, with the CVE-2012-2459 comment at lines 16-50: https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/consensus/merkle.cpp#L51
Read-back

What the Lean code literally says, in plain math · claude-fable-5-1 (independent sub-agent, blind: Lean code + auditor instructions only)

Read-back: BitcoinMerkle.root_pair

Binders and assumptions. HHH is an arbitrary type with decidable equality (for x,y∈Hx,y \in Hx,y∈H the Boolean [x=y][x = y][x=y] is true\mathrm{true}true exactly when x=yx = yx=y and false\mathrm{false}false otherwise). c:H→H→Hc : H \to H \to Hc:H→H→H is an arbitrary two-argument operation and z∈Hz \in Hz∈H an arbitrary element; nothing is assumed about either. a,b∈Ha, b \in Ha,b∈H are two arbitrary elements — they may be equal or distinct. There are no further hypotheses.

Conclusion.

Mc,z([a,b])  =  (c(a,b), [a=b]),M_{c,z}([a, b]) \;=\; \bigl(c(a, b),\ [a = b]\bigr),Mc,z​([a,b])=(c(a,b), [a=b]),

an equality of ordered pairs in H×{true,false}H \times \{\mathrm{true},\mathrm{false}\}H×{true,false}: the first component of the result on the two-element list [a,b][a,b][a,b] is exactly c(a,b)c(a,b)c(a,b) (with aaa as first argument and bbb as second), and the second component is the Boolean that is true\mathrm{true}true if a=ba = ba=b and false\mathrm{false}false if a≠ba \neq ba=b.

Unfolding Mc,zM_{c,z}Mc,z​ (computeMerkleRoot). Mc,z(hs)=Rc,z(hs,false)M_{c,z}(hs) = R_{c,z}(hs, \mathrm{false})Mc,z​(hs)=Rc,z​(hs,false), where Rc,zR_{c,z}Rc,z​ (rootLoop) on a list hshshs and Boolean mmm is

Rc,z(hs,m)={Rc,z(Pc(hs), m∨E(hs))if 1<∣hs∣,(headz(hs), m)if ∣hs∣≤1,R_{c,z}(hs, m) = \begin{cases} R_{c,z}\bigl(P_c(hs),\ m \lor E(hs)\bigr) & \text{if } 1 < |hs|,\\ \bigl(\mathrm{head}_z(hs),\ m\bigr) & \text{if } |hs| \le 1, \end{cases}Rc,z​(hs,m)={Rc,z​(Pc​(hs), m∨E(hs))(headz​(hs), m)​if 1<∣hs∣,if ∣hs∣≤1,​

with headz(hs)\mathrm{head}_z(hs)headz​(hs) the first entry of hshshs or zzz if hs=[ ]hs = [\,]hs=[], ∨\lor∨ Boolean "or", PcP_cPc​ (pairUp) given by Pc(a′::b′::r)=c(a′,b′)::Pc(r)P_c(a' :: b' :: r) = c(a',b') :: P_c(r)Pc​(a′::b′::r)=c(a′,b′)::Pc​(r), Pc([a′])=[c(a′,a′)]P_c([a']) = [c(a',a')]Pc​([a′])=[c(a′,a′)], Pc([ ])=[ ]P_c([\,]) = [\,]Pc​([])=[], and EEE (hasEqualPair) the Boolean E(a′::b′::r)=[a′=b′]∨E(r)E(a' :: b' :: r) = [a' = b'] \lor E(r)E(a′::b′::r)=[a′=b′]∨E(r), E([ ])=E([a′])=falseE([\,]) = E([a']) = \mathrm{false}E([])=E([a′])=false. On [a,b][a,b][a,b]: the loop test 1<21 < 21<2 holds, so the loop performs one pass producing the list Pc([a,b])=[c(a,b)]P_c([a,b]) = [c(a,b)]Pc​([a,b])=[c(a,b)] and the flag false∨E([a,b])=false∨[a=b]\mathrm{false} \lor E([a,b]) = \mathrm{false} \lor [a = b]false∨E([a,b])=false∨[a=b]; then 1<11 < 11<1 fails and the result is (c(a,b), false∨[a=b])(c(a,b),\ \mathrm{false} \lor [a=b])(c(a,b), false∨[a=b]). The theorem asserts this pair equals (c(a,b),[a=b])(c(a,b), [a = b])(c(a,b),[a=b]).

What is and is not claimed. The statement concerns only two-element inputs. The flag component is a Boolean (the decision of a=ba = ba=b), not a proposition; the theorem says the flag is true\mathrm{true}true precisely in the case a=ba = ba=b and false\mathrm{false}false precisely in the case a≠ba \neq ba=b. The element zzz does not appear in the right-hand side (it is unused for a nonempty input). The claim holds for every ccc and zzz, with no restriction on whether c(a,b)c(a,b)c(a,b) equals c(b,a)c(b,a)c(b,a), aaa, bbb, or anything else.

Human review
  • Endorsed by Shuze Chen · Oct 26, 2026

    Confirmed by the moderator at approval.

  • Endorsed by pitimespi · Oct 26, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me