ConnectBlock computes the declarative ledger
ProvedBitcoinBlock.connectBlock_applyconnectBlock S b = some (u, undo) implies u = (applySpec S b).utxo: the ledger after the source loop is the fold of UpdateCoins over the block's transactions (or unchanged for the genesis).
Deprecated. Superseded by BitcoinBlockV2.connectBlock_apply (revision 2 of the block mission): the p2shSigOpCount of this revision counted every push of scriptSig instead of only the redeem script, over-counting P2SH sigops; the V2 declarations carry the corrected definition.
import Definitions.Def_BitcoinBlock import Definitions.Def_BitcoinSer
theorem BitcoinBlock.connectBlock_apply (S : ChainState) (b : BitcoinSer.Block) (u : Ledger) (undo : BlockUndo)
(h : BitcoinBlock.connectBlock S b = some (u, undo)) : u = (BitcoinBlock.applySpec S b).utxo := 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: BitcoinBlock.connectBlock_apply
Binders and hypotheses
- : a chain state .
- : a serialized block (header, transaction list ).
- : a ledger (association list from outpoints to coins).
- : a block undo list (a list of lists of coins).
- Hypothesis : .
Conclusion
Hypothesis, unfolded
Let be the double-SHA256 of the serialized header of and . is:
- if equals the genesis hash constant: ;
- else if (the block is not one of the two historical repeat blocks and the header at index of is either absent or has a hash different from the BIP34 hash constant, or ) and fails (some transaction of and some index have present in ): none;
- else run with flags (base flags P2SH/witness/taproot, or none for the BIP16 exception block, or P2SH/witness for the Taproot exception block; plus DERSIG, CLTV, CSV, NULLDUMMY when is at least , , , respectively), the height, the median-time-past function , lock-time flags ( if else ), starting state , over : if it returns none, none; otherwise with final state , none if , else .
The loop processes transactions in order from state : for a coinbase (: exactly one input with null prevout) the fee and undo are unchanged; otherwise on the current ledger must succeed with some fee, must be in , BIP68 sequence locks must hold, and the undo gets the list of coins (via , dummy if missing) spent by the inputs appended; then is increased by the transaction's sigop cost and must be ; then for a non-coinbase every input script must verify; then the ledger becomes and the loop continues.
Conclusion, unfolded
is if equals the genesis hash, and otherwise , the left fold of over the transactions in order, where removes from every entry keyed by a prevout of (nothing removed for a coinbase) and then adds, for , the coin under key — skipping outputs whose scriptPubKey is unspendable (starts with byte , or is longer than bytes), and otherwise prepending the new entry after removing any existing entry with that key.
So the statement says: whenever the executable connection succeeds with ledger , that ledger equals the one obtained by folding over the block's transactions (or for the genesis-hashed shortcut). The component is not constrained by the conclusion.
Edge cases silently included
Genesis-hashed block (both sides give ); empty (loop returns the initial state, the coinbase bound is checked against the genesis coinbase's output, and is the identity); a block whose transactions are not checked by (e.g. a coinbase-shaped transaction in a later position is treated as a coinbase by the loop and by alike); duplicate keys in ; the hypothesis may be unsatisfiable, making the statement vacuous.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.