Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

A chain of accepted blocks raises the ledger by at most the summed subsidies

Proved
BitcoinUtxo.chain_bound

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

bitcoinbitcoin-mainnetconsensusformal-verificationutxovalue-conservation

For every subsidy function sss, list of blocks B1,…,BnB_1, \dots, B_nB1​,…,Bn​ each with pairwise distinct txids, view UUU with distinct outpoints and height hhh, if connectChains(U,h,[B1,…,Bn])=some(U′)\mathrm{connectChain}_s(U, h, [B_1, \dots, B_n]) = \mathrm{some}(U')connectChains​(U,h,[B1​,…,Bn​])=some(U′) then

totalValue(U′)≤totalValue(U)+∑i<ns(h+i).\mathrm{totalValue}(U') \le \mathrm{totalValue}(U) + \sum_{i<n} s(h + i).totalValue(U′)≤totalValue(U)+i<n∑​s(h+i).
Preamble
import Definitions.Def_BitcoinUtxo
open BitcoinUtxo
Formal statement
theorem BitcoinUtxo.chain_bound {T : Type} [DecidableEq T] (subsidy : Nat → Int) :
    ∀ (blocks : List (List (Tx T))) (u : UtxoSet T) (h : Nat) (u' : UtxoSet T),
      keysNodup u → (∀ b ∈ blocks, (b.map Tx.txid).Nodup) →
      connectChain subsidy u h blocks = some u' →
      totalValue u' ≤ totalValue u + subsidySum subsidy h blocks.length := by sorry
Source
Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48: CheckTransaction, src/consensus/tx_check.cpp lines 11-68: https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/consensus/tx_check.cpp; Consensus::CheckTxInputs, src/consensus/tx_verify.cpp (lines 157-220): https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/consensus/tx_verify.cpp; CCoinsViewCache::AddCoin, AddCoins, SpendCoin, HaveInputs, src/coins.cpp: https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/coins.cpp; UpdateCoins, BIP30 check (lines 2396-2475), fee accumulation and coinbase bound in Chainstate::ConnectBlock (lines 2518-2612), src/validation.cpp: https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/validation.cpp; COIN, MAX_MONEY, MoneyRange, src/consensus/amount.h; COINBASE_MATURITY, src/consensus/consensus.h
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 of BitcoinUtxo.chain_bound.

Let TTT be any type with decidable equality. A UTXO set over TTT is a finite ordered list of pairs (outpoint, coin), where an outpoint is ⟨txid,n⟩\langle \mathrm{txid}, n\rangle⟨txid,n⟩ with txid∈T\mathrm{txid} \in Ttxid∈T, n∈Nn \in \mathbb{N}n∈N, and a coin ccc carries an output (integer c.out.valuec.\mathrm{out}.\mathrm{value}c.out.value, Boolean c.out.unspendablec.\mathrm{out}.\mathrm{unspendable}c.out.unspendable), a height c.height∈Nc.\mathrm{height} \in \mathbb{N}c.height∈N and a Boolean c.isCoinbasec.\mathrm{isCoinbase}c.isCoinbase. u[p]u[p]u[p] is the coin of the first entry of uuu at outpoint ppp, or "none". tv(u)\mathrm{tv}(u)tv(u) is the integer sum of c.out.valuec.\mathrm{out}.\mathrm{value}c.out.value over all entries of uuu. keysNodup(u)\mathrm{keysNodup}(u)keysNodup(u) says the outpoints of uuu are pairwise distinct. A transaction has fields txid∈T\mathrm{txid} \in Ttxid∈T, vin\mathrm{vin}vin (outpoints), vout\mathrm{vout}vout (outputs with integer values and unspendable flags) and Boolean isCoinbase\mathrm{isCoinbase}isCoinbase; a block is a list of transactions; valueOut(tx)\mathrm{valueOut}(\mathrm{tx})valueOut(tx) is the sum of its output values. MAX_MONEY=2.1×1015\mathrm{MAX\_MONEY} = 2.1 \times 10^{15}MAX_MONEY=2.1×1015 and moneyRange(v)  ⟺  0≤v≤MAX_MONEY\mathrm{moneyRange}(v) \iff 0 \le v \le \mathrm{MAX\_MONEY}moneyRange(v)⟺0≤v≤MAX_MONEY.

For subsidy:N→Z\mathrm{subsidy} : \mathbb{N} \to \mathbb{Z}subsidy:N→Z, connectBlock(subsidy,w,k,B)\mathrm{connectBlock}(\mathrm{subsidy}, w, k, B)connectBlock(subsidy,w,k,B) is "some (w′,f)(w', f)(w′,f)" exactly when: (i) B=cb::restB = \mathrm{cb} :: \mathrm{rest}B=cb::rest is non-empty with cb.isCoinbase\mathrm{cb}.\mathrm{isCoinbase}cb.isCoinbase true, every other transaction's isCoinbase\mathrm{isCoinbase}isCoinbase false, and every transaction of BBB having non-empty vin\mathrm{vin}vin and vout\mathrm{vout}vout, duplicate-free vin\mathrm{vin}vin, all output values in [0,MAX_MONEY][0, \mathrm{MAX\_MONEY}][0,MAX_MONEY] and all partial sums of output values in [0,MAX_MONEY][0, \mathrm{MAX\_MONEY}][0,MAX_MONEY]; (ii) for every tx∈B\mathrm{tx} \in Btx∈B and every o<∣tx.vout∣o < |\mathrm{tx}.\mathrm{vout}|o<∣tx.vout∣, www has no entry at ⟨tx.txid,o⟩\langle \mathrm{tx}.\mathrm{txid}, o\rangle⟨tx.txid,o⟩; (iii) processing BBB left to right from (w,0)(w, 0)(w,0) succeeds: a coinbase-flagged transaction is applied by adding, for j=0,…,∣vout∣−1j = 0, \dots, |\mathrm{vout}|-1j=0,…,∣vout∣−1, the coin (output ojo_joj​, height kkk, flag true) at ⟨txid,j⟩\langle \mathrm{txid}, j\rangle⟨txid,j⟩ (replacing any entry there; skipped if ojo_joj​ is unspendable) with no checks and no fee change; a non-coinbase transaction requires that every input outpoint be present in the current set, that no input coin be a coinbase coin with k−˙height<100k \mathbin{\dot-} \mathrm{height} < 100k−˙​height<100 (truncated subtraction), that each input value and each running total of input values be in [0,MAX_MONEY][0, \mathrm{MAX\_MONEY}][0,MAX_MONEY], that the input total vin≥valueOut(tx)v_{\mathrm{in}} \ge \mathrm{valueOut}(\mathrm{tx})vin​≥valueOut(tx), that fee=vin−valueOut(tx)∈[0,MAX_MONEY]\mathrm{fee} = v_{\mathrm{in}} - \mathrm{valueOut}(\mathrm{tx}) \in [0, \mathrm{MAX\_MONEY}]fee=vin​−valueOut(tx)∈[0,MAX_MONEY] and that the accumulated fee f+fee∈[0,MAX_MONEY]f + \mathrm{fee} \in [0, \mathrm{MAX\_MONEY}]f+fee∈[0,MAX_MONEY]; it then removes every entry at each input outpoint and adds its outputs at height kkk with flag false as above; (iv) valueOut(cb)≤f+subsidy(k)\mathrm{valueOut}(\mathrm{cb}) \le f + \mathrm{subsidy}(k)valueOut(cb)≤f+subsidy(k) for the final fff. The result (w′,f)(w', f)(w′,f) is the final set and fee.

Then connectChain(subsidy,u,h,[B0,B1,…,Bn−1])\mathrm{connectChain}(\mathrm{subsidy}, u, h, [B_0, B_1, \dots, B_{n-1}])connectChain(subsidy,u,h,[B0​,B1​,…,Bn−1​]) is "some u′u'u′" exactly when there are sets u=w0,w1,…,wn=u′u = w_0, w_1, \dots, w_n = u'u=w0​,w1​,…,wn​=u′ with connectBlock(subsidy,wi,h+i,Bi)=some (wi+1,fi)\mathrm{connectBlock}(\mathrm{subsidy}, w_i, h + i, B_i) = \text{some } (w_{i+1}, f_i)connectBlock(subsidy,wi​,h+i,Bi​)=some (wi+1​,fi​) for every i<ni < ni<n (the fees fif_ifi​ are discarded); for n=0n = 0n=0 it is "some uuu". Finally

subsidySum(subsidy,h,n)=∑k=0n−1subsidy(h+k),\mathrm{subsidySum}(\mathrm{subsidy}, h, n) = \sum_{k=0}^{n-1} \mathrm{subsidy}(h + k),subsidySum(subsidy,h,n)=k=0∑n−1​subsidy(h+k),

which is 000 when n=0n = 0n=0.

The theorem states: for every type TTT with decidable equality and every function subsidy:N→Z\mathrm{subsidy} : \mathbb{N} \to \mathbb{Z}subsidy:N→Z, for every list of blocks blocks=[B0,…,Bn−1]\mathrm{blocks} = [B_0, \dots, B_{n-1}]blocks=[B0​,…,Bn−1​] over TTT, every UTXO set uuu over TTT, every height h∈Nh \in \mathbb{N}h∈N and every UTXO set u′u'u′, if

  • keysNodup(u)\mathrm{keysNodup}(u)keysNodup(u): the outpoints of uuu are pairwise distinct;
  • for every block BBB occurring in blocks\mathrm{blocks}blocks, the list of transaction ids of BBB has no duplicates (distinctness is required within each block only; the same transaction id may occur in different blocks);
  • connectChain(subsidy,u,h,blocks)=some u′\mathrm{connectChain}(\mathrm{subsidy}, u, h, \mathrm{blocks}) = \text{some } u'connectChain(subsidy,u,h,blocks)=some u′;

then

tv(u′)≤tv(u)+∑k=0n−1subsidy(h+k),n=∣blocks∣,\mathrm{tv}(u') \le \mathrm{tv}(u) + \sum_{k=0}^{n-1} \mathrm{subsidy}(h + k), \qquad n = |\mathrm{blocks}|,tv(u′)≤tv(u)+k=0∑n−1​subsidy(h+k),n=∣blocks∣,

a non-strict integer inequality.

The quantifiers over blocks\mathrm{blocks}blocks, uuu, hhh, u′u'u′ are all universal and come after subsidy\mathrm{subsidy}subsidy is fixed. For blocks=[ ]\mathrm{blocks} = [\,]blocks=[] the third hypothesis forces u′=uu' = uu′=u and the conclusion reads tv(u)≤tv(u)+0\mathrm{tv}(u) \le \mathrm{tv}(u) + 0tv(u)≤tv(u)+0. The function subsidy\mathrm{subsidy}subsidy is arbitrary (it may take negative values), and the conclusion does not assert keysNodup(u′)\mathrm{keysNodup}(u')keysNodup(u′).

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