The acceptance theorem: C(S,B,t) accepts iff V(S,B,t)
ProvedBitcoinBlock.acceptanceFor every chain state reachable from the genesis, candidate block and clock reading :
The source-linked validation path — AcceptBlockHeader, CheckBlock, ContextualCheckBlock, ConnectBlock with the published subsidy, difficulty, median-time, activation, merkle, script and BIP68 transcriptions — accepts exactly when the declarative specification admits the block: the header predicate (a valid compact target met by the hash, the tip as parent, the required difficulty, the median-time floor, the two-hour ceiling, the version floors), the block predicate, the contextual predicate, and the ledger predicate (BIP30 where it applies, every transaction admissible in sequence with the BIP68 specification and every input script verifying, the coinbase bounded by fees plus the specification subsidy).
Formalization Note. The reachability hypothesis is carried as in the goal contract; the equivalence holds for every state. Temporary future-time rejections are a separate outcome (futureTime_iff, futureTime_transient), and the resulting state is ApplySpec (apply_spec).
Deprecated. Superseded by BitcoinBlockV2.acceptance (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.acceptance (S : ChainState) (b : BitcoinSer.Block) (now : Int) (hR : BitcoinBlock.Reachable S) :
BitcoinBlock.accepts S b now ↔ BitcoinBlock.Valid S b now := 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.acceptance
Binders and hypotheses
- : a chain state (a list of serialized headers and a ledger, i.e. an association list from outpoints to coins ).
- : a serialized block: a header (version ; previous-block hash, merkle root as byte lists; time, bits, nonce ) and a list of transactions (each: version , inputs, outputs, lock time ).
- : the local clock.
- Hypothesis : , the inductively defined predicate with two rules: the initial state is reachable; and if is reachable and for some block , clock , state and undo list one has , then is reachable.
Conclusion
Left side
is the proposition , where is computed as follows.
First is evaluated: invalid if the proof-of-work check fails (hash of the header, read little-endian as a number, must be at most the compact target decoded from , with the target required to be non-negative, non-zero, non-overflowing and at most ); else missingPrev if differs from the hash of the tip header (the last header of , or the genesis header if has none); else invalid if differs from the required work (the tip's bits unless is a multiple of , in which case the retarget computed from the time of the header at index , clamped at index ); else invalid if (the sorted median of the most recent at most header times, default ); else futureTime if ; else invalid if the version is below , or while, respectively, , or ; else accept.
If the header outcome is not accept, returns that same outcome. Otherwise: if is false, invalid; else if is false, invalid; else if is none, invalid; else, with , the result is .
- is the conjunction, in order: header PoW; the merkle root computed from the txids of (pairwise double-SHA256 of concatenations, odd last element paired with itself, root zero bytes for no transactions) equals ; the merkle "mutated" flag (some aligned equal pair at some level) is false; ; ; ; the first transaction (defaulting to the genesis coinbase if there is none) is a coinbase (exactly one input, whose prevout is 32 zero bytes with index ); no later transaction is a coinbase; every transaction passes (non-empty inputs and outputs; witness-stripped size ; every output value in with every running partial sum in that range; pairwise distinct input prevouts; for a coinbase the first input's scriptSig length is in , otherwise no input prevout is null); and .
- : with and cutoff if else : every transaction is final (lock time , or lock time height resp. cutoff according to whether it is below , or every input sequence ); if then the height script ( for , for , else the canonical push of the script-number encoding) is a prefix of the first input's scriptSig of the first transaction (defaults: genesis coinbase, default input); the witness-malleation check with "expect" ; and the block weight ( stripped size full size) .
- : if the header hash equals the genesis hash, ; else if BIP30 is checked (not one of the two historical repeat blocks and the header at index is absent or has a hash other than the BIP34 hash, or height ) and some output of some transaction already exists in the ledger, none; else run the transaction loop from with the script flags for the height and the exception table, the height, the median-time-past function of (clamped to ) and the lock-time flags ( once height , else ); none propagates; otherwise none if the first transaction's total output exceeds accumulated fees plus the subsidy ( halved per blocks, beyond halvings), else . The loop, per transaction: for a coinbase, no input checks; otherwise must give a fee, the new fee total must be in money range, and BIP68 must hold; then the cumulative sigop cost must not exceed ; then (non-coinbase) every input script must verify; then the ledger is updated (inputs spent unless coinbase, spendable outputs added at the height).
Right side
is the conjunction :
- : the compact word is not negative, does not overflow, its exact (untruncated) target is and , and the header hash value is that target; ; the compact word equals ; ; and the version is not outdated (negation of the same three-way disjunction as above).
- : ; merkle root equal and not mutated; the two size bounds; every transaction among the first one is a coinbase and none of the rest is; every transaction satisfies (non-empty inputs/outputs, stripped size bound, each output value in and total output , distinct prevouts, coinbase every input scriptSig length in , non-coinbase no null prevout); and the legacy sigop bound.
- : same finality, witness-malleation and weight clauses as , but the height-script clause is "if BIP34 is active then for every transaction among the first one and every input among its first one, the height script is a prefix of its scriptSig" (vacuous when there is no transaction or no input).
- : the header hash equals the genesis hash, or all of: if BIP30 is checked then no output with is present in ; holds from (each non-coinbase satisfies — existing, mature, in-range coins; total input ; outputs inputs; BIP68 specification form; every input script verifies — and the running fee total ; the running sigop cost ; recursively on the updated ledger); and for every transaction among the first one, its total output the block's total fees (against the running ledger) plus the specification subsidy .
Edge cases silently included
is the only hypothesis and is used on both sides only as stated; empty (defaults to the genesis coinbase in several Boolean checks, vacuous quantifiers in the specification); a block whose header hash is the genesis hash (both sides short-circuit the ledger part); unbounded naturals for time/bits/version reduced modulo where converted; natural subtraction in , in the retarget index and in coin maturity; defaulting to a dummy coin of value in the specification's ; the function clamped to .
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.