Htlcs

From claude-dev-suite/claude-dev-suite · View interactive version

Htlcs is an AI agent skill from the GitHub repository claude-dev-suite/claude-dev-suite. HTLC (Hash Time-Locked Contract) lifecycle: offered/received, fulfill via preimage, fail/timeout, 2nd-stage txs. Modern variant PTLCs (Point Time-Locked Contracts) with adaptor signatures. USE WHEN: implementing payment forwarding, debugging stuck HTLCs, reasoning about CLTV deltas in routes.

How to use this skill

Skill file

HTLCs (Hash Time-Locked Contracts)

The atomicity primitive that makes Lightning routing work. An HTLC

is "claimable with preimage r such that hash(r) = H, OR refundable

after CLTV expires".

Lifecycle

Sender → first hop

Alice → Bob: update_add_htlc(amount, hash, cltv, onion)

The onion contains routing data for Bob to forward.

Forward chain

Bob receives, peels onion, sees instructions to forward to Carol:

Bob → Carol: update_add_htlc(amount - bob_fee, hash, cltv - bob_delta, onion')

Continues until destination Dave (final hop, onion is empty payload).

Settlement (cooperative)

Dave reveals preimage r:

Dave → Carol: update_fulfill_htlc(channel_id, htlc_id, r)
Carol → Bob:  update_fulfill_htlc(...)   (verifies hash(r) = H, propagates)
Bob → Alice:  update_fulfill_htlc(...)

Each hop earns its fee (held in the HTLC amount).

Settlement (failed)

Carol → Bob: update_fail_htlc(channel_id, htlc_id, encrypted_failure)
Bob → Alice: update_fail_htlc(...)

Failure encryption uses ChaCha20 with onion shared secrets, hop-by-hop

(only Alice can decrypt the original failure).

Settlement (force-close)

If a peer is unresponsive past timeout → force-close that channel,

HTLC resolved on chain.

CLTV deltas

The HTLC has CLTV expiry. As the payment travels:

This ordering ensures:

Standard cltv_expiry_delta: 40-100 blocks per hop typically.

HTLC scripts on chain (post force-close)

For an HTLC the channel partner offered to you:

hash160(payment_hash) OP_EQUALVERIFY <local_htlc_pk> OP_CHECKSIG
  OR
<cltv> OP_CHECKLOCKTIMEVERIFY OP_DROP <remote_htlc_pk> OP_CHECKSIG
  OR
<revocation_pubkey> OP_CHECKSIG

Three paths: success (preimage), timeout (CLTV), revocation (cheating

detection).

2nd-stage HTLC txs

After force-close, HTLC outputs aren't directly spendable — they go

through pre-signed 2nd-stage txs:

is to_local-style with CSV delay before claimable by you.

output.

This 2-stage structure is required for legacy commitment because

sigs are pre-committed at channel open (no flexibility post-broadcast).

Anchor zero-fee variant

option_anchors_zero_fee_htlc_tx: HTLC 2nd-stage txs are 0-fee at

sign time, fee-bumped via the commitment's anchors when broadcast.

PTLCs (Point Time-Locked Contracts)

Modern Schnorr/Taproot-based replacement for HTLCs:

conditional on revealing the secret.

observers can't correlate hops by hash value.

Status: BOLT update in flight; implementations partial.

In-flight HTLC limits

Channel-level limits (advertised in accept_channel):

Excess HTLCs cause update_add_htlc to fail.

"Stuck" HTLCs

Causes:

Recovery:

channel, recover via 2nd-stage timeout tx.

Replacement cycling impact

HTLC-timeout txs are pre-signed at channel open. An attacker could

historically "pin" these via low-fee descendants → honest party can't

broadcast → CLTV passes upstream → loss.

Post TRUC v3 + ephemeral anchors: pinning surface removed.

Common bugs

resolves → forced refund and lost fees.

parties try to claim, possible loss.

reject HTLCs.

See also

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.