Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

An accepted block raises the ledger by at most the subsidy

Proved
BitcoinUtxo.block_bound

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

bitcoinbitcoin-mainnetconsensusformal-verificationutxovalue-conservation

For every subsidy function sss, view UUU with distinct outpoints, height hhh, and block BBB whose transactions have pairwise distinct txids, if connectBlocks(U,h,B)=some(U′,fees)\mathrm{connectBlock}_s(U, h, B) = \mathrm{some}(U', \mathrm{fees})connectBlocks​(U,h,B)=some(U′,fees) then

totalValue(U′)≤totalValue(U)+s(h),\mathrm{totalValue}(U') \le \mathrm{totalValue}(U) + s(h),totalValue(U′)≤totalValue(U)+s(h),

and U′U'U′ has pairwise distinct outpoints. The fees paid by the block's transactions leave the ledger and are returned to it by the coinbase, which may add at most s(h)s(h)s(h) beyond them.

Preamble
import Definitions.Def_BitcoinUtxo
open BitcoinUtxo
Formal statement
theorem BitcoinUtxo.block_bound {T : Type} [DecidableEq T] (subsidy : Nat → Int) (u : UtxoSet T) (h : Nat) (block : List (Tx T))
    (u' : UtxoSet T) (fees : Int) (hn : keysNodup u) (hnd : (block.map Tx.txid).Nodup)
    (hc : connectBlock subsidy u h block = some (u', fees)) :
    totalValue u' ≤ totalValue u + subsidy h ∧ keysNodup u' := 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.block_bound.

Let TTT be any type with decidable equality. A UTXO set over TTT is a finite ordered list of pairs (outpoint, coin): 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; a coin ccc has an output c.outc.\mathrm{out}c.out (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 with outpoint ppp, or "none"; haveCoin(u,p)\mathrm{haveCoin}(u, p)haveCoin(u,p) is "u[p]u[p]u[p] is not 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) is the proposition that the outpoints of uuu are pairwise distinct. A transaction tx\mathrm{tx}tx has fields txid∈T\mathrm{txid} \in Ttxid∈T, vin\mathrm{vin}vin (list of outpoints), vout\mathrm{vout}vout (list of outputs ooo with integer o.valueo.\mathrm{value}o.value, Boolean o.unspendableo.\mathrm{unspendable}o.unspendable), Boolean isCoinbase\mathrm{isCoinbase}isCoinbase; valueOut(tx)=∑o∈tx.vouto.value\mathrm{valueOut}(\mathrm{tx}) = \sum_{o \in \mathrm{tx}.\mathrm{vout}} o.\mathrm{value}valueOut(tx)=∑o∈tx.vout​o.value. A block is a finite list of transactions. MAX_MONEY=2.1×1015\mathrm{MAX\_MONEY} = 2.1\times 10^{15}MAX_MONEY=2.1×1015, moneyRange(v)  ⟺  0≤v≤MAX_MONEY\mathrm{moneyRange}(v) \iff 0 \le v \le \mathrm{MAX\_MONEY}moneyRange(v)⟺0≤v≤MAX_MONEY.

The function connectBlock(subsidy,u,h,B)\mathrm{connectBlock}(\mathrm{subsidy}, u, h, B)connectBlock(subsidy,u,h,B), for subsidy:N→Z\mathrm{subsidy} : \mathbb{N} \to \mathbb{Z}subsidy:N→Z, returns an optional pair (UTXO set, integer) and is "some (u′,f)(u', f)(u′,f)" exactly when all of the following hold:

  1. Structure (checkBlockTxs\mathrm{checkBlockTxs}checkBlockTxs): BBB is non-empty, B=cb::restB = \mathrm{cb} :: \mathrm{rest}B=cb::rest, with cb.isCoinbase=true\mathrm{cb}.\mathrm{isCoinbase} = \mathrm{true}cb.isCoinbase=true, checkTransaction(cb)=true\mathrm{checkTransaction}(\mathrm{cb}) = \mathrm{true}checkTransaction(cb)=true, and for every tx∈rest\mathrm{tx} \in \mathrm{rest}tx∈rest, tx.isCoinbase=false\mathrm{tx}.\mathrm{isCoinbase} = \mathrm{false}tx.isCoinbase=false and checkTransaction(tx)=true\mathrm{checkTransaction}(\mathrm{tx}) = \mathrm{true}checkTransaction(tx)=true. Here checkTransaction(tx)\mathrm{checkTransaction}(\mathrm{tx})checkTransaction(tx) means: vin\mathrm{vin}vin non-empty, vout\mathrm{vout}vout non-empty, every output value in [0,MAX_MONEY][0, \mathrm{MAX\_MONEY}][0,MAX_MONEY] with every partial sum (from 000, in list order) in [0,MAX_MONEY][0, \mathrm{MAX\_MONEY}][0,MAX_MONEY], and vin\mathrm{vin}vin without duplicates.
  2. BIP30 pre-check (bip30Ok\mathrm{bip30Ok}bip30Ok): for every tx∈B\mathrm{tx} \in Btx∈B (the coinbase included) and every index o∈{0,…,∣tx.vout∣−1}o \in \{0, \dots, |\mathrm{tx}.\mathrm{vout}|-1\}o∈{0,…,∣tx.vout∣−1}, haveCoin(u,⟨tx.txid,o⟩)=false\mathrm{haveCoin}(u, \langle \mathrm{tx}.\mathrm{txid}, o\rangle) = \mathrm{false}haveCoin(u,⟨tx.txid,o⟩)=false, tested against the initial uuu only.
  3. Transaction loop (connectLoop\mathrm{connectLoop}connectLoop from (u,0)(u, 0)(u,0)): processing BBB left to right with current set www (initially uuu) and accumulated fee fff (initially 000): a transaction with isCoinbase=true\mathrm{isCoinbase} = \mathrm{true}isCoinbase=true is applied as w↦updateCoins(w,tx,h)w \mapsto \mathrm{updateCoins}(w, \mathrm{tx}, h)w↦updateCoins(w,tx,h) with fff unchanged and no check; a transaction with isCoinbase=false\mathrm{isCoinbase} = \mathrm{false}isCoinbase=false requires checkTxInputs(w,tx,h)=some fee\mathrm{checkTxInputs}(w, \mathrm{tx}, h) = \text{some } \mathrm{fee}checkTxInputs(w,tx,h)=some fee and moneyRange(f+fee)=true\mathrm{moneyRange}(f + \mathrm{fee}) = \mathrm{true}moneyRange(f+fee)=true, then w↦updateCoins(w,tx,h)w \mapsto \mathrm{updateCoins}(w, \mathrm{tx}, h)w↦updateCoins(w,tx,h), f↦f+feef \mapsto f + \mathrm{fee}f↦f+fee; the loop yields the final (u′,f)(u', f)(u′,f). Here updateCoins(w,tx,h)\mathrm{updateCoins}(w, \mathrm{tx}, h)updateCoins(w,tx,h) first (for a non-coinbase transaction only) removes every entry at each outpoint of tx.vin\mathrm{tx}.\mathrm{vin}tx.vin, then for j=0,…,∣tx.vout∣−1j = 0, \dots, |\mathrm{tx}.\mathrm{vout}|-1j=0,…,∣tx.vout∣−1 in order adds the coin (output ojo_joj​, height hhh, flag tx.isCoinbase\mathrm{tx}.\mathrm{isCoinbase}tx.isCoinbase) at ⟨tx.txid,j⟩\langle \mathrm{tx}.\mathrm{txid}, j\rangle⟨tx.txid,j⟩ by removing any entry at that outpoint and prepending the new one, unless oj.unspendableo_j.\mathrm{unspendable}oj​.unspendable is true, in which case nothing is added. And checkTxInputs(w,tx,h)=some fee\mathrm{checkTxInputs}(w, \mathrm{tx}, h) = \text{some } \mathrm{fee}checkTxInputs(w,tx,h)=some fee means: every p∈tx.vinp \in \mathrm{tx}.\mathrm{vin}p∈tx.vin has w[p]=w[p] = w[p]= some coin; for each such coin, not (c.isCoinbasec.\mathrm{isCoinbase}c.isCoinbase and h−˙c.height<100h \mathbin{\dot-} c.\mathrm{height} < 100h−˙​c.height<100, with truncated subtraction); each coin value and each running total of coin values (from 000, in order, with multiplicity) lies in [0,MAX_MONEY][0, \mathrm{MAX\_MONEY}][0,MAX_MONEY]; vin:=v_{\mathrm{in}} := vin​:= that total satisfies vin≥valueOut(tx)v_{\mathrm{in}} \ge \mathrm{valueOut}(\mathrm{tx})vin​≥valueOut(tx); and fee=vin−valueOut(tx)\mathrm{fee} = v_{\mathrm{in}} - \mathrm{valueOut}(\mathrm{tx})fee=vin​−valueOut(tx) lies in [0,MAX_MONEY][0, \mathrm{MAX\_MONEY}][0,MAX_MONEY].
  4. Coinbase bound: valueOut(cb)≤f+subsidy(h)\mathrm{valueOut}(\mathrm{cb}) \le f + \mathrm{subsidy}(h)valueOut(cb)≤f+subsidy(h) (non-strict), where cb\mathrm{cb}cb is the first transaction of BBB and fff the final accumulated fee.

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 UTXO set uuu over TTT, every height h∈Nh \in \mathbb{N}h∈N, every block BBB of transactions over TTT, every UTXO set u′u'u′ and every integer fees\mathrm{fees}fees, if

  • keysNodup(u)\mathrm{keysNodup}(u)keysNodup(u): the outpoints of uuu are pairwise distinct;
  • the list of transaction ids of BBB, [tx.txid:tx∈B][\mathrm{tx}.\mathrm{txid} : \mathrm{tx} \in B][tx.txid:tx∈B], has no duplicates (all transactions in the block have pairwise distinct ids);
  • connectBlock(subsidy,u,h,B)=some (u′,fees)\mathrm{connectBlock}(\mathrm{subsidy}, u, h, B) = \text{some } (u', \mathrm{fees})connectBlock(subsidy,u,h,B)=some (u′,fees);

then both

tv(u′)≤tv(u)+subsidy(h)andkeysNodup(u′).\mathrm{tv}(u') \le \mathrm{tv}(u) + \mathrm{subsidy}(h) \qquad\text{and}\qquad \mathrm{keysNodup}(u').tv(u′)≤tv(u)+subsidy(h)andkeysNodup(u′).

The bound involves subsidy(h)\mathrm{subsidy}(h)subsidy(h) only, not fees\mathrm{fees}fees; subsidy(h)\mathrm{subsidy}(h)subsidy(h) may be any integer. The conclusion's inequality is non-strict. No condition is placed on the heights or values of the coins already in uuu beyond what the success of connectBlock\mathrm{connectBlock}connectBlock forces for the coins actually consumed.

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