Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

An accepted ordinary transaction cannot create value

Proved
BitcoinUtxo.tx_conservation

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

bitcoinbitcoin-mainnetconsensusformal-verificationutxovalue-conservation

For every view UUU with distinct outpoints, non-coinbase transaction txtxtx with distinct inputs, spend height hhh and fee fff such that checkTxInputs(U,tx,h)=some(f)\mathrm{checkTxInputs}(U, tx, h) = \mathrm{some}(f)checkTxInputs(U,tx,h)=some(f), provided no outpoint (tx.txid,j)(tx.\mathrm{txid}, j)(tx.txid,j) with j<∣tx.vout∣j < |tx.\mathrm{vout}|j<∣tx.vout∣ is present in UUU and every output value is non-negative,

totalValue(updateCoins(U,tx,h))≤totalValue(U)−f.\mathrm{totalValue}(\mathrm{updateCoins}(U, tx, h)) \le \mathrm{totalValue}(U) - f.totalValue(updateCoins(U,tx,h))≤totalValue(U)−f.

The ledger loses the fee, and loses more when an output is unspendable. The freshness hypothesis is the BIP30 condition; non-negativity of the outputs comes from CheckTransaction.

Preamble
import Definitions.Def_BitcoinUtxo
open BitcoinUtxo
Formal statement
theorem BitcoinUtxo.tx_conservation {T : Type} [DecidableEq T] (u : UtxoSet T) (tx : Tx T) (h : Nat) (fee : Int)
    (hn : keysNodup u) (hnd : tx.vin.Nodup) (hcb : tx.isCoinbase = false)
    (hfee : checkTxInputs u tx h = some fee)
    (hfresh : ∀ j, j < tx.vout.length → getCoin u ⟨tx.txid, j⟩ = none)
    (hpos : ∀ o ∈ tx.vout, 0 ≤ o.value) :
    totalValue (updateCoins u tx h) ≤ totalValue u - fee := 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.tx_conservation.

Let TTT be any type with decidable equality. A UTXO set uuu 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 and 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". 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 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 and Boolean o.unspendableo.\mathrm{unspendable}o.unspendable) and Boolean isCoinbase\mathrm{isCoinbase}isCoinbase. 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.

Spending and adding. spendCoin(u,p)\mathrm{spendCoin}(u, p)spendCoin(u,p) deletes every entry of outpoint ppp; spendInputs(u,[p1,…,pm])\mathrm{spendInputs}(u, [p_1,\dots,p_m])spendInputs(u,[p1​,…,pm​]) applies this successively for p1,…,pmp_1, \dots, p_mp1​,…,pm​. addCoin(u,p,c)\mathrm{addCoin}(u, p, c)addCoin(u,p,c) is uuu unchanged if c.out.unspendablec.\mathrm{out}.\mathrm{unspendable}c.out.unspendable is true, and otherwise (p,c)(p, c)(p,c) prepended to spendCoin(u,p)\mathrm{spendCoin}(u, p)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,\mathrm{updateCoins}(u, \mathrm{tx}, h) = \text{the result of adding, for } j = 0, 1, \dots, |\mathrm{tx}.\mathrm{vout}| - 1 \text{ in order, the coin } \langle o_j, h, \mathrm{tx}.\mathrm{isCoinbase}\rangle \text{ at outpoint } \langle \mathrm{tx}.\mathrm{txid}, j\rangle \text{ to } u_0,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 ojo_joj​ is the jjj-th output of tx.vout\mathrm{tx}.\mathrm{vout}tx.vout, and u0=uu_0 = uu0​=u if tx.isCoinbase\mathrm{tx}.\mathrm{isCoinbase}tx.isCoinbase is true, u0=spendInputs(u,tx.vin)u_0 = \mathrm{spendInputs}(u, \mathrm{tx}.\mathrm{vin})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)\mathrm{checkTxInputs}(u, \mathrm{tx}, h)checkTxInputs(u,tx,h) returns an optional integer: none if tx.isCoinbase\mathrm{tx}.\mathrm{isCoinbase}tx.isCoinbase is false and some input of tx.vin\mathrm{tx}.\mathrm{vin}tx.vin has no entry in uuu; otherwise it runs through tx.vin=[p1,…,pm]\mathrm{tx}.\mathrm{vin} = [p_1, \dots, p_m]tx.vin=[p1​,…,pm​] with running total a0=0a_0 = 0a0​=0, returning none if some u[pi]u[p_i]u[pi​] is none, or if u[pi]=u[p_i] = u[pi​]= some cic_ici​ with ci.isCoinbasec_i.\mathrm{isCoinbase}ci​.isCoinbase true and h−˙ci.height<100h \mathbin{\dot-} c_i.\mathrm{height} < 100h−˙​ci​.height<100 (truncated natural subtraction, so in particular whenever ci.height≥hc_i.\mathrm{height} \ge hci​.height≥h), or if moneyRange(ci.out.value)\mathrm{moneyRange}(c_i.\mathrm{out}.\mathrm{value})moneyRange(ci​.out.value) or moneyRange(ai)\mathrm{moneyRange}(a_i)moneyRange(ai​) fails where ai=ai−1+ci.out.valuea_i = a_{i-1} + c_i.\mathrm{out}.\mathrm{value}ai​=ai−1​+ci​.out.value; otherwise, with vin=amv_{\mathrm{in}} = a_mvin​=am​ and vout=∑o∈tx.vouto.valuev_{\mathrm{out}} = \sum_{o \in \mathrm{tx}.\mathrm{vout}} o.\mathrm{value}vout​=∑o∈tx.vout​o.value, it returns none if vin<voutv_{\mathrm{in}} < v_{\mathrm{out}}vin​<vout​ or if moneyRange(vin−vout)\mathrm{moneyRange}(v_{\mathrm{in}} - v_{\mathrm{out}})moneyRange(vin​−vout​) fails, and otherwise some (vin−vout)(v_{\mathrm{in}} - v_{\mathrm{out}})(vin​−vout​).

The theorem states: for every type TTT with decidable equality, every UTXO set uuu over TTT, every transaction tx\mathrm{tx}tx over TTT, every height h∈Nh \in \mathbb{N}h∈N and every integer fee\mathrm{fee}fee, if

  • keysNodup(u)\mathrm{keysNodup}(u)keysNodup(u): the outpoints of uuu are pairwise distinct;
  • the list tx.vin\mathrm{tx}.\mathrm{vin}tx.vin has no duplicate outpoints;
  • tx.isCoinbase=false\mathrm{tx}.\mathrm{isCoinbase} = \mathrm{false}tx.isCoinbase=false;
  • checkTxInputs(u,tx,h)=some fee\mathrm{checkTxInputs}(u, \mathrm{tx}, h) = \text{some } \mathrm{fee}checkTxInputs(u,tx,h)=some fee (with the same hhh used as the spend height);
  • (freshness) for every natural number jjj with j<∣tx.vout∣j < |\mathrm{tx}.\mathrm{vout}|j<∣tx.vout∣, u[⟨tx.txid,j⟩]=noneu[\langle \mathrm{tx}.\mathrm{txid}, j\rangle] = \text{none}u[⟨tx.txid,j⟩]=none — i.e. in the original set uuu (before any inputs are spent) there is no entry at any of the outpoints ⟨tx.txid,0⟩,…,⟨tx.txid,∣tx.vout∣−1⟩\langle \mathrm{tx}.\mathrm{txid}, 0\rangle, \dots, \langle \mathrm{tx}.\mathrm{txid}, |\mathrm{tx}.\mathrm{vout}|-1\rangle⟨tx.txid,0⟩,…,⟨tx.txid,∣tx.vout∣−1⟩; nothing is said about indices ≥∣tx.vout∣\ge |\mathrm{tx}.\mathrm{vout}|≥∣tx.vout∣, and the condition is vacuous if tx.vout\mathrm{tx}.\mathrm{vout}tx.vout is empty;
  • for every output ooo occurring in tx.vout\mathrm{tx}.\mathrm{vout}tx.vout, 0≤o.value0 \le o.\mathrm{value}0≤o.value;

then

tv(updateCoins(u,tx,h))≤tv(u)−fee,\mathrm{tv}\big(\mathrm{updateCoins}(u, \mathrm{tx}, h)\big) \le \mathrm{tv}(u) - \mathrm{fee},tv(updateCoins(u,tx,h))≤tv(u)−fee,

a non-strict inequality of integers (not an equality).

The same hhh 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\mathrm{tx}tx passes checkTransaction (its vin\mathrm{vin}vin or vout\mathrm{vout}vout may be empty, and the output values are only required to be ≥0\ge 0≥0, not ≤MAX_MONEY\le \mathrm{MAX\_MONEY}≤MAX_MONEY). The hypotheses are jointly satisfiable only when every input of tx\mathrm{tx}tx is present in uuu with a value in [0,MAX_MONEY][0, \mathrm{MAX\_MONEY}][0,MAX_MONEY], so a transaction with no inputs satisfies the fourth hypothesis only if ∑oo.value≤0\sum_{o} o.\mathrm{value} \le 0∑o​o.value≤0.

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