The money supply of a chain state: the total value of the UTXO set, the issued subsidy, and the value-range invariant
DefinitionBitcoinSupplyFour names over the block mission's BitcoinBlockV2 and the subsidy mission's BitcoinSubsidy; nothing is re-transcribed.
totalValue u — the sum of nValue over the coins of a ledger (an association list of outpoints and coins), as an integer.
ValuesInRange u — every coin of has 0 ≤ nValue ≤ MAX_MONEY (the MoneyRange of consensus/amount.h).
issued n — BitcoinSubsidy.issuedBelow n as an integer: the sum of GetBlockSubsidy over heights , i.e. the subsidy a chain of blocks has issued.
genesisSubsidy — GetBlockSubsidy 0 as an integer, the fifty bitcoin of the genesis coinbase, which the source never adds to the UTXO set (ConnectBlock's genesis shortcut; CMainParams).
Formalization Note. The chain state, the ledger, updateCoins, validate and Reachable are the block mission's; coreSubsidy and issuedBelow are the subsidy mission's. Only Std is imported.
import Definitions.Def_BitcoinBlockV2 import Definitions.Def_BitcoinSubsidy /-! # The money supply as a chain invariant `GetBlockSubsidy` bounds what each coinbase may create; `CheckTxInputs` requires every other transaction to spend at least what it creates. Together they bound the total value of the UTXO set of every chain state reachable from the genesis by the subsidy issued so far. This file names the quantities the theorems speak about; the rules themselves are those of the block mission (`BitcoinBlockV2`) and the subsidy mission (`BitcoinSubsidy`). -/ namespace BitcoinSupply open BitcoinBlockV2 /-- The total value of the coins of a ledger. -/ def totalValue : Ledger → Int | [] => 0 | e :: rest => e.2.out.nValue + totalValue rest /-- Every coin's value lies in `[0, MAX_MONEY]`. -/ def ValuesInRange (u : Ledger) : Prop := ∀ e ∈ u, 0 ≤ e.2.out.nValue ∧ e.2.out.nValue ≤ MAX_MONEY /-- The subsidy a chain of `n` blocks (heights `0..n-1`) has issued, as `GetBlockSubsidy` sums it. -/ def issued (n : Nat) : Int := (BitcoinSubsidy.issuedBelow n : Int) /-- The genesis subsidy: its coinbase is not in the UTXO set (`CMainParams`, `ConnectBlock`'s genesis shortcut), so it is issued but never spendable. -/ def genesisSubsidy : Int := (BitcoinSubsidy.coreSubsidy 0 : Int) end BitcoinSupply
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: Def_BitcoinSupply.lean (namespace BitcoinSupply)
Throughout, a ledger is a finite list of pairs where is an outpoint (a pair of a byte list and a natural number ) and is a coin: a triple with an output (an integer value and a byte-list script), , and a boolean. The type places no restriction on the list: keys may repeat, values may be negative or arbitrarily large, and the list may be empty.
The constant used in this file is the integer (the block mission's integer constant, not the subsidy mission's natural-number constant; the two are numerically equal).
totalValue : Ledger → ℤ
For a ledger ,
an integer. The empty ledger has total value . Every entry of the list contributes, including entries whose key coincides with an earlier entry's key (no de-duplication is performed), entries whose value is negative, and entries whose script is unspendable; the coin's height and coinbase flag play no role.
ValuesInRange : Ledger → Prop
For a ledger , is the proposition
Both bounds are non-strict. It is vacuously true for the empty ledger. It says nothing about the sum of the values, about repeated keys, or about any field other than the value.
issued : ℕ → ℤ
For , is the natural number of the subsidy mission, cast to an integer, where
so that
Here, for a height , with ,
(the right shift of the natural number by bits). Note that for the shifted value is already , so the branch does not change any value. In particular , , and is non-decreasing in and eventually constant. The argument is a count of blocks, not a largest height: the sum runs over heights .
genesisSubsidy : ℤ
The constant cast to an integer, i.e.
It is a bare numeric constant; nothing in this definition refers to the genesis block, its coinbase, or any ledger.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.