ContextualCheckBlock characterized
ProvedBitcoinBlock.contextualCheck_iffFor a non-empty block whose transactions have inputs, contextualCheckBlock S b = true iff ContextSpec S b: every transaction final against the lock-time cutoff (median time past once CSV is active, else the block time), the BIP34 coinbase height prefix when active, the witness commitment rule, and the weight limit.
Deprecated. Superseded by BitcoinBlockV2.contextualCheck_iff (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.contextualCheck_iff (S : ChainState) (b : BitcoinSer.Block)
(hne : b.vtx ≠ []) (hvin : ∀ tx ∈ b.vtx, tx.vin ≠ []) :
BitcoinBlock.contextualCheckBlock S b = true ↔ BitcoinBlock.ContextSpec 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.contextualCheck_iff
Binders and hypotheses
- : a chain state .
- : a serialized block (header, transaction list ).
- Hypothesis : .
- Hypothesis : every transaction has .
Both hypotheses are carried by the statement and absent from the conclusion.
Conclusion
Common notation: ; (natural subtraction); (sorted median of the first of the header times at heights taken most recent first, default ) if , else as an integer.
Left side, unfolded
Boolean conjunction of:
- every satisfies : true if ; else true if when , respectively otherwise; else true iff every input has ;
- is false, or is a prefix of the scriptSig of the head input (default input with empty scriptSig) of the head transaction of (default: the genesis coinbase); if , if , otherwise the canonical push (length byte or PUSHDATA prefix) of the little-endian minimal signed script-number encoding of ;
- : with = "no transaction of has an input with a non-empty witness": if the expectation flag is false, ; if true, find the commitment index — the largest output index of the first transaction whose scriptPubKey has length and starts with bytes (none if is empty): if none, ; else the witness stack of the first input (default input) of the first transaction (default genesis coinbase) must be exactly one element of length with equal to bytes through of output 's scriptPubKey, where is the merkle root of zero bytes followed by the wtxids of the transactions after the first;
- , where .
Right side, unfolded
is the conjunction of:
- (same function);
- is a prefix of ;
- (same function);
- .
The two sides differ only in clause 2, where the executable side uses head-with-default and the specification quantifies over the (at most one) first transaction and its (at most one) first input.
Edge cases silently included
The hypotheses rule out exactly the cases where clause 2 differs (empty , or a first transaction with no inputs); empty header list (, median ); unbounded; and unbounded naturals compared exactly; no coinbase or assumption (the "first transaction" need not be a coinbase).
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.