OP_CHECKSEQUENCEVERIFY on a serialized number passes exactly when CsvPasses holds
ProvedBitcoinToLocal.csv_stepFor a state whose stack top is serialize delay with : execOp f o true OP_CHECKSEQUENCEVERIFY s = if CsvPasses f o delay then some s else none.
import Definitions.Def_BitcoinToLocal import Definitions.Def_BitcoinScript open BitcoinToLocal BitcoinSig BitcoinVerify open BitcoinScript
theorem BitcoinToLocal.csv_step (f : Flags) (o : Oracle) (s : State) (delay : Int) (rest : List Bytes)
(hs : s.stack = BitcoinScript.serialize delay :: rest) (hd : delay.natAbs < 2 ^ 32) :
BitcoinScript.execOp f o true BitcoinScript.OP_CHECKSEQUENCEVERIFY s =
if BitcoinToLocal.CsvPasses f o delay 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: BitcoinToLocal.csv_step
Statement. Let
- be a script flag record, a triple of booleans ;
- be an oracle: a record of five arbitrary hash functions on byte strings, an arbitrary function from two byte strings to an optional boolean, and two arbitrary functions (no properties are assumed of any of them);
- be an interpreter state: a record where the first two are lists of byte strings written top-first, is a list of booleans and ;
- (named
delay) and a list of byte strings.
Assume the two hypotheses
where is the absolute value as a natural number. Then
Here is the byte the preamble names OP_CHECKSEQUENCEVERIFY, and the right-hand side is a case split on the (decidable) proposition . The equality is between optional states: "" means the step succeeds and returns the same state (nothing popped, no counter changed); "" means script failure.
Unfolding execOp at 0xb2. executes one non-push opcode on state , where is an "executing" flag. It is a chain of tests on ; for the earlier tests ( or ; ; ) all fail and the CHECKSEQUENCEVERIFY branch is taken. That branch does not consult the flag (here ). It computes:
- If : return .
- Otherwise, if is empty: return . (Excluded here by the first hypothesis.)
- Otherwise let be the top element (not removed). Convert to a number with maximum size and without the minimal-encoding requirement: if return ; otherwise let , where is: if the last byte of has its bit set (for empty , "no"), then , else the little-endian value of (so ).
- If : return .
- Else if : return .
- Else if : return .
- Else return .
Here is the script-layer constant SEQUENCE_LOCKTIME_DISABLE_FLAG, is bitwise AND on naturals and truncates negatives to (irrelevant after step 4).
Unfolding serialize and CsvPasses. ; for , let be the little-endian base- digits of without trailing zeros; if the last byte of has bit set, append (if ) or (if ); otherwise set bit on the last byte if , else leave . The proposition is
What the hypotheses do. The first hypothesis fixes the top of the stack to be the encoding of (so the number read back in step 3 is ), with arbitrary below it; the alt-stack, condition stack and op-count of are unconstrained. The second hypothesis bounds below ; step 3 rejects stack tops longer than bytes. The theorem asserts the step's outcome is exactly: unchanged state when holds, failure otherwise.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.