<oembed><type>rich</type><version>1.0</version><title>Antoine Riard [ARCHIVE] wrote</title><author_name>Antoine Riard [ARCHIVE] (npub1vj…4x8dd)</author_name><author_url>https://yabu.me/npub1vjzmc45k8dgujppapp2ue20h3l9apnsntgv4c0ukncvv549q64gsz4x8dd</author_url><provider_name>njump</provider_name><provider_url>https://yabu.me</provider_url><html>📅 Original date posted:2023-10-16&#xA;🗒️ Summary of this message: Cross-posting mempool issues have exposed lightning channels to the risk of loss of funds, potentially affecting other multi-party bitcoin applications. Mitigations have been implemented, but their effectiveness against advanced replacement cycling attacks is still uncertain.&#xA;📝 Original message:&#xA;(cross-posting mempool issues identified are exposing lightning chan to&#xA;loss of funds risks, other multi-party bitcoin apps might be affected)&#xA;&#xA;Hi,&#xA;&#xA;End of last year (December 2022), amid technical discussions on eltoo&#xA;payment channels and incentives compatibility of the mempool anti-DoS&#xA;rules, a new transaction-relay jamming attack affecting lightning channels&#xA;was discovered.&#xA;&#xA;After careful analysis, it turns out this attack is practical and&#xA;immediately exposed lightning routing hops carrying HTLC traffic to loss of&#xA;funds security risks, both legacy and anchor output channels. A potential&#xA;exploitation plausibly happening even without network mempools congestion.&#xA;&#xA;Mitigations have been designed, implemented and deployed by all major&#xA;lightning implementations during the last months.&#xA;&#xA;Please find attached the release numbers, where the mitigations should be&#xA;present:&#xA;- LDK: v0.0.118 - CVE-2023 -40231&#xA;- Eclair: v0.9.0 - CVE-2023-40232&#xA;- LND: v.0.17.0-beta - CVE-2023-40233&#xA;- Core-Lightning: v.23.08.01 - CVE-2023-40234&#xA;&#xA;While neither replacement cycling attacks have been observed or reported in&#xA;the wild since the last ~10 months or experimented in real-world conditions&#xA;on bitcoin mainet, functional test is available exercising the affected&#xA;lightning channel against bitcoin core mempool (26.0 release cycle).&#xA;&#xA;It is understood that a simple replacement cycling attack does not demand&#xA;privileged capabilities from an attacker (e.g no low-hashrate power) and&#xA;only access to basic bitcoin and lightning software. Yet I still think&#xA;executing such an attack successfully requests a fair amount of bitcoin&#xA;technical know-how and decent preparation.&#xA;&#xA;&gt;From my understanding of those issues, it is yet to be determined if the&#xA;mitigations deployed are robust enough in face of advanced replacement&#xA;cycling attackers, especially ones able to combine different classes of&#xA;transaction-relay jamming such as pinnings or vetted with more privileged&#xA;capabilities.&#xA;&#xA;Please find a list of potential affected bitcoin applications in this full&#xA;disclosure report using bitcoin script timelocks or multi-party&#xA;transactions, albeit no immediate security risk exposure as severe as the&#xA;ones affecting lightning has been identified. Only cursory review of&#xA;non-lightning applications has been conducted so far.&#xA;&#xA;There is a paper published summarizing replacement cycling attacks on the&#xA;lightning network:&#xA;https://github.com/ariard/mempool-research/blob/2023-10-replacement-paper/replacement-cycling.pdf&#xA;&#xA; ## Problem&#xA;&#xA;A lightning node allows HTLCs forwarding (in bolt3&#39;s parlance accepted HTLC&#xA;on incoming link and offered HTLC on outgoing link) should settle the&#xA;outgoing state with either a success or timeout before the incoming state&#xA;timelock becomes final and an asymmetric defavorable settlement might&#xA;happen (cf &#34;Flood &amp; Loot: A Systematic Attack on The Lightning Network&#34;&#xA;section 2.3 for a classical exposition of this lightning security property).&#xA;&#xA;Failure to satisfy this settlement requirement exposes a forwarding hop to&#xA;a loss of fund risk where the offered HTLC is spent by the outgoing link&#xA;counterparty&#39;s HTLC-preimage and the accepted HTLC is spent by the incoming&#xA;link counterparty&#39;s HTLC-timeout.&#xA;&#xA;The specification mandates the incoming HTLC expiration timelock to be&#xA;spaced out by an interval of `cltv_expiry_delta` from the outgoing HTLC&#xA;expiration timelock, this exact interval value being an implementation and&#xA;node policy setting. As a minimal value, the specification recommends 34&#xA;blocks of interval. If the timelock expiration I of the inbound HTLC is&#xA;equal to 100 from chain tip, the timelock expiration O of the outbound HTLC&#xA;must be equal to 66 blocks from chain tip, giving a reasonable buffer of&#xA;reaction to the lightning forwarding node.&#xA;&#xA;In the lack of cooperative off-chain settlement of the HTLC on the outgoing&#xA;link negotiated with the counterparty (either `update_fulfill_htlc` or&#xA;`update_fail_htlc`) when O is reached, the lightning node should broadcast&#xA;its commitment transaction. Once the commitment is confirmed (if anchor and&#xA;the 1 CSV encumbrance is present), the lightning node broadcasts and&#xA;confirms its HTLC-timeout before I height is reached.&#xA;&#xA;Here enter a replacement cycling attack. A malicious channel counterparty&#xA;can broadcast its HTLC-preimage transaction with a higher absolute fee and&#xA;higher feerate than the honest HTLC-timeout of the victim lightning node&#xA;and triggers a replacement. Both for legacy and anchor output channels, a&#xA;HTLC-preimage on a counterparty commitment transaction is malleable, i.e&#xA;additional inputs or outputs can be added. The HTLC-preimage spends an&#xA;unconfirmed and unrelated to the channel parent transaction M and conflicts&#xA;its child.&#xA;&#xA;As the HTLC-preimage spends an unconfirmed input that was already included&#xA;in the unconfirmed and unrelated child transaction (rule 2), pays an&#xA;absolute higher fee of at least the sum paid by the HTLC-timeout and child&#xA;transaction (rule 3) and the HTLC-preimage feerate is greater than all&#xA;directly conflicting transactions (rule 6), the replacement is accepted.&#xA;The honest HTLC-timeout is evicted out of the mempool.&#xA;&#xA;In an ulterior move, the malicious counterparty can replace the parent&#xA;transaction itself with another candidate N satisfying the replacement&#xA;rules, triggering the eviction of the malicious HTLC-preimage from the&#xA;mempool as it was a child of the parent T.&#xA;&#xA;There is no spending candidate of the offered HTLC output for the current&#xA;block laying in network mempools.&#xA;&#xA;This replacement cycling tricks can be repeated for each rebroadcast&#xA;attempt of the HTLC-timeout by the honest lightning node until expiration&#xA;of the inbound HTLC timelock I. Once this height is reached a HTLC-timeout&#xA;is broadcast by the counterparty&#39;s on the incoming link in collusion with&#xA;the one on the outgoing link broadcasting its own HTLC-preimage.&#xA;&#xA;The honest Lightning node has been &#34;double-spent&#34; in its HTLC forwarding.&#xA;&#xA;As a notable factor impacting the success of the attack, a lightning node&#39;s&#xA;honest HTLC-timeout might be included in the block template of the miner&#xA;winning the block race and therefore realizes a spent of the offered&#xA;output. In practice, a replacement cycling attack might over-connect to&#xA;miners&#39; mempools and public reachable nodes to succeed in a fast eviction&#xA;of the HTLC-timeout by its HTLC-preimage. As this latter transaction can&#xA;come with a better ancestor-score, it should be picked up on the flight by&#xA;economically competitive miners.&#xA;&#xA;A functional test exercising a simple replacement cycling of a HTLC&#xA;transaction on bitcoin core mempool is available:&#xA;https://github.com/ariard/bitcoin/commits/2023-test-mempool&#xA;&#xA;## Deployed LN mitigations&#xA;&#xA;Aggressive rebroadcasting: As the replacement cycling attacker benefits&#xA;from the HTLC-timeout being usually broadcast by lightning nodes only once&#xA;every block, or less the replacement cycling malicious transactions paid&#xA;only equal the sum of the absolute fees paid by the HTLC, adjusted with the&#xA;replacement penalty. Rebroadcasting randomly and multiple times before the&#xA;next block increases the absolute fee cost for the attacker.&#xA;&#xA;Implemented and deployed by Eclair, Core-Lightning, LND and LDK .&#xA;&#xA;Local-mempool preimage monitoring: As the replacement cycling attacker in a&#xA;simple setup broadcast the HTLC-preimage to all the network mempools, the&#xA;honest lightning node is able to catch on the flight the unconfirmed&#xA;HTLC-preimage, before its subsequent mempool replacement. The preimage can&#xA;be extracted from the second-stage HTLC-preimage and used to fetch the&#xA;off-chain inbound HTLC with a cooperative message or go on-chain with it to&#xA;claim the accepted HTLC output.&#xA;&#xA;Implemented and deployed by Eclair and LND.&#xA;&#xA;CLTV Expiry Delta: With every jammed block comes an absolute fee cost paid&#xA;by the attacker, a risk of the HTLC-preimage being detected or discovered&#xA;by the honest lightning node, or the HTLC-timeout to slip in a winning&#xA;block template. Bumping the default CLTV delta hardens the odds of success&#xA;of a simple replacement cycling attack.&#xA;&#xA;Default setting: Eclair 144, Core-Lightning 34, LND 80 and LDK 72.&#xA;&#xA;## Affected Bitcoin Protocols and Applications&#xA;&#xA;&gt;From my understanding the following list of Bitcoin protocols and&#xA;applications could be affected by new denial-of-service vectors under some&#xA;level of network mempools congestion. Neither tests or advanced review of&#xA;specifications (when available) has been conducted for each of them:&#xA;- on-chain DLCs&#xA;- coinjoins&#xA;- payjoins&#xA;- wallets with time-sensitive paths&#xA;- peerswap and submarine swaps&#xA;- batch payouts&#xA;- transaction &#34;accelerators&#34;&#xA;&#xA;Inviting their developers, maintainers and operators to investigate how&#xA;replacement cycling attacks might disrupt their in-mempool chain of&#xA;transactions, or fee-bumping flows at the shortest delay. Simple flows and&#xA;non-multi-party transactions should not be affected to the best of my&#xA;understanding.&#xA;&#xA;## Open Problems: Package Malleability&#xA;&#xA;Pinning attacks have been known for years as a practical vector to&#xA;compromise lightning channels funds safety, under different scenarios (cf.&#xA;current bip331&#39;s motivation section). Mitigations at the mempool level have&#xA;been designed, discussed and are under implementation by the community&#xA;(ancestor package relay + nverrsion=3 policy). Ideally, they should&#xA;constraint a pinning attacker to always attach a high feerate package&#xA;(commitment + CPFP) to replace the honest package, or allow a honest&#xA;lightning node to overbid a malicious pinning package and get its&#xA;time-sensitive transaction optimistically included in the chain.&#xA;&#xA;Replacement cycling attack seem to offer a new way to neutralize the design&#xA;goals of package relay and its companion nversion=3 policy, where an&#xA;attacker package RBF a honest package out of the mempool to subsequently&#xA;double-spend its own high-fee child with a transaction unrelated to the&#xA;channel. As the remaining commitment transaction is pre-signed with a&#xA;minimal relay fee, it can be evicted out of the mempool.&#xA;&#xA;A functional test exercising a simple replacement cycling of a lightning&#xA;channel commitment transaction on top of the nversion=3 code branch is&#xA;available:&#xA;https://github.com/ariard/bitcoin/commits/2023-10-test-mempool-2&#xA;&#xA;## Discovery&#xA;&#xA;In 2018, the issue of static fees for pre-signed lightning transactions is&#xA;made more widely known, the carve-out exemption in mempool rules to&#xA;mitigate in-mempool package limits pinning and the anchor output pattern&#xA;are proposed.&#xA;&#xA;In 2019, bitcoin core 0.19 is released with carve-out support. Continued&#xA;discussion of the anchor output pattern as a dynamic fee-bumping method.&#xA;&#xA;In 2020, draft of anchor output submitted to the bolts. Initial finding of&#xA;economic pinning against lightning commitment and second-stage HTLC&#xA;transactions. Subsequent discussions of a preimage-overlay network or&#xA;package-relay as mitigations. Public call made to inquiry more on potential&#xA;other transaction-relay jamming attacks affecting lightning.&#xA;&#xA;In 2021, initial work in bitcoin core 22.0 of package acceptance. Continued&#xA;discussion of the pinning attacks and shortcomings of current mempool rules&#xA;during community-wide online workshops. Later the year, in light of all&#xA;issues for bitcoin second-layers, a proposal is made about killing the&#xA;mempool.&#xA;&#xA;In 2022, bip proposed for package relay and new proposed v3 policy design&#xA;proposed for a review and implementation. Mempoolfullrbf is supported in&#xA;bitcoin core 24.0 and conceptual questions about alignment of mempool rules&#xA;w.r.t miners incentives are investigated.&#xA;&#xA;Along this year 2022, eltoo lightning channels design are discussed,&#xA;implemented and reviewed. In this context and after discussions on mempool&#xA;anti-DoS rules, I discovered this new replacement cycling attack was&#xA;affecting deployed lightning channels and immediately reported the finding&#xA;to some bitcoin core developers and lightning maintainers.&#xA;&#xA;## Timeline&#xA;&#xA;- 2022-12-16: Report of the finding to Suhas Daftuar, Anthony Towns, Greg&#xA;Sanders and Gloria Zhao&#xA;- 2022-12-16: Report to LN maintainers: Rusty Russell, Bastien Teinturier,&#xA;Matt Corallo and Olaoluwa Osuntunkun&#xA;- 2022-12-23: Sharing to Eugene Siegel (LND)&#xA;- 2022-12-24: Sharing to James O&#39;Beirne and Antoine Poinsot (non-lightning&#xA;potential affected projects)&#xA;- 2022-01-14: Sharing to Gleb Naumenko (miners incentives and cross-layers&#xA;issuers) and initial proposal of an early public disclosure&#xA;- 2022-01-19: Collection of analysis if other second-layers and multi-party&#xA;applications affected. LN mitigations development starts.&#xA;- 2023-05-04: Sharing to Wilmer Paulino (LDK)&#xA;- 2023-06-20: LN mitigations implemented and progressively released. Week&#xA;of the 16 october proposed for full disclosure.&#xA;- 2023-08-10: CVEs assigned by MITRE&#xA;- 2023-10-05: Pre-disclosure of LN CVEs numbers and replacement cycling&#xA;attack existence to security at bitcoincore.org.&#xA;- 2023-10-16: Full disclosure of CVE-2023-40231 / CVE-2023-40232 /&#xA;CVE-2023-40233 / CVE-2023-40234 and replacement cycling attacks&#xA;&#xA;## Conclusion&#xA;&#xA;Despite the line of mitigations adopted and deployed by current major&#xA;lightning implementations, I believe replacement cycling attacks are still&#xA;practical for advanced attackers. Beyond this new attack might come as a&#xA;way to partially or completely defeat some of the pinning mitigations which&#xA;have been working for years as a community.&#xA;&#xA;As of today, it is uncertain to me if lightning is not affected by a more&#xA;severe long-term package malleability critical security issue under current&#xA;consensus rules, and if any other time-sensitive multi-party protocol,&#xA;designed or deployed isn&#39;t de facto affected too (loss of funds or denial&#xA;of service).&#xA;&#xA;Assuming analysis on package malleability is correct, it is unclear to me&#xA;if it can be corrected by changes in replacement / eviction rules or&#xA;mempool chain of transactions processing strategy. Inviting my technical&#xA;peers and the bitcoin community to look more on this issue, including to&#xA;dissent. I&#39;ll be the first one pleased if I&#39;m fundamentally wrong on those&#xA;issues, or if any element has not been weighted with the adequate technical&#xA;accuracy it deserves.&#xA;&#xA;Do not trust, verify. All mistakes and opinions are my own.&#xA;&#xA;Antoine&#xA;&#xA;&#34;meet with Triumph and Disaster. And treat those two impostors just the&#xA;same&#34; - K.&#xA;-------------- next part --------------&#xA;An HTML attachment was scrubbed...&#xA;URL: &lt;http://lists.linuxfoundation.org/pipermail/lightning-dev/attachments/20231016/6e4e649f/attachment-0001.html&gt;</html></oembed>