CheckSequence for a 16-bit delay, in terms of the input's nSequence
ProvedBitcoinToLocal.checkSequence_iffFor : checkSequence tx nIn delay = true iff the transaction version is at least 2, the input's nSequence has no disable bit, its masked value (type flag and low 16 bits) is below the type flag (block-based), and the delay is at most that masked value. BIP68/BIP112 as GenericTransactionSignatureChecker::CheckSequence implements them, specialised to a block-count delay.
import Definitions.Def_BitcoinToLocal import Definitions.Def_BitcoinSer import Definitions.Def_BitcoinSig open BitcoinToLocal BitcoinSig BitcoinVerify open BitcoinScript
theorem BitcoinToLocal.checkSequence_iff (tx : BitcoinSer.Tx) (nIn : Nat) (delay : Int) (h0 : 0 ≤ delay) (h16 : delay < 2 ^ 16) :
BitcoinSig.checkSequence tx nIn delay = true ↔
2 ≤ tx.version ∧
BitcoinToLocal.inputSequence tx nIn &&& BitcoinSig.SEQUENCE_LOCKTIME_DISABLE_FLAG = 0 ∧
BitcoinToLocal.inputSequence tx nIn &&& (BitcoinSig.SEQUENCE_LOCKTIME_TYPE_FLAG ||| BitcoinSig.SEQUENCE_LOCKTIME_MASK) <
BitcoinSig.SEQUENCE_LOCKTIME_TYPE_FLAG ∧
delay.toNat ≤ BitcoinToLocal.inputSequence tx nIn &&& (BitcoinSig.SEQUENCE_LOCKTIME_TYPE_FLAG ||| BitcoinSig.SEQUENCE_LOCKTIME_MASK) := 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.checkSequence_iff
Statement. For every transaction , every natural number , and every integer (named delay) satisfying the two hypotheses
the following equivalence holds. Write and (bitwise OR on naturals; since the two constants have disjoint bits, ). Then
Here is bitwise AND on natural numbers; is itself since by hypothesis (it would be for a negative integer). The constants are the preamble's , and (the signature-layer copies).
The objects involved.
- A transaction is a record where is a list of inputs, each a record . The types impose no upper bound on or on any .
- is the field of the -th input of (zero-indexed); when a default input with is substituted, so in that case. (Then the right-hand side reduces to , i.e. under the hypotheses.)
- , for an integer , is the boolean computed as follows. Let be as above (the same out-of-range default applies). If , the result is . Else, if , the result is . Else let and (so a negative is treated as here). If it is not the case that either ( and ) or ( and ), the result is . Else, if , the result is . Otherwise the result is .
What is and is not quantified. The theorem is stated for arbitrary (including transactions with no inputs, or with fewer than inputs) and arbitrary ; the only constraints are on : non-negative and strictly below . No hypothesis bounds or . The right-hand side's third conjunct requires the masked sequence value to have bit clear, and the fourth requires to be at most that masked value (which, with bit clear, lies in ).
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.