Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Accepted blocks strictly increase the chain work

Proved
BitcoinBlock.work_increases

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

bip30bip34bitcoinbitcoin-mainnetblock-validationconnectblockconsensusformal-verificationundo

validate S b now = accept S' undo implies S.chainWork < S'.chainWork: GetBlockProof of a header with valid proof of work is at least one, so the most-work rule always prefers an extended chain.

Deprecated. Superseded by BitcoinBlockV2.work_increases (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
import Definitions.Def_BitcoinSer
Formal statement
theorem BitcoinBlock.work_increases (S : ChainState) (b : BitcoinSer.Block) (now : Int) (S' : ChainState) (undo : BlockUndo)
    (h : BitcoinBlock.validate S b now = .accept S' undo) : S.chainWork < S'.chainWork := 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.work_increases

Binders and hypotheses

  • SSS : a chain state ⟨headers,utxo⟩\langle\mathit{headers},\mathit{utxo}\rangle⟨headers,utxo⟩; bbb : a serialized block; now∈Z\mathit{now} \in \mathbb{Z}now∈Z.
  • S′S'S′ : a chain state; undo\mathit{undo}undo : a block undo list.
  • Hypothesis hhh : validate(S,b,now)=accept(S′,undo)\mathrm{validate}(S, b, \mathit{now}) = \mathrm{accept}(S', \mathit{undo})validate(S,b,now)=accept(S′,undo).

Conclusion

chainWork(S)<chainWork(S′),\mathrm{chainWork}(S) < \mathrm{chainWork}(S'),chainWork(S)<chainWork(S′),

a strict inequality of natural numbers, where chainWork(T)=∑h∈T.headersblockProof(h.bits)\mathrm{chainWork}(T) = \sum_{h \in T.\mathrm{headers}} \mathrm{blockProof}(h.\mathrm{bits})chainWork(T)=∑h∈T.headers​blockProof(h.bits) and

blockProof(bits)={0if deriveTarget(bits mod 232)=none,⌊2256−1−tt+1⌋+1if deriveTarget(bits mod 232)=some t,\mathrm{blockProof}(\mathit{bits}) = \begin{cases} 0 & \text{if } \mathrm{deriveTarget}(\mathit{bits} \bmod 2^{32}) = \mathrm{none},\\ \left\lfloor \dfrac{2^{256} - 1 - t}{t + 1}\right\rfloor + 1 & \text{if } \mathrm{deriveTarget}(\mathit{bits} \bmod 2^{32}) = \mathrm{some}\,t, \end{cases}blockProof(bits)=⎩⎨⎧​0⌊t+12256−1−t​⌋+1​if deriveTarget(bitsmod232)=none,if deriveTarget(bitsmod232)=somet,​

with deriveTarget\mathrm{deriveTarget}deriveTarget decoding the compact word (mantissa === low 232323 bits, exponent === top byte, left shift truncated modulo 22562^{256}2256) and returning none when the word is "negative" (mantissa ≠0\ne 0=0 and bit 0x008000000x008000000x00800000 set), the value is 000, the word "overflows", or the value exceeds 2224−12^{224}-12224−1.

Hypothesis, unfolded

hhh holds exactly when: checkHeaderPow(b.header)\mathrm{checkHeaderPow}(b.\mathrm{header})checkHeaderPow(b.header) is true (in particular deriveTarget(b.header.bits mod 232)\mathrm{deriveTarget}(b.\mathrm{header.bits} \bmod 2^{32})deriveTarget(b.header.bitsmod232) is some ttt with the header hash value ≤t\le t≤t); b.header.prevBlock=tipHash(S)b.\mathrm{header.prevBlock} = \mathrm{tipHash}(S)b.header.prevBlock=tipHash(S); the bits equal requiredBits(S)\mathrm{requiredBits}(S)requiredBits(S); mtp(S)<b.header.time≤now+7200\mathrm{mtp}(S) < b.\mathrm{header.time} \le \mathit{now} + 7200mtp(S)<b.header.time≤now+7200; the version is not outdated; checkBlock(b)\mathrm{checkBlock}(b)checkBlock(b) and contextualCheckBlock(S,b)\mathrm{contextualCheckBlock}(S,b)contextualCheckBlock(S,b) hold; connectBlock(S,b)=some(u,undo)\mathrm{connectBlock}(S,b) = \mathrm{some}(u, \mathit{undo})connectBlock(S,b)=some(u,undo); and S′=⟨S.headers+ ⁣ ⁣+[b.header], u⟩S' = \langle S.\mathrm{headers} \mathbin{+\!\!+} [b.\mathrm{header}],\ u\rangleS′=⟨S.headers++[b.header], u⟩.

So the statement says: under those conditions, the sum of per-header proofs over S′S'S′'s headers — which are SSS's headers followed by bbb's header — strictly exceeds the sum over SSS's headers; i.e. (since the sums differ exactly by blockProof(b.header.bits)\mathrm{blockProof}(b.\mathrm{header.bits})blockProof(b.header.bits)) that blockProof(b.header.bits)>0\mathrm{blockProof}(b.\mathrm{header.bits}) > 0blockProof(b.header.bits)>0.

Edge cases silently included

undo\mathit{undo}undo and now\mathit{now}now matter only inside hhh; blockProof\mathrm{blockProof}blockProof is 000 for headers with an invalid compact target (possible among SSS's existing headers, which are unconstrained); the formula ⌊(2256−1−t)/(t+1)⌋+1\lfloor(2^{256}-1-t)/(t+1)\rfloor + 1⌊(2256−1−t)/(t+1)⌋+1 uses natural subtraction and floor division (t≤2224−1t \le 2^{224}-1t≤2224−1 whenever defined); the hypothesis may be unsatisfiable for a given SSS, making the claim vacuous.

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