Revocation spends and height-locked transactions
DefinitionBitcoinHtlcLocksTwo names over the HTLC and block missions.
RevocationSpend c script revHash pk sig — in verification context (transaction, input index, amount, flags), the witness's public key hashes (hash160) to the revocation hash and the signature verifies for it under the signature mission's checkSigPreTapscript with the witness-v0 sighash on script: the revocation path of an HTLC output.
HeightLocked tx — the transaction's nLockTime is nonzero and below LOCKTIME_THRESHOLD (500,000,000), i.e. a block height, as for a BOLT #3 HTLC-timeout transaction whose lock time is cltv_expiry.
Formalization Note. isFinalTx, LOCKTIME_THRESHOLD, SEQUENCE_FINAL are the block mission's (BitcoinBlockV2); receivedBytes, ReceivedSpend the HTLC mission's; verifyScript, Ctx the verification mission's. Only Std is imported.
import Definitions.Def_BitcoinHtlc
import Definitions.Def_BitcoinBlockV2
/-!
# HTLC lock times at the block level
The HTLC mission proves which witnesses spend a received HTLC output under `VerifyScript`; the
timeout path carries `OP_CHECKLOCKTIMEVERIFY <cltv_expiry>`. The block mission's
`ContextualCheckBlock` requires every transaction of a block to be final (`IsFinalTx`) at the
block's height. This file composes the two: a transaction that spends a received HTLC with a
two-element witness and sits in a block at height `h` is either a revocation spend or has
`cltv_expiry < h`. The same bound holds for a pre-signed HTLC-timeout transaction whose
`nLockTime` is the expiry.
-/
namespace BitcoinHtlcLocks
open BitcoinSer BitcoinScript BitcoinSig BitcoinVerify BitcoinHtlc BitcoinBlockV2
/-- The revocation spend of an HTLC output in context `c`: the witness's public key hashes to the
revocation hash and the signature verifies for it under the context's checker on `script`. -/
def RevocationSpend (c : BitcoinVerify.Ctx) (script revHash pk sig : BitcoinSer.Bytes) : Prop :=
BitcoinSer.hash160 pk = revHash ∧
BitcoinSig.checkSigPreTapscript (BitcoinVerify.sigFlagsOf c.flags) c.tx c.nIn c.amount .witnessV0 script sig pk = some true
/-- A transaction whose lock time is a block height (nonzero and below the threshold), as a
second-stage HTLC-timeout transaction's is. -/
def HeightLocked (tx : BitcoinSer.Tx) : Prop := 0 < tx.nLockTime ∧ tx.nLockTime < BitcoinBlockV2.LOCKTIME_THRESHOLD
end BitcoinHtlcLocks
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: definitions in Def_BitcoinHtlcLocks
This file introduces two definitions and no theorems.
BitcoinHtlcLocks.RevocationSpend
A proposition in five arguments: a verification context and four byte strings (finite lists of 8-bit vectors) , (revHash), and . The context is a record where is a record of seven Booleans , is a transaction (a record with a version , a list of inputs, a list of outputs, and a lock time ; each input having a previous outpoint, a scriptSig byte string, a sequence number and a witness stack), is an input index and is an amount. The proposition is the conjunction of two conditions:
Here with concrete SHA-256 and RIPEMD-160 implementations, so the first conjunct says the 20-byte RIPEMD-160-of-SHA-256 digest of equals as byte strings (nothing requires to have length 20; if it does not, the equality is simply false). is the signature-flag record . returns an optional Boolean: with signature version the script code is unchanged (no find-and-delete of the signature push, which only happens for the base version); it returns no value when the signature-encoding check fails (with these flags: an empty passes; otherwise, if holds and is not a valid DER-encoded signature it fails; otherwise it passes) or the public-key-encoding check fails (with and both off it never fails); otherwise it returns of , which is false if is not a valid public key, false if is empty, and otherwise splits into its last byte (the hash type) and the remaining raw signature, computes the witness-version-0 signature hash of , returns false if , and otherwise returns the outcome of verifying the raw signature against that hash under . Thus the second conjunct requires the encoding checks to pass and the ECDSA verdict to be true; a "no value" result or a false verdict both make the proposition false. Nothing in the definition refers to , , or the other flags, to the witness stacks of , or to any bound on (an out-of-range is passed through to the signature-hash computation as is). The byte string is used only as the script code for the signature hash.
BitcoinHtlcLocks.HeightLocked
A proposition in one argument, a transaction (a record with a version , a list of inputs, a list of outputs and a lock time ). It is the conjunction
both comparisons on natural numbers. Equivalently, . The proposition is false when and false when . It says nothing about the transaction's inputs, their sequence numbers, its outputs or its version, and places no upper bound such as on the lock time beyond the threshold itself.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.