No opcode lowers the operation count
ProvedBitcoinScript.execOp_opCountFor every flag setting, oracle, execution flag, opcode and states with : , and either the count is unchanged or (for CHECKMULTISIG, which adds its key count) it is at most . A case analysis over the whole opcode table.
import Definitions.Def_BitcoinScript
theorem BitcoinScript.execOp_opCount (f : Flags) (o : Oracle) (e : Bool) (c : Byte) (s s' : State)
(h : BitcoinScript.execOp f o e c s = some s') :
s.opCount ≤ s'.opCount ∧ (s'.opCount = s.opCount ∨ s'.opCount ≤ BitcoinScript.MAX_OPS_PER_SCRIPT) := 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.execOp_opCount
Binders and hypothesis. Universally quantified: , a flags record; , an oracle; , a Boolean (the "currently executing" argument of execOp, called in the definition); , a byte (any value –); and , two machine states (each with a main stack, alt stack, condition stack, and natural-number opCount). One hypothesis, :
i.e. executing the single opcode from state (with executing-flag ) succeeds and produces .
Conclusion. A conjunction about the natural numbers and :
with . In words: a successful execOp never decreases the operation count, and either leaves it unchanged or leaves it at a value not exceeding .
Unfolding execOp. execOp is a chain of cases on . Every branch except one returns a state whose opCount field is copied from unchanged (branches that return itself, or with only the stack, altstack or vfExec fields replaced, including pushNum, which touches only the stack). The single exception is the CHECKMULTISIG / CHECKMULTISIGVERIFY branch ( or ). There, after reading the key count from the top element with and requiring , it sets and fails (none) if ; if all subsequent checks succeed the returned state has . The hypothesis rules out the failure, so in that branch and ; in all other branches . The theorem's disjunction mirrors these two situations but does not name them: it only says "unchanged, or at most ".
Scope. is unconstrained: the statement covers calls with , which step makes only for conditional opcodes but which execOp as a function accepts for any . is unconstrained: for bytes on which execOp always fails (OP_RETURN, unknown bytes, disabled bytes), the hypothesis is unsatisfiable and the theorem holds vacuously for those . The states and are unconstrained beyond : in particular may already exceed (then the first disjunct, equality, is what the non-multisig branches provide; the multisig branch cannot succeed from such an since ). Flags and oracle are arbitrary; the nulldummy flag and the oracle's checkSig influence whether the multisig branch succeeds but not the arithmetic of the count.
Note on the second disjunct. The conclusion's second conjunct is a disjunction, not a conjunction: it does not assert outright. If and , the theorem is satisfied via the equality disjunct even though .
What is not said. The theorem does not say by how much the count can increase (no bound of , no mention of ). It does not say which opcodes change the count, nor that only CHECKMULTISIG does. It does not concern step, which performs its own increment and its own check before calling execOp — the theorem is about execOp alone, so nothing is said about the total effect of one loop iteration or about opsIn. It does not say anything about the stacks, vfExec, or stack sizes of . It does not say that execOp fails when the count would exceed (that is the contrapositive-shaped fact one might expect, but the statement only speaks about successful executions). It is not an "iff": no claim that a count implies success.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.