A commitment spend with nSequence = to_self_delay: the delayed path opens iff version ≥ 2 and nSequence ≥ delay
ProvedBitcoinToLocal.lightning_delayFor and an input whose nSequence is below (no flags, as Lightning sets it): checkSequence tx nIn delay = true ↔ 2 ≤ tx.version ∧ delay ≤ inputSequence tx nIn. Together with p2wsh_spend and csv_concrete: the local node's delayed spend is accepted exactly when its transaction is version 2 or later, sets the input's nSequence to at least to_self_delay, and carries a valid signature for the delayed key.
import Definitions.Def_BitcoinToLocal import Definitions.Def_BitcoinSer import Definitions.Def_BitcoinSig open BitcoinToLocal BitcoinSig BitcoinVerify open BitcoinScript
theorem BitcoinToLocal.lightning_delay (tx : BitcoinSer.Tx) (nIn : Nat) (delay : Int) (h0 : 0 ≤ delay) (h16 : delay < 2 ^ 16)
(hseq : BitcoinToLocal.inputSequence tx nIn < 2 ^ 16) :
BitcoinSig.checkSequence tx nIn delay = true ↔ 2 ≤ tx.version ∧ delay.toNat ≤ BitcoinToLocal.inputSequence tx nIn := 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.lightning_delay
Statement. For every transaction , every natural number , and every integer (named delay), under the three hypotheses
the following equivalence holds:
Since , (which sends negative integers to ) is just viewed as a natural number.
The objects involved.
- A transaction is a record ; each element of the list is an input record carrying, among other fields, a natural number . No upper bound on or comes from the types.
- is the of the -th input of (zero-indexed), or when (a default input is substituted). Write for this value; the third hypothesis says , which is automatically true in the out-of-range case.
- , for an integer , is the boolean: if then ; else if then ; else, with , and : if neither ( and ) nor ( and ) then ; else if then ; else . (Here and are bitwise AND and OR on natural numbers; the constants are the preamble's , , .)
Edge cases made explicit. When is out of range, and the right-hand side becomes , i.e. . The hypotheses bound both and strictly below , so each lies entirely within the low bits; neither bit nor bit can be set in either. Nothing constrains beyond what appears in the conclusion.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.