Skip to content

Close last pinning vector using OP_TEMPLATEHASH#2

Open
darosior wants to merge 2 commits into
bip448:masterfrom
darosior:templatehash_pinning
Open

Close last pinning vector using OP_TEMPLATEHASH#2
darosior wants to merge 2 commits into
bip448:masterfrom
darosior:templatehash_pinning

Conversation

@darosior

@darosior darosior commented Jun 30, 2026

Copy link
Copy Markdown

A single pinning vector remains open in today's Lightning channels following the adoption of TRUC with the zero_fee_commitments upgrade. Unfortunately patching this gap requires introducing more interactivity (and therefore complexity) when updating the channel's state, because it requires committing to a second-stage HTLC transaction also for the preimage spend path paying the remote party in offered HTLC outputs.

The added interactivity can be avoided by simply committing to the second-stage HTLC transaction using OP_TEMPLATEHASH instead. This PR specifies exactly how this could be achieved, using a minimal approach with an experimental feature bit. A full implementation for LDK is available here, and an integration test for LDK-node demonstrating the feature end-to-end is available here.

The purpose of this work is to demonstrate that OP_TEMPLATEHASH can realistically reduce interactivity in existing protocols. It is not intended to argue that Lightning should adopt this particular change, as such a decision for a mature protocol involves many tradeoffs.

darosior and others added 2 commits June 30, 2026 15:35
Leverage OP_TEMPLATEHASH to fix the last pinning gap in Lightning, by committing to a v3 spending transaction in the preimage spend path in offered HTLC outputs.
Test vectors for the htlc_success tapscript spend path introduced by
option_htlcs_claim_tx (offered HTLC outputs become P2TR with a two-leaf
tapscript tree, and the htlc_success leaf commits via OP_TEMPLATEHASH to
a fixed v3 claim transaction).

Channel parameters reuse the same keys as zero-fee-commitments-test.json.
Three cases:
  1. Single offered HTLC above dust (baseline).
  2. Offered HTLC with sub-satoshi millisatoshi truncation — the claim tx
     output is 25000 sat for both a 25000000 msat and a 25000821 msat HTLC;
     the template hash is identical in both cases (commits to the output
     value, not the msat amount).
  3. Mixed: one outgoing offered (P2TR) + one incoming received (P2WSH,
     unchanged) HTLC.

Each case includes: signed commitment tx, htlc_timeout_script (2-of-2
tapscript), htlc_success_script (preimage check + OP_TEMPLATEHASH),
template_hash, unsigned htlc_claim_tx, and htlc_claim_tx_with_witness
(tapscript spend with the payment preimage).

Generated from the rust-lightning implementation in
lightning/src/ln/channel.rs::htlcs_claim_tx_test_vectors.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@darosior darosior force-pushed the templatehash_pinning branch from 6135147 to 57d5430 Compare June 30, 2026 19:35
@darosior darosior changed the title WIP: Close last pinning vector using OP_TEMPLATEHASH Close last pinning vector using OP_TEMPLATEHASH Jul 1, 2026
@darosior darosior marked this pull request as ready for review July 1, 2026 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant