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 T be any type with decidable equality. A UTXO set over T is a finite ordered list of pairs (outpoint, coin): an outpoint is ⟨txid,n⟩ with txid∈T, n∈N; a coin c has an output c.out (integer c.out.value, Boolean c.out.unspendable), a height c.height∈N and a Boolean c.isCoinbase. u[p] is the coin of the first entry of u with outpoint p, or "none"; haveCoin(u,p) is "u[p] is not none". tv(u) is the integer sum of c.out.value over all entries of u. keysNodup(u) is the proposition that the outpoints of u are pairwise distinct. A transaction tx has fields txid∈T, vin (list of outpoints), vout (list of outputs o with integer o.value, Boolean o.unspendable), Boolean isCoinbase; valueOut(tx)=∑o∈tx.vouto.value. A block is a finite list of transactions. MAX_MONEY=2.1×1015, moneyRange(v)⟺0≤v≤MAX_MONEY.
The function connectBlock(subsidy,u,h,B), for subsidy:N→Z, returns an optional pair (UTXO set, integer) and is "some (u′,f)" exactly when all of the following hold:
- Structure (checkBlockTxs): B is non-empty, B=cb::rest, with cb.isCoinbase=true, checkTransaction(cb)=true, and for every tx∈rest, tx.isCoinbase=false and checkTransaction(tx)=true. Here checkTransaction(tx) means: vin non-empty, vout non-empty, every output value in [0,MAX_MONEY] with every partial sum (from 0, in list order) in [0,MAX_MONEY], and vin without duplicates.
- BIP30 pre-check (bip30Ok): for every tx∈B (the coinbase included) and every index o∈{0,…,∣tx.vout∣−1}, haveCoin(u,⟨tx.txid,o⟩)=false, tested against the initial u only.
- Transaction loop (connectLoop from (u,0)): processing B left to right with current set w (initially u) and accumulated fee f (initially 0): a transaction with isCoinbase=true is applied as w↦updateCoins(w,tx,h) with f unchanged and no check; a transaction with isCoinbase=false requires checkTxInputs(w,tx,h)=some fee and moneyRange(f+fee)=true, then w↦updateCoins(w,tx,h), f↦f+fee; the loop yields the final (u′,f). Here updateCoins(w,tx,h) first (for a non-coinbase transaction only) removes every entry at each outpoint of tx.vin, then for j=0,…,∣tx.vout∣−1 in order adds the coin (output oj, height h, flag tx.isCoinbase) at ⟨tx.txid,j⟩ by removing any entry at that outpoint and prepending the new one, unless oj.unspendable is true, in which case nothing is added. And checkTxInputs(w,tx,h)=some fee means: every p∈tx.vin has w[p]= some coin; for each such coin, not (c.isCoinbase and h−˙c.height<100, with truncated subtraction); each coin value and each running total of coin values (from 0, in order, with multiplicity) lies in [0,MAX_MONEY]; vin:= that total satisfies vin≥valueOut(tx); and fee=vin−valueOut(tx) lies in [0,MAX_MONEY].
- Coinbase bound: valueOut(cb)≤f+subsidy(h) (non-strict), where cb is the first transaction of B and f the final accumulated fee.
The theorem states: for every type T with decidable equality, every function subsidy:N→Z, every UTXO set u over T, every height h∈N, every block B of transactions over T, every UTXO set u′ and every integer fees, if
- keysNodup(u): the outpoints of u are pairwise distinct;
- the list of transaction ids of 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);
then both
tv(u′)≤tv(u)+subsidy(h)andkeysNodup(u′).
The bound involves subsidy(h) only, not fees; 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 u beyond what the success of connectBlock forces for the coins actually consumed.
Confirmed by the moderator at approval.