More than 201 operations never succeed
ProvedBitcoinScript.op_count_failsFor every flag setting, oracle, starting stack and script with more than counted opcodes — non-push opcodes above OP_16, which is exactly what nOpCount counts (OP_1NEGATE, OP_RESERVED and OP_1…OP_16 are exempt) — returns none. Each counted opcode, executed or skipped, raises nOpCount by one and the limit is checked before every one of them.
import Definitions.Def_BitcoinScript
theorem BitcoinScript.op_count_fails (f : Flags) (o : Oracle) (stack : List Bytes) (script : Script)
(h : BitcoinScript.MAX_OPS_PER_SCRIPT < BitcoinScript.opsIn script) :
BitcoinScript.evalScript f o stack script = none := 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: BitcoinScript.op_count_fails
Binders and hypothesis. Universally quantified: , a flags record (three Booleans); , an oracle; , a list of byte lists (the initial main stack, arbitrary, possibly empty, possibly longer than ); , a list of instructions. One hypothesis, :
i.e. the static count is at least (strict inequality against ).
Unfolding opsIn. ; a push instruction contributes ; an instruction contributes if (i.e. ) and otherwise. So the hypothesis says: contains at least opcode instructions whose byte exceeds , counting every occurrence regardless of position, regardless of whether it would sit inside a non-executed conditional branch, and regardless of what the opcode does (NOPs, disabled bytes, unknown bytes, CHECKMULTISIG all count once each; OP_1NEGATE, OP_RESERVED, OP_1–OP_16 and pushes never count).
Conclusion.
Evaluating from the initial state (given main stack, empty alt stack, empty condition stack, operation count ) fails.
Unfolding the mechanism (as the code defines it). evalScript is run from State.initial, mapped to the main stack. run processes instructions in order and stops with none at the first failing step. For an instruction with , step first tests and returns none if so; otherwise it increments opCount by one and continues. This test runs for every such opcode — executed or not, disabled or not — before any other processing. Pushes and opcodes never change opCount; the CHECKMULTISIG branch of execOp may additionally add to it, and only ever increases it. Hence, as the code is written, along any successful prefix of the run the count is at least the number of counted opcodes processed so far; by the time the nd counted opcode is reached (if the run has not already failed for another reason), the count is at least and that step fails. The theorem asserts the resulting none without naming the failing step or reason.
Scope. Flags and oracle are arbitrary and the conclusion is uniform in them. The initial stack is arbitrary; a stack already exceeding elements, or a script that fails for a different reason (stack underflow, OP_RETURN, unbalanced conditional), still satisfies the conclusion since the conclusion is simply "none". The hypothesis is satisfiable (e.g. copies of ), so the theorem is not vacuous.
What is not said. The theorem does not say that scripts with succeed, nor that is the exact threshold (no converse). It does not account for the dynamic contribution of CHECKMULTISIG to the count: a script with, say, counted opcodes and a 20-key CHECKMULTISIG is not covered by the hypothesis, and nothing is asserted about it. It is stated for evalScript (count starting at ) rather than for run from an arbitrary state. It says nothing about verifyScriptPlain, where the count is reset between the two scripts, so a scriptSig and scriptPubKey whose combined count exceeds are not covered. It does not identify the position at which failure occurs or state that failure happens at the nd counted opcode. It does not mention the stack-size limit, element-size limit, or disabled opcodes.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.