IsFinalTx for a height-locked transaction with a non-final input
ProvedBitcoinHtlcLocks.isFinalTx_heightFor a transaction with HeightLocked tx and some input (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.
import Definitions.Def_BitcoinHtlcLocks import Definitions.Def_BitcoinSer open BitcoinHtlcLocks BitcoinVerify BitcoinHtlc open BitcoinScript hiding Bytes Byte
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 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: 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 is a record with four fields: a version number , a finite list of inputs , a finite list of outputs , and a lock time (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 , and a list of byte strings (the witness stack). Two constants are used:
The finality predicate. For a transaction , a height and a block time , the Boolean is defined by three cases, tried in order:
- if , the value is true;
- otherwise, let regarded as an integer, and let the comparison target be (cast from to ) when (as natural numbers), and otherwise; if target (as integers) the value is true;
- otherwise the value is true exactly when every input in has (so, in particular, this case yields true when is empty), and false when at least one input has a different sequence number.
Note that in case 2 the block time is only consulted when the lock time is at or above ; for lock times strictly below the threshold the height is the only quantity compared.
The "height-locked" predicate. is the proposition
both comparisons on natural numbers.
The indexed-input access. For a natural number , the expression "the -th input of with default" denotes the -th element of (zero-based) when , and otherwise the default input whose previous outpoint is (empty byte string, ), whose scriptSig is empty, whose is , and whose witness stack is empty. In this theorem the hypothesis is present, so the default is never selected and the expression is the genuine -th input.
Statement. For every transaction , every (height), every (blockTime), assuming
- (hl) , i.e. ;
- for every with (hi) and
- (hseq) the -th input of (with the default described above) has ,
the following bi-implication holds:
where the right-hand comparison is between natural numbers (no cast), while the comparison inside is between the integer casts of the same two natural numbers.
Edge cases made explicit.
- Under (hl), , so case 1 of does not apply, and , so in case 2 the comparison target is and the block time is never consulted; is an unconstrained binder that does not appear in the conclusion.
- Under (hi), is non-empty (it has at least elements), so the "all inputs final" case 3 is not vacuous; (hseq) names one specific input whose sequence number is not .
- No hypothesis restricts (it may be ), , , or the other inputs' sequence numbers.
- The statement is an "if and only if": it asserts both that finality implies and that implies finality, under the stated hypotheses.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.