Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

IsFinalTx for a height-locked transaction with a non-final input

Proved
BitcoinHtlcLocks.isFinalTx_height

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

bip65bitcoinbitcoin-mainnetbolt3consensusfinalityformal-verificationhtlclightninglocktime

For a transaction with HeightLocked tx and some input iii (in range) whose nSequence is not 0xffffffff: isFinalTx tx height blockTime = true ↔ tx.nLockTime < height. The lock time is enforced as a block height, and the non-final input blocks the SEQUENCE_FINAL bypass.

Preamble
import Definitions.Def_BitcoinHtlcLocks
import Definitions.Def_BitcoinSer
open BitcoinHtlcLocks BitcoinVerify BitcoinHtlc
open BitcoinScript hiding Bytes Byte
Formal statement
theorem BitcoinHtlcLocks.isFinalTx_height (tx : BitcoinSer.Tx) (height : Nat) (blockTime : Int)
    (hl : BitcoinHtlcLocks.HeightLocked tx) (i : Nat) (hi : i < tx.vin.length)
    (hseq : (tx.vin.getD i ⟨⟨[], 0⟩, [], 0, []⟩).nSequence ≠ BitcoinBlockV2.SEQUENCE_FINAL) :
    BitcoinBlockV2.isFinalTx tx height blockTime = true ↔ tx.nLockTime < height := by sorry
Source
BOLT #3, HTLC-Timeout and HTLC-Success Transactions (locktime = cltv_expiry), Received HTLC Outputs: https://github.com/lightning/bolts/blob/master/03-transactions.md#htlc-timeout-and-htlc-success-transactions; Bitcoin Core a773e1e33b349dc819b5a0edc1c7a4839dc73b48: IsFinalTx (src/consensus/tx_verify.cpp) as the block mission's `isFinalTx`, ContextualCheckBlock (src/validation.cpp), GenericTransactionSignatureChecker::CheckLockTime (src/script/interpreter.cpp); BIP65
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: BitcoinHtlcLocks.isFinalTx_height

Declaration shape. This is a theorem with a universally quantified transaction, a height, a block time, an input index, and three hypotheses, whose conclusion is a bi-implication.

Objects involved. A transaction txtxtx is a record with four fields: a version number version(tx)∈N\mathrm{version}(tx) \in \mathbb{N}version(tx)∈N, a finite list of inputs vin(tx)\mathrm{vin}(tx)vin(tx), a finite list of outputs vout(tx)\mathrm{vout}(tx)vout(tx), and a lock time nLockTime(tx)∈N\mathrm{nLockTime}(tx) \in \mathbb{N}nLockTime(tx)∈N (a natural number, not bounded by the statement to 32 bits). An input is a record with four fields: a previous outpoint (a byte string "hash" together with a natural-number index), a byte string scriptSig, a sequence number nSequence∈N\mathrm{nSequence} \in \mathbb{N}nSequence∈N, and a list of byte strings (the witness stack). Two constants are used:

LOCKTIME_THRESHOLD=500 000 000,SEQUENCE_FINAL=0xffffffff=4 294 967 295.\mathrm{LOCKTIME\_THRESHOLD} = 500\,000\,000, \qquad \mathrm{SEQUENCE\_FINAL} = \mathtt{0xffffffff} = 4\,294\,967\,295 .LOCKTIME_THRESHOLD=500000000,SEQUENCE_FINAL=0xffffffff=4294967295.

The finality predicate. For a transaction txtxtx, a height h∈Nh \in \mathbb{N}h∈N and a block time t∈Zt \in \mathbb{Z}t∈Z, the Boolean isFinalTx(tx,h,t)\mathrm{isFinalTx}(tx, h, t)isFinalTx(tx,h,t) is defined by three cases, tried in order:

  1. if nLockTime(tx)=0\mathrm{nLockTime}(tx) = 0nLockTime(tx)=0, the value is true;
  2. otherwise, let L=nLockTime(tx)L = \mathrm{nLockTime}(tx)L=nLockTime(tx) regarded as an integer, and let the comparison target be hhh (cast from N\mathbb{N}N to Z\mathbb{Z}Z) when nLockTime(tx)<500 000 000\mathrm{nLockTime}(tx) < 500\,000\,000nLockTime(tx)<500000000 (as natural numbers), and ttt otherwise; if L<L <L< target (as integers) the value is true;
  3. otherwise the value is true exactly when every input in vin(tx)\mathrm{vin}(tx)vin(tx) has nSequence=0xffffffff\mathrm{nSequence} = \mathtt{0xffffffff}nSequence=0xffffffff (so, in particular, this case yields true when vin(tx)\mathrm{vin}(tx)vin(tx) is empty), and false when at least one input has a different sequence number.

