Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

CheckLockTime for a block-height expiry

Proved
BitcoinHtlc.checkLockTime_iff

by pitimespi · Oct 29, 2026 · Mathlib 0df444a (Lean v4.33.1)

bip65bitcoinbitcoin-mainnetbolt3checkmultisigcltvformal-verificationhtlclightningp2wshscript

For 0≤expiry<500,000,0000 \le {\rm expiry} < 500{,}000{,}0000≤expiry<500,000,000: checkLockTime tx nIn expiry = true iff the transaction's nLockTime is also a block height (below 500,000,000), expiry ≤ nLockTime, and the input's nSequence is not 0xffffffff. BIP65 as GenericTransactionSignatureChecker::CheckLockTime implements it.

Preamble
import Definitions.Def_BitcoinHtlc
import Definitions.Def_BitcoinSer
import Definitions.Def_BitcoinSig
import Definitions.Def_BitcoinToLocal
open BitcoinToLocal BitcoinSig BitcoinVerify
open BitcoinScript
Formal statement
theorem BitcoinHtlc.checkLockTime_iff (tx : BitcoinSer.Tx) (nIn : Nat) (expiry : Int) (h0 : 0 ≤ expiry)
    (hT : expiry < 500000000) :
    BitcoinSig.checkLockTime tx nIn expiry = true ↔
      tx.nLockTime < 500000000 ∧ expiry ≤ (tx.nLockTime : Int) ∧ BitcoinToLocal.inputSequence tx nIn ≠ 0xffffffff := by sorry
Source
BOLT #3, Bitcoin Transaction and Script Formats, 'Offered HTLC Outputs' and 'Received HTLC Outputs': https://github.com/lightning/bolts/blob/master/03-transactions.md#offered-htlc-outputs; Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48: EvalScript (OP_DUP, OP_HASH160, OP_EQUAL, OP_IF/OP_NOTIF, OP_SWAP, OP_SIZE, OP_CHECKMULTISIG, OP_CHECKLOCKTIMEVERIFY, OP_CHECKSIG), GenericTransactionSignatureChecker::CheckLockTime (src/script/interpreter.cpp: https://github.com/bitcoin/bitcoin/blob/a773e1e33b349dc819b5a0edc1c7a4839dc73b48/src/script/interpreter.cpp); BIP65, BIP141, BIP147
Read-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.checkLockTime_iff

Statement. Let tx\mathit{tx}tx be any transaction, i.e. a record with a version (a natural number), a list tx.vin\mathit{tx}.\mathrm{vin}tx.vin of inputs (each input a record with a previous outpoint, a scriptSig byte string, a natural number nSequence and a witness list), a list of outputs, and a natural number tx.nLockTime\mathit{tx}.\mathrm{nLockTime}tx.nLockTime (no upper bound such as 2322^{32}232 is assumed on it here). Let nnn be any natural number (an input index, possibly out of range) and eee any integer satisfying the two hypotheses 0≤e0 \le e0≤e and e<500 000 000e < 500\,000\,000e<500000000. Then the theorem asserts the equivalence

CLT(tx,n,e)=true  ⟺  tx.nLockTime<500 000 000 ∧ e≤tx.nLockTime ∧ seq(tx,n)≠0xffffffff,\mathrm{CLT}(\mathit{tx}, n, e) = \mathrm{true} \iff \mathit{tx}.\mathrm{nLockTime} < 500\,000\,000\ \land\ e \le \mathit{tx}.\mathrm{nLockTime}\ \land\ \mathrm{seq}(\mathit{tx}, n) \ne 0\mathrm{xffffffff},CLT(tx,n,e)=true⟺tx.nLockTime<500000000 ∧ e≤tx.nLockTime ∧ seq(tx,n)=0xffffffff,

where the comparison e≤tx.nLockTimee \le \mathit{tx}.\mathrm{nLockTime}e≤tx.nLockTime is between integers (the natural number cast to Z\mathbb{Z}Z), and the two functions are as follows. seq(tx,n)\mathrm{seq}(\mathit{tx}, n)seq(tx,n) ("input sequence") is the nSequence field of the nnn-th input of tx\mathit{tx}tx (0-based) when n<∣tx.vin∣n < |\mathit{tx}.\mathrm{vin}|n<∣tx.vin∣, and otherwise the nSequence of a default input, which is 000. CLT(tx,n,t)\mathrm{CLT}(\mathit{tx}, n, t)CLT(tx,n,t) is the transcription of Bitcoin Core's CheckLockTime as a Boolean function of the transaction, the input index and an integer operand ttt: it is false unless either (tx.nLockTime<500 000 000\mathit{tx}.\mathrm{nLockTime} < 500\,000\,000tx.nLockTime<500000000 and t<500 000 000t < 500\,000\,000t<500000000) or (500 000 000≤tx.nLockTime500\,000\,000 \le \mathit{tx}.\mathrm{nLockTime}500000000≤tx.nLockTime and 500 000 000≤t500\,000\,000 \le t500000000≤t); otherwise it is false if tx.nLockTime<t\mathit{tx}.\mathrm{nLockTime} < ttx.nLockTime<t (as integers); otherwise it is false if the nSequence of the nnn-th input, with the same out-of-range default input (nSequence 000), equals 0xffffffff=4 294 967 2950\mathrm{xffffffff} = 4\,294\,967\,2950xffffffff=4294967295; and otherwise it is true. Nothing else is assumed about tx\mathit{tx}tx or nnn; in particular when n≥∣tx.vin∣n \ge |\mathit{tx}.\mathrm{vin}|n≥∣tx.vin∣ both sides refer to the default sequence value 000.

Human review
  • Endorsed by Shuze Chen · Oct 29, 2026

    Confirmed by the moderator at approval.

  • Endorsed by pitimespi · Oct 29, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me