Apply-spec equality
ProvedBitcoinBlock.apply_spec: whenever the validation accepts, the resulting state is the declaratively specified one — the headers extended by the block's header and the ledger transformed by the block's transactions in order.
Deprecated. Superseded by BitcoinBlockV2.apply_spec (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.apply_spec (S : ChainState) (b : BitcoinSer.Block) (now : Int) (S' : ChainState) (undo : BlockUndo)
(h : BitcoinBlock.validate S b now = .accept S' undo) : S' = BitcoinBlock.applySpec S b := 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.apply_spec
Binders and hypotheses
- : a chain state (list of serialized headers; ledger as an association list outpoint coin).
- : a serialized block (header and transaction list ).
- : the clock.
- : a chain state.
- : a block undo list (a list of lists of coins).
- Hypothesis : .
Conclusion
Unfolding the hypothesis
returns only along one path: the header outcome is accept (PoW holds; equals the tip hash; bits modulo equal the required bits; the time exceeds the tip's median-time-past; the time is at most ; the version is not outdated for height ), then is true, then is true, then , in which case the result is
So the hypothesis says exactly that all these checks pass and , , where is the ledger returned by : itself if the header hash equals the genesis hash; otherwise the ledger produced by the transaction loop (for each transaction in order: non-coinbase inputs spent from the running ledger, then its spendable outputs — those whose script does not start with and is at most bytes long — added at height with the coinbase flag, each added entry replacing any existing entry with the same outpoint), after the BIP30, input, fee, BIP68, sigop, script and coinbase-bound checks have all passed.
Unfolding the conclusion
is:
- if the double-SHA256 hash of equals the genesis hash: ;
- otherwise , where and , with = add the outputs of (indices , keyed by , height , coinbase flag , unspendable outputs skipped) to the ledger obtained from by removing every entry keyed by a prevout of — except that for a coinbase (exactly one input with null prevout) nothing is removed.
Thus the claim is that the state produced by the executable path equals the state obtained by appending the header and applying (or leaving the ledger untouched for a genesis-hashed block). The undo list and the clock appear only in the hypothesis.
Edge cases silently included
A block whose header hash is the genesis hash (both sides keep the ledger); cannot be empty under (checkBlock requires it non-empty) but no explicit hypothesis says so; is unconstrained beyond ; the hypothesis may be unsatisfiable for a given (e.g. an empty header list, where the tip defaults to the genesis header), making the statement vacuous there.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.