Note that in case 2 the block time ttt is only consulted when the lock time is at or above 500 000 000500\,000\,000500000000; for lock times strictly below the threshold the height is the only quantity compared.

The "height-locked" predicate. HeightLocked(tx)\mathrm{HeightLocked}(tx)HeightLocked(tx) is the proposition

0<nLockTime(tx)  ∧  nLockTime(tx)<500 000 000,0 < \mathrm{nLockTime}(tx) \;\wedge\; \mathrm{nLockTime}(tx) < 500\,000\,000 ,0<nLockTime(tx)∧nLockTime(tx)<500000000,

both comparisons on natural numbers.

The indexed-input access. For a natural number iii, the expression "the iii-th input of txtxtx with default" denotes the iii-th element of vin(tx)\mathrm{vin}(tx)vin(tx) (zero-based) when i<∣vin(tx)∣i < |\mathrm{vin}(tx)|i<∣vin(tx)∣, and otherwise the default input whose previous outpoint is (empty byte string, 000), whose scriptSig is empty, whose nSequence\mathrm{nSequence}nSequence is 000, and whose witness stack is empty. In this theorem the hypothesis i<∣vin(tx)∣i < |\mathrm{vin}(tx)|i<∣vin(tx)∣ is present, so the default is never selected and the expression is the genuine iii-th input.

Statement. For every transaction txtxtx, every h∈Nh \in \mathbb{N}h∈N (height), every t∈Zt \in \mathbb{Z}t∈Z (blockTime), assuming

  • (hl) HeightLocked(tx)\mathrm{HeightLocked}(tx)HeightLocked(tx), i.e. 0<nLockTime(tx)<500 000 0000 < \mathrm{nLockTime}(tx) < 500\,000\,0000<nLockTime(tx)<500000000;
  • for every i∈Ni \in \mathbb{N}i∈N with (hi) i<∣vin(tx)∣i < |\mathrm{vin}(tx)|i<∣vin(tx)∣ and
  • (hseq) the iii-th input of txtxtx (with the default described above) has nSequence≠0xffffffff\mathrm{nSequence} \neq \mathtt{0xffffffff}nSequence=0xffffffff,

the following bi-implication holds:

isFinalTx(tx,h,t)=true⟺nLockTime(tx)<h,\mathrm{isFinalTx}(tx, h, t) = \mathbf{true} \quad\Longleftrightarrow\quad \mathrm{nLockTime}(tx) < h ,isFinalTx(tx,h,t)=true⟺nLockTime(tx)<h,

where the right-hand comparison is between natural numbers (no cast), while the comparison inside isFinalTx\mathrm{isFinalTx}isFinalTx is between the integer casts of the same two natural numbers.

Edge cases made explicit.

  • Under (hl), nLockTime(tx)≠0\mathrm{nLockTime}(tx) \neq 0nLockTime(tx)=0, so case 1 of isFinalTx\mathrm{isFinalTx}isFinalTx does not apply, and nLockTime(tx)<500 000 000\mathrm{nLockTime}(tx) < 500\,000\,000nLockTime(tx)<500000000, so in case 2 the comparison target is hhh and the block time ttt is never consulted; ttt is an unconstrained binder that does not appear in the conclusion.
  • Under (hi), vin(tx)\mathrm{vin}(tx)vin(tx) is non-empty (it has at least i+1i+1i+1 elements), so the "all inputs final" case 3 is not vacuous; (hseq) names one specific input whose sequence number is not 0xffffffff\mathtt{0xffffffff}0xffffffff.
  • No hypothesis restricts hhh (it may be 000), version(tx)\mathrm{version}(tx)version(tx), vout(tx)\mathrm{vout}(tx)vout(tx), or the other inputs' sequence numbers.
  • The statement is an "if and only if": it asserts both that finality implies nLockTime(tx)<h\mathrm{nLockTime}(tx) < hnLockTime(tx)<h and that nLockTime(tx)<h\mathrm{nLockTime}(tx) < hnLockTime(tx)<h implies finality, under the stated hypotheses.
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