Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

A coinbase adds at most its output value

Proved
BitcoinUtxo.coinbase_bound

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

bitcoinbitcoin-mainnetconsensusformal-verificationutxovalue-conservation

For every view UUU, coinbase transaction txtxtx, height hhh, 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)+valueOut(tx).\mathrm{totalValue}(\mathrm{updateCoins}(U, tx, h)) \le \mathrm{totalValue}(U) + \mathrm{valueOut}(tx).totalValue(updateCoins(U,tx,h))≤totalValue(U)+valueOut(tx).

Equality holds when no output is unspendable.

Preamble
import Definitions.Def_BitcoinUtxo
open BitcoinUtxo
Formal statement
theorem BitcoinUtxo.coinbase_bound {T : Type} [DecidableEq T] (u : UtxoSet T) (tx : Tx T) (h : Nat)
    (hcb : tx.isCoinbase = true)
    (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 + valueOut tx := 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.coinbase_bound.

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 (an integer c.out.valuec.\mathrm{out}.\mathrm{value}c.out.value and a 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 (with multiplicity, no range restriction). A transaction tx\mathrm{tx}tx 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 ooo with integer o.valueo.\mathrm{value}o.value and Boolean o.unspendableo.\mathrm{unspendable}o.unspendable) and 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 (zero if vout\mathrm{vout}vout is empty).

spendCoin(u,p)\mathrm{spendCoin}(u, p)spendCoin(u,p) deletes every entry of outpoint ppp from uuu. addCoin(u,p,c)\mathrm{addCoin}(u, p, c)addCoin(u,p,c) is uuu unchanged if c.out.unspendable=truec.\mathrm{out}.\mathrm{unspendable} = \mathrm{true}c.out.unspendable=true, and otherwise (p,c)(p, c)(p,c) prepended to spendCoin(u,p)\mathrm{spendCoin}(u, p)spendCoin(u,p). For a transaction with tx.isCoinbase=true\mathrm{tx}.\mathrm{isCoinbase} = \mathrm{true}tx.isCoinbase=true (the case of this theorem), the inputs are not spent, and

updateCoins(u,tx,h)=the result of successively applying addCoin(⋅,⟨tx.txid,j⟩,⟨oj,h,true⟩) to u for j=0,1,…,∣tx.vout∣−1,\mathrm{updateCoins}(u, \mathrm{tx}, h) = \text{the result of successively applying } \mathrm{addCoin}\big(\cdot, \langle \mathrm{tx}.\mathrm{txid}, j\rangle, \langle o_j, h, \mathrm{true}\rangle\big) \text{ to } u \text{ for } j = 0, 1, \dots, |\mathrm{tx}.\mathrm{vout}|-1,updateCoins(u,tx,h)=the result of successively applying addCoin(⋅,⟨tx.txid,j⟩,⟨oj​,h,true⟩) to u for j=0,1,…,∣tx.vout∣−1,

where ojo_joj​ is the jjj-th output of tx.vout\mathrm{tx}.\mathrm{vout}tx.vout and ⟨oj,h,true⟩\langle o_j, h, \mathrm{true}\rangle⟨oj​,h,true⟩ is the coin with output ojo_joj​, height hhh and coinbase flag true. An unspendable output adds nothing but still consumes its index.

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

  • tx.isCoinbase=true\mathrm{tx}.\mathrm{isCoinbase} = \mathrm{true}tx.isCoinbase=true;
  • (freshness) for every natural number 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. uuu has 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⟩ (indices ≥∣tx.vout∣\ge |\mathrm{tx}.\mathrm{vout}|≥∣tx.vout∣ are not covered; vacuous when vout\mathrm{vout}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)+valueOut(tx),\mathrm{tv}\big(\mathrm{updateCoins}(u, \mathrm{tx}, h)\big) \le \mathrm{tv}(u) + \mathrm{valueOut}(\mathrm{tx}),tv(updateCoins(u,tx,h))≤tv(u)+valueOut(tx),

a non-strict integer inequality.

There is no hypothesis that the outpoints of uuu are pairwise distinct, no hypothesis that tx\mathrm{tx}tx passes checkTransaction or any input check, no upper bound on the output values, and no constraint on tx.vin\mathrm{tx}.\mathrm{vin}tx.vin (which plays no role, since a coinbase-flagged transaction spends nothing). The height hhh enters only as the recorded height of the newly added coins and does not affect the conclusion's quantities.

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