UpdateCoins creates at most the output value and destroys the input value
ProvedBitcoinSupply.update_boundFor a ledger with distinct keys and non-negative coin values, and a transaction with non-negative outputs, distinct prevouts, and (unless it is a coinbase) every input present in : totalValue (updateCoins u tx H) ≤ totalValue u + valueOut tx − (if coinbase then 0 else valueIn u tx.vin). The inequality (rather than equality) absorbs unspendable outputs, which AddCoin does not store, and overwritten coins.
import Definitions.Def_BitcoinSupply import Definitions.Def_BitcoinSer open BitcoinSupply BitcoinBlockV2
theorem BitcoinSupply.update_bound (u : Ledger) (tx : BitcoinSer.Tx) (H : Nat) (hnd : BitcoinBlockV2.keysNodup u)
(hnn : ∀ e ∈ u, 0 ≤ e.2.out.nValue) (hos : ∀ o ∈ tx.vout, 0 ≤ o.nValue)
(hdup : (tx.vin.map BitcoinSer.TxIn.prevout).Nodup)
(hin : BitcoinBlockV2.isCoinBase tx = false → ∀ i ∈ tx.vin, BitcoinBlockV2.haveCoin u i.prevout = true) :
BitcoinSupply.totalValue (BitcoinBlockV2.updateCoins u tx H) ≤
BitcoinSupply.totalValue u + BitcoinBlockV2.valueOut tx -
(if BitcoinBlockV2.isCoinBase tx then 0 else BitcoinBlockV2.valueIn u tx.vin) := by sorryRead-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: BitcoinSupply.update_bound
Objects and notation
A ledger is a finite list of pairs : an outpoint (a byte list and a natural number ), a coin whose output has an integer value and a byte-list script. A transaction has a version , a list of inputs (each input has an outpoint , a scriptSig, a sequence number and a witness), a list of outputs (each output has an integer and a script), and a lock time.
- : the coin of the first entry of whose key equals , if any. is true iff such an entry exists.
- : that coin if it exists, otherwise the dummy coin whose output has value (and empty script, height , non-coinbase).
- is true iff consists of exactly one input and that input's outpoint is the null outpoint (hash 32 zero bytes and index ). A transaction with no inputs, or with two or more inputs, is not a coinbase under this definition.
- (integer sum, for no outputs).
- ; an input whose outpoint has no entry in contributes .
- , every list entry counted.
- : the list of keys of has no repeated element.
- : the double SHA-256 of the witness-stripped serialization of .
- A script is unspendable iff ( is non-empty and its first byte is ) or .
- for : let if , and otherwise let be with, for each input of in order, every entry whose key equals deleted. Then, for the outputs of in order with their indices: if 's script is unspendable the ledger is unchanged; otherwise every entry with key is deleted and the entry is prepended. The result is the ledger after the last output.
Statement
For every ledger , every transaction , and every natural number , under the hypotheses
- : the keys of are pairwise distinct;
- for every entry : ;
- for every output : ;
- the list of outpoints has no repeated element;
- if is false, then for every input , is true (some entry of has key );
the following inequality between integers holds:
The subtraction is ordinary integer subtraction. The inequality is non-strict.
Edge cases the statement includes
- only becomes the recorded height of the newly added coins; it is otherwise unconstrained (it may be , or unrelated to anything in ).
- with no inputs: is false, hypothesis 5 is vacuous, no entries are deleted, , and the claim is \mathrm{totalValue}(\text{utx added}) \le \mathrm{totalValue}(u) + \mathrm{valueOut}(tx).
- with no outputs: nothing is added; for a non-coinbase the claim is that deleting the spent entries lowers the total by at least .
- A coinbase (one null-outpoint input): no deletion, no term; hypothesis 5 does not apply, and nothing requires to lack an entry at the null outpoint.
- Outputs with unspendable scripts are counted in but are never added to the ledger.
- Outputs of whose key already occurs in replace the existing entry (the old entry is deleted); hypothesis 5 and the BIP30 rule are not part of this statement, so such collisions are allowed here.
- No upper bound on any value is assumed: values in and in may exceed ; only non-negativity is assumed.
- The hypotheses do not require to be well formed in any other way (no script checks, no size checks, no requirement that non-coinbase inputs have non-null outpoints).
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.