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.tx_conservation.
Let T be any type with decidable equality. A UTXO set u over T is a finite ordered list of pairs (outpoint, coin): an outpoint is ⟨txid,n⟩ with txid∈T and 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". tv(u) is the integer sum of c.out.value over all entries of u. keysNodup(u) says 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 and Boolean o.unspendable) and Boolean isCoinbase. MAX_MONEY=2.1×1015; moneyRange(v)⟺0≤v≤MAX_MONEY.
Spending and adding. spendCoin(u,p) deletes every entry of outpoint p; spendInputs(u,[p1,…,pm]) applies this successively for p1,…,pm. addCoin(u,p,c) is u unchanged if c.out.unspendable is true, and otherwise (p,c) prepended to spendCoin(u,p). Then
updateCoins(u,tx,h)=the result of adding, for j=0,1,…,∣tx.vout∣−1 in order, the coin ⟨oj,h,tx.isCoinbase⟩ at outpoint ⟨tx.txid,j⟩ to u0,
where oj is the j-th output of tx.vout, and u0=u if tx.isCoinbase is true, u0=spendInputs(u,tx.vin) otherwise. (Each addition is applied to the result of the previous one; an unspendable output is skipped but its index is still consumed.)
The input check. checkTxInputs(u,tx,h) returns an optional integer: none if tx.isCoinbase is false and some input of tx.vin has no entry in u; otherwise it runs through tx.vin=[p1,…,pm] with running total a0=0, returning none if some u[pi] is none, or if u[pi]= some ci with ci.isCoinbase true and h−˙ci.height<100 (truncated natural subtraction, so in particular whenever ci.height≥h), or if moneyRange(ci.out.value) or moneyRange(ai) fails where ai=ai−1+ci.out.value; otherwise, with vin=am and vout=∑o∈tx.vouto.value, it returns none if vin<vout or if moneyRange(vin−vout) fails, and otherwise some (vin−vout).
The theorem states: for every type T with decidable equality, every UTXO set u over T, every transaction tx over T, every height h∈N and every integer fee, if
- keysNodup(u): the outpoints of u are pairwise distinct;
- the list tx.vin has no duplicate outpoints;
- tx.isCoinbase=false;
- checkTxInputs(u,tx,h)=some fee (with the same h used as the spend height);
- (freshness) for every natural number j with j<∣tx.vout∣, u[⟨tx.txid,j⟩]=none — i.e. in the original set u (before any inputs are spent) there is no entry at any of the outpoints ⟨tx.txid,0⟩,…,⟨tx.txid,∣tx.vout∣−1⟩; nothing is said about indices ≥∣tx.vout∣, and the condition is vacuous if tx.vout is empty;
- for every output o occurring in tx.vout, 0≤o.value;
then
tv(updateCoins(u,tx,h))≤tv(u)−fee,
a non-strict inequality of integers (not an equality).
The same h serves both as the spend height in the input check and as the creation height of the new coins. There is no hypothesis that tx passes checkTransaction (its vin or vout may be empty, and the output values are only required to be ≥0, not ≤MAX_MONEY). The hypotheses are jointly satisfiable only when every input of tx is present in u with a value in [0,MAX_MONEY], so a transaction with no inputs satisfies the fourth hypothesis only if ∑oo.value≤0.
Confirmed by the moderator at approval.