Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Reachable states are well formed

Proved
BitcoinBlock.reachable_wellFormed

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

bip30bip34bitcoinbitcoin-mainnetblock-validationconnectblockconsensusformal-verificationundo

Every state reachable from the genesis has the genesis header first, pairwise distinct ledger keys, and only spendable coins created at heights between 1 and the tip.

Deprecated. Superseded by BitcoinBlockV2.reachable_wellFormed (revision 2 of the block mission): the p2shSigOpCount of this revision counted every push of scriptSig instead of only the redeem script, over-counting P2SH sigops; the V2 declarations carry the corrected definition.

Preamble
import Definitions.Def_BitcoinBlock
Formal statement
theorem BitcoinBlock.reachable_wellFormed (S : ChainState) (h : BitcoinBlock.Reachable S) :
    BitcoinBlock.WellFormed S := by sorry
Source
Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48: AcceptBlockHeader, CheckBlockHeader, ContextualCheckBlockHeader, CheckBlock, CheckMerkleRoot, CheckWitnessMalleation, ContextualCheckBlock, ConnectBlock, GetBlockScriptFlags, IsBIP30Repeat, IsBIP30Unspendable, UpdateCoins, DisconnectBlock, ApplyTxInUndo, src/validation.cpp: https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/validation.cpp; CheckTransaction (consensus/tx_check.cpp); IsFinalTx, GetLegacySigOpCount, GetP2SHSigOpCount, GetTransactionSigOpCost, CheckTxInputs (consensus/tx_verify.cpp); CScript::GetSigOpCount, IsUnspendable (script/script.cpp, script.h); CountWitnessSigOps (script/interpreter.cpp); AddCoin, SpendCoin, AddCoins (coins.cpp); GetBlockProof (chain.cpp); GetWitnessCommitmentIndex, GetBlockWeight (consensus/validation.h); CMainParams (kernel/chainparams.cpp)
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: BitcoinBlock.reachable_wellFormed

Binders and hypotheses

  • SSS : a chain state ⟨headers,utxo⟩\langle\mathit{headers}, \mathit{utxo}\rangle⟨headers,utxo⟩.
  • Hypothesis hhh : Reachable(S)\mathrm{Reachable}(S)Reachable(S), the least predicate closed under: (genesis) Reachable(⟨[genesisHeader],[ ]⟩)\mathrm{Reachable}(\langle [\mathrm{genesisHeader}], [\,]\rangle)Reachable(⟨[genesisHeader],[]⟩); (step) for any S0S_0S0​, block bbb, clock t∈Zt \in \mathbb{Z}t∈Z, state S1S_1S1​ and undo list uuu, if Reachable(S0)\mathrm{Reachable}(S_0)Reachable(S0​) and validate(S0,b,t)=accept(S1,u)\mathrm{validate}(S_0, b, t) = \mathrm{accept}(S_1, u)validate(S0​,b,t)=accept(S1​,u) then Reachable(S1)\mathrm{Reachable}(S_1)Reachable(S1​).

Conclusion

WellFormed(S),\mathrm{WellFormed}(S),WellFormed(S),

i.e. the conjunction of:

  1. the head of S.headersS.\mathrm{headers}S.headers exists and equals genesisHeader\mathrm{genesisHeader}genesisHeader (version 111, prevBlock 32 zero bytes, merkleRoot the txid of the genesis coinbase, time 123100650512310065051231006505, bits 0x1d00ffff0x1d00ffff0x1d00ffff, nonce 208323689320832368932083236893);
  2. keysNodup(S.utxo)\mathrm{keysNodup}(S.\mathrm{utxo})keysNodup(S.utxo): the list of outpoint keys of the ledger has no duplicates;
  3. for every entry e=(op,c)e = (\mathit{op}, c)e=(op,c) of S.utxoS.\mathrm{utxo}S.utxo: 1≤c.height1 \le c.\mathrm{height}1≤c.height, c.height≤∣S.headers∣−1c.\mathrm{height} \le |S.\mathrm{headers}| - 1c.height≤∣S.headers∣−1 (natural subtraction), and c.out.scriptPubKeyc.\mathrm{out.scriptPubKey}c.out.scriptPubKey is not unspendable (it does not start with byte 0x6a0x6a0x6a and its length is at most 10 00010\,00010000).

The step rule, unfolded

validate(S0,b,t)=accept(S1,u)\mathrm{validate}(S_0,b,t) = \mathrm{accept}(S_1,u)validate(S0​,b,t)=accept(S1​,u) means: the header of bbb passes proof of work, builds on the tip hash of S0S_0S0​, has the required bits, a time above the tip's median-time-past and at most t+7200t+7200t+7200, and a non-outdated version; checkBlock(b)\mathrm{checkBlock}(b)checkBlock(b) and contextualCheckBlock(S0,b)\mathrm{contextualCheckBlock}(S_0,b)contextualCheckBlock(S0​,b) hold; and connectBlock(S0,b)=some(u1,u)\mathrm{connectBlock}(S_0,b) = \mathrm{some}(u_1,u)connectBlock(S0​,b)=some(u1​,u) with S1=⟨S0.headers+ ⁣ ⁣+[b.header],u1⟩S_1 = \langle S_0.\mathrm{headers} \mathbin{+\!\!+} [b.\mathrm{header}], u_1\rangleS1​=⟨S0​.headers++[b.header],u1​⟩. In connectBlock\mathrm{connectBlock}connectBlock, if the block's header hash is the genesis hash the ledger is returned unchanged; otherwise u1u_1u1​ results from the transaction loop at height ∣S0.headers∣|S_0.\mathrm{headers}|∣S0​.headers∣, which spends inputs and adds spendable outputs (unspendable scripts are never stored; an added entry replaces any entry with the same key) at that height, after BIP30 (when checked), input, fee, BIP68, sigop, script and coinbase-bound checks.

Edge cases silently included

The initial state has an empty ledger, so clauses 2 and 3 are vacuous there; the genesis-hashed shortcut adds a header without touching the ledger; clause 3 compares to ∣S.headers∣−1|S.\mathrm{headers}|-1∣S.headers∣−1 which is 000 for an empty list (unreachable under hhh but the predicate itself is defined for it); the undo lists and clocks in the derivation are existentially hidden in the hypothesis.

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

    Confirmed by the moderator at approval.

  • Endorsed by pitimespi · Oct 27, 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