CheckBlock characterized
ProvedBitcoinBlock.checkBlock_iffcheckBlock b = true iff the proof of work holds and BlockSpec b: non-empty, merkle root matching and unmutated, size limits, exactly the first transaction a coinbase, every transaction well formed, legacy sigops within 80,000.
Deprecated. Superseded by BitcoinBlockV2.checkBlock_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.checkBlock_iff (b : BitcoinSer.Block) :
BitcoinBlock.checkBlock b = true ↔ BitcoinBlock.checkHeaderPow b.header = true ∧ BitcoinBlock.BlockSpec 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.checkBlock_iff
Binders
- : a serialized block: a header (version ; prevBlock, merkleRoot byte lists; time, bits, nonce ) and a transaction list (each transaction: version , input list, output list, lock time ; an input has a prevout , a scriptSig, a sequence and a witness stack; an output has a value and a scriptPubKey).
There are no hypotheses.
Conclusion
Left side, unfolded
is the Boolean conjunction (in source order) of:
- : the little-endian value of the double-SHA256 of the serialized header is at most the target decoded (with truncation modulo ) from , and that compact word is not negative, not zero-valued, not overflowing, and decodes to at most ;
- the first component of equals , where runs the merkle loop on the list of txids (double-SHA256 of the witness-stripped serialization) of : while more than one hash remains, flag "mutated" if some aligned pair (positions ) is equal, then replace the list by the double-SHA256 of each concatenated aligned pair, an odd last element being concatenated with itself; the root is the single remaining hash, or zero bytes for an empty list;
- the second component (the mutated flag) of is false;
- is non-empty;
- ;
- , where is the serialized header followed by the compact-size-prefixed list of witness-stripped transaction serializations;
- of the head of , with the genesis coinbase as default for an empty list; means is a one-element list whose prevout has hash equal to zero bytes and index ;
- every transaction of after the first is not a coinbase;
- every transaction of satisfies : , , , the output loop succeeds (each value and and each running partial sum in ), the prevouts of are pairwise distinct, and if then the scriptSig length of the head of (default input: empty prevout hash, index , empty scriptSig, sequence , empty witness) lies in , otherwise no input of has a null prevout;
- , where sums, over every input scriptSig and every output scriptPubKey, the inaccurate sigop count: scan the script instruction by instruction (stopping at a parse failure or when the byte-length fuel runs out), adding for each
OP_CHECKSIG/OP_CHECKSIGVERIFYbyte and for eachOP_CHECKMULTISIG/OP_CHECKMULTISIGVERIFYbyte.
Right side, unfolded
as in item 1, and , the proposition:
- ;
- and ;
- and ;
- every transaction in the first one element of is a coinbase, and every transaction after the first is not;
- every satisfies : , , , every output value satisfies , the sum of all output values is , prevouts pairwise distinct, every input's scriptSig length is in , and no input has a null prevout;
- .
Edge cases silently included
Empty (left: item 4 fails, while item 7 would consult the genesis coinbase; right: first clause fails); the coinbase scriptSig bound is checked on the head input on the left versus all inputs on the right (a coinbase has exactly one input); partial-sum range on the left versus total-sum range on the right; unbounded reduced modulo ; no well-formedness of byte lengths (hashes of length other than 32) is assumed.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.