Replacement cycling

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

Replacement cycling is an AI agent skill from the GitHub repository claude-dev-suite/claude-dev-suite. Replacement cycling attack on Lightning (Riard 2023): exploits BIP125 rule 5 to indefinitely delay an honest HTLC-timeout, costing the victim. Mitigated by TRUC v3 + ephemeral anchors. USE WHEN: auditing LN security posture, evaluating fee-bumping strategies, understanding why TRUC was activated.

How to use this skill

Skill file

Replacement Cycling Attack

Disclosed by Antoine Riard, Oct 2023. A novel mempool-policy attack

against Lightning where an attacker repeatedly cycles RBF-replacing

their own malicious child tx, forcing your honest fee-bumping

attempts to incur progressively higher costs while their tx sits in

mempool, eventually causing your legitimate sweep tx (HTLC-timeout)

to miss its CLTV deadline.

The setup

You're routing a payment Alice → You → Bob:

If Bob force-closes and you can't claim his outgoing HTLC before

your incoming HTLC times out → you lose the payment forwarded to Bob

but still owe Alice.

The exploit

Attacker (Bob) attempts:

  1. Bob force-closes the channel; HTLC output appears on chain.
  2. You publish HTLC-timeout tx (pre-signed) to claim back the funds

after CLTV.

  1. Bob publishes a competing HTLC-success tx using a (potentially

recently learned) preimage, with lower fee → your tx and his tx

both spend the same output.

  1. You bump your tx via RBF.
  2. Bob bumps his tx slightly by replacing his own with a marginally

higher-fee version.

  1. By BIP125 rule 5, each replacement must pay extra per added vbyte.
  2. Bob repeats step 5, marginally bumping each time.
  3. Each Bob's bump is cheap; your bump becomes more expensive each

round (you must beat his absolute fee).

  1. Eventually you stop bumping (resource exhaustion), Bob's tx

confirms with the preimage. He's revealed it now to you, but

you've already paid Alice's HTLC (you trusted the chain to

resolve before).

The ATTACK COST to Bob is small (he keeps replacing his own tx with

incremental bumps); the COST TO YOU includes both the failed timeout

fees and the lost payment to Alice.

Why BIP125 enabled it

BIP125 rule 5: replacement tx must pay extra `incrementalrelayfee ×

size_increase` beyond the original. But this allows an attacker who

controls a competing tx to force you to keep bumping ahead of

them, while their own bumps are tiny.

Mitigation 1: TRUC v3 (BIP431)

v3 transactions limit:

This breaks the cycling pattern: attacker can't keep stacking

replacements with tiny bumps; sibling eviction lets honest party

replace cheaply.

Mitigation 2: Ephemeral anchors

Anchor with value=0 and trivially-spendable script. Must be spent

in the same package as parent. Eliminates pinning surface (anchor

isn't independently spendable).

Mitigation 3: Increase pre-signed fee buffer

Pre-sign HTLC-timeout txs with a generous fee. If mempool fee rates

spike beyond expectations, you have headroom.

Mitigation 4: Watchtower + witness monitoring

Watchtowers monitor not just for cheating commitments but also for

HTLC pinning attempts; can attempt punitive replacement.

Lightning impact

in the channels they create after BIP431 activation (Sept 2024).

closed and reopened.

Status

Common confusions

blocking your tx from confirming via large descendants). They

share the underlying BIP125 mechanic but exploit it differently.

protocol; it's a flaw in pre-TRUC mempool policy that Lightning

was relying on.

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.