Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

From an empty ledger, total value never exceeds the subsidies issued

Proved
BitcoinUtxo.ledger_bound

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

bitcoinbitcoin-mainnetconsensusformal-verificationutxovalue-conservation

For every subsidy function s:N→Zs : \mathbb N \to \mathbb Zs:N→Z, starting height hhh, and sequence of blocks B1,…,BnB_1, \dots, B_nB1​,…,Bn​ whose transactions have pairwise distinct txids within each block, if connecting them from the empty UTXO set succeeds,

connectChains([ ],h,[B1,…,Bn])=some(U)  ⟹  totalValue(U)≤∑i<ns(h+i).\mathrm{connectChain}_s([\,], h, [B_1, \dots, B_n]) = \mathrm{some}(U) \;\Longrightarrow\; \mathrm{totalValue}(U) \le \sum_{i<n} s(h + i).connectChains​([],h,[B1​,…,Bn​])=some(U)⟹totalValue(U)≤i<n∑​s(h+i).

Here connectChain applies the transcribed ConnectBlock accounting — CheckTransaction, the BIP30 check, CheckTxInputs, fee accumulation, UpdateCoins, and the coinbase bound — at consecutive heights.

This is the supply bound of the ledger: fees move value between outputs, unspendable outputs destroy it, and the only creation is the coinbase, bounded by fees plus subsidy. With sss the mainnet GetBlockSubsidy and h=1h = 1h=1 (the genesis coinbase is never connected), the right-hand side is below MAX_MONEY\mathrm{MAX\_MONEY}MAX_MONEY by the subsidy mission's bound.

Formalization Note. The subsidy is a parameter, so the statement does not depend on the schedule. Distinct txids within a block stand for collision-freedom of transaction hashes, which an abstract id type cannot supply; the BIP30 check is modeled as enforced.

Preamble
import Definitions.Def_BitcoinUtxo
open BitcoinUtxo
Formal statement
theorem BitcoinUtxo.ledger_bound {T : Type} [DecidableEq T] (subsidy : Nat → Int) (blocks : List (List (Tx T))) (h : Nat)
    (u' : UtxoSet T) (hnd : ∀ b ∈ blocks, (b.map Tx.txid).Nodup)
    (hc : connectChain subsidy [] h blocks = some 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.ledger_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. w[p]w[p]w[p] denotes the coin of the first entry of www at outpoint ppp, or "none". tv(w)\mathrm{tv}(w)tv(w) is the integer sum of c.out.valuec.\mathrm{out}.\mathrm{value}c.out.value over all entries of www, with tv([ ])=0\mathrm{tv}([\,]) = 0tv([])=0. A transaction has fields txid∈T\mathrm{txid} \in Ttxid∈T, vin\mathrm{vin}vin (a list of outpoints), vout\mathrm{vout}vout (a list of outputs with integer values and unspendable flags) and a Boolean isCoinbase\mathrm{isCoinbase}isCoinbase; a block is a list of transactions; valueOut(tx)\mathrm{valueOut}(\mathrm{tx})valueOut(tx) is the sum of the output values of tx\mathrm{tx}tx. 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, cb.isCoinbase\mathrm{cb}.\mathrm{isCoinbase}cb.isCoinbase is true, every transaction in rest\mathrm{rest}rest has isCoinbase\mathrm{isCoinbase}isCoinbase false, and every transaction of BBB has 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 (from 000, in order) in [0,MAX_MONEY][0, \mathrm{MAX\_MONEY}][0,MAX_MONEY]; (ii) for every tx∈B\mathrm{tx} \in Btx∈B and every o∈{0,…,∣tx.vout∣−1}o \in \{0, \dots, |\mathrm{tx}.\mathrm{vout}|-1\}o∈{0,…,∣tx.vout∣−1}, 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, where a coinbase-flagged transaction is applied without any check or fee change 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⟩ — removing any entry at that outpoint and prepending the new one, or doing nothing if ojo_joj​ is unspendable — and a non-coinbase transaction requires that every input outpoint have an entry in the current set, that no input coin be a coinbase coin with k−˙height<100k \mathbin{\dot-} \mathrm{height} < 100k−˙​height<100 (truncated natural subtraction, so any coinbase coin of height ≥k\ge k≥k is rejected), 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 vinv_{\mathrm{in}}vin​ satisfy 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 new accumulated fee f+fee∈[0,MAX_MONEY]f + \mathrm{fee} \in [0, \mathrm{MAX\_MONEY}]f+fee∈[0,MAX_MONEY], after which every entry at each input outpoint is removed and the outputs are added 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 accumulated fee fff. Then connectChain(subsidy,w0,h,[B0,…,Bn−1])\mathrm{connectChain}(\mathrm{subsidy}, w_0, h, [B_0, \dots, B_{n-1}])connectChain(subsidy,w0​,h,[B0​,…,Bn−1​]) is "some u′u'u′" exactly when there are sets w0,w1,…,wn=u′w_0, w_1, \dots, w_n = 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 each i<ni < ni<n (fees discarded); for n=0n = 0n=0 it is "some w0w_0w0​". And 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=0n−1​subsidy(h+k), equal to 000 for n=0n = 0n=0.

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

  • for every block BBB occurring in blocks\mathrm{blocks}blocks, the list of transaction ids of BBB has no duplicates (distinctness within each block only; ids may repeat across different blocks);
  • connectChain(subsidy,[ ],h,blocks)=some u′\mathrm{connectChain}(\mathrm{subsidy}, [\,], h, \mathrm{blocks}) = \text{some } u'connectChain(subsidy,[],h,blocks)=some u′, i.e. connecting the blocks in order at heights h,h+1,…,h+n−1h, h+1, \dots, h+n-1h,h+1,…,h+n−1 starting from the empty UTXO set succeeds and yields u′u'u′;

then

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

a non-strict integer inequality.

There is no explicit keysNodup hypothesis (the starting set is the empty list, which has no outpoints). For blocks=[ ]\mathrm{blocks} = [\,]blocks=[] the second hypothesis forces u′=[ ]u' = [\,]u′=[] and the conclusion reads 0≤00 \le 00≤0. The function subsidy\mathrm{subsidy}subsidy is arbitrary and may take negative values; the conclusion does not assert that the outpoints of u′u'u′ are distinct, nor anything about fees.

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