OP_CHECKLOCKTIMEVERIFY on a serialized number passes exactly when CltvPasses holds
ProvedBitcoinHtlc.cltv_stepFor a state whose stack top is serialize expiry with : execOp f o true OP_CHECKLOCKTIMEVERIFY s = if CltvPasses f o expiry then some s else none.
import Definitions.Def_BitcoinHtlc import Definitions.Def_BitcoinScript open BitcoinToLocal BitcoinSig BitcoinVerify open BitcoinScript
theorem BitcoinHtlc.cltv_step (f : Flags) (o : Oracle) (s : State) (expiry : Int) (rest : List Bytes)
(hs : s.stack = BitcoinScript.serialize expiry :: rest) (hd : expiry.natAbs < 2 ^ 32) :
BitcoinScript.execOp f o true BitcoinScript.OP_CHECKLOCKTIMEVERIFY s =
if BitcoinHtlc.CltvPasses f o expiry then some s else 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: BitcoinHtlc.cltv_step
Statement. Let be any flag set, any oracle, any interpreter state (a record of a main stack , an alt stack, a condition stack of Booleans, and an operation count), any integer and any list of byte strings, under the two hypotheses (the top of the main stack is the script-number encoding of ) and (absolute value). The theorem asserts
where is the single-opcode execution function of the interpreter (the switch of EvalScript), here called with the "executing" argument (which this opcode's branch does not consult) and the opcode byte . Its definition at this opcode, after the earlier branches (OP_1NEGATE/OP_1…OP_16, OP_NOP) are found not to match, is: if is false, the result is (state unchanged); otherwise, if is empty the result is ; otherwise the top element is decoded as , which is (whence the result is ) if and otherwise with the little-endian value of , the top bit of its last byte read as a sign (no minimal-encoding requirement); then the result is if , if , and (the state unchanged, operand left on the stack) otherwise. The right-hand side is a case split on the decidable proposition unfolded below. Note that the hypotheses do not say anything about , the alt stack, the condition stack or the operation count, and that the encoding of an with has at most bytes.
Definitions unfolded
Basic notions used throughout. A byte is an 8-bit word and a byte string (written ) is a finite list of bytes; denotes the length of a byte string . The constant is the interpreter's maximum size of one stack element. A flag set consists of three Booleans , , . An oracle is an arbitrary structure supplying eight functions with no constraints whatsoever on their behaviour: (so in particular is any function from byte strings to byte strings, not necessarily RIPEMD160SHA256, not necessarily 20-byte-valued), (first argument the signature, second the public key; the value represents a script-aborting failure, a verdict ), and . Stacks are lists written top element first. is: false for the empty string; for a one-byte string , true iff and ; for with non-empty, true iff or (so a string of zero bytes whose last byte is is false). and (the empty string). The script-number encoding of an integer is: if ; otherwise the little-endian bytes of with no trailing zero byte, then, if the last of those bytes has its top bit () set, an extra byte (for ) or (for ) is appended, and otherwise, for , the top bit of the last byte is set. For example and . The decoding ("script number of at most bytes, non-minimal encodings allowed") is if , and otherwise of the little-endian value of with the top bit of the last byte read as a sign (the empty string decodes to ).
The lock-time predicate. , for a flag set , an oracle and an integer , is the proposition
so it holds unconditionally when the cltv flag is off, and otherwise requires non-negative and the oracle's lock-time check to accept .
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.