<oembed><type>rich</type><version>1.0</version><author_name>npub1vjzmc45k8dgujppapp2ue20h3l9apnsntgv4c0ukncvv549q64gsz4x8dd</author_name><author_url>https://nostr.ae/npub1vjzmc45k8dgujppapp2ue20h3l9apnsntgv4c0ukncvv549q64gsz4x8dd</author_url><provider_name>njump</provider_name><provider_url>https://nostr.ae</provider_url><html>📅 Original date posted:2021-10-04&#xA;📝 Original message:&#xA;Hi,&#xA;&#xA;I&#39;m writing a report to disclose specification-level vulnerabilities&#xA;affecting the Lightning implementations.&#xA;&#xA;The vulnerabilities are expected to be patched in:&#xA;* Eclair: v0.6.2+ (CVE-2021-41591)&#xA;* LND: v0.13.3+ (CVE-2021-41592)&#xA;* LDK: v0.0.102 (not released as production software yet)&#xA;&#xA;The vulnerabilities are also affecting c-lightning (CVE-2021-41593).&#xA;&#xA;Those vulnerabilities can be exploited in a wide range of attacks, going&#xA;from fee blackmailing of node operators, burning liquidity of your&#xA;competing LSPs or even stealing your counterparty channel balance if you&#xA;avail mining capabilities. Exercise of the vulnerability revealed that a&#xA;majority of the balance funds can be at loss.&#xA;&#xA;Credit to Eugene Siegel (Crypt-iQ) for reporting the trimmed-to-dust&#xA;exploitation and multiple insights about attacks.&#xA;&#xA;Thanks to Bastien Teinturier and Matt Corallo for numerous contributions&#xA;about mitigations development.&#xA;&#xA;# Problem&#xA;&#xA;The current BOLT specification only requires Alice&#39;s `dust_limit_satoshis`&#xA;(applied on Alice&#39;s commitment) to be under Alice&#39;s&#xA;`channel_reserve_satoshis` (applied on Bob). As those 2 parameters are&#xA;selectable by Alice, she can inflate the dust limit until reaching the&#xA;implementation-defined max value (e.g LND: 20% of chan capacity, LDK: 100%&#xA;of chan capacity).&#xA;&#xA;Any in-flight incoming HTLC under Alice&#39;s dust limit will be converted as&#xA;miner fees on Alice&#39;s commitment. This HTLC is deducted from Bob&#39;s balance&#xA;and as such they&#39;re still owned by Bob, until resolution (i.e a RAA&#xA;removing the HTLC from Alice&#39;s commitment). This limitation only applies&#xA;per-HTLC. No implementation enforces a limit on the sum of in-flight HTLCs&#xA;burned as fees. Therefore, Alice is free to inflict a substantial loss to&#xA;Bob funds by publishing her commitment on-chain.&#xA;&#xA;In-flight outgoing HTLC are also committed as fees on Bob&#39;s commitment if&#xA;they&#39;re under Bob&#39;s threshold. Alice can also exploit from this angle by&#xA;circular routing HTLCs until reaching Bob&#39;s&#xA;`max_htlc_value_in_flight_msat`. Alice withholds HTLCs resolution until Bob&#xA;goes on-chain to timeout an offered HTLC or claim an accepted HTLC.&#xA;&#xA;Dust HTLC processing can be also exploited at `update_fee` reception.&#xA;&#xA;As the BOLT3&#39;s fees computation encompasses the negotiated feerate from&#xA;`update_fee` for the 2nd-stage HTLC fees to decide if the HTLC must be&#xA;trimmed, the amount of balance at risk is a function of current mempool&#xA;feerates.&#xA;&#xA;The maximum of funds at risk on a counterparty commitment is:&#xA;&#xA;counterparty&#39;s `max_accepted_htlcs` * (`htlc_success_tx_kw` * opener&#39;s&#xA;`feerate_per_kw` + counterparty&#39;s `dust_limit_satoshis`) + holder&#39;s&#xA;`max_accepted_htlcs` * (`htlc_timeout_tx_kw` * opener&#39;s `feerate_per_kw` +&#xA;counterparty&#39;s `dust_limit_satoshis`)&#xA;&#xA;If the opener is also the attacker, the negotiated feerate can be&#xA;manipulated beyond the &#34;honest&#34; mempool feerates only upper bounded&#xA;implementation-defined value (before fixes, LDK: 2 * high-feerate of our&#xA;fee-estimator). If the opener is the victim, the negotiated feerate is&#xA;still a safety concern in case of spontaneous mempool spikes.&#xA;&#xA;Note, `anchors_zero_htlc_fee` channels are not affected by the feerate&#xA;inflation as the trimmed-to-dust fee computation mechanism for 2nd-stage&#xA;HTLC is removed. They&#39;re still at risk of the sum of the HTLCs under the&#xA;dust limit being maliciously burned.&#xA;&#xA;# Solution&#xA;&#xA;A first mitigation is to verify the counterparty&#39;s announced&#xA;`dust_limit_satoshis` at channel opening (`open_channel`/`accept_channel`)&#xA;reception and reject if it&#39;s estimated too large (see #894)&#xA;&#xA;For LDK, we choose the value of 660 satoshis as it&#39;s beyond the highest&#xA;dust threshold enforced by Bitcoin Core (p2pkh: 546) with a margin of&#xA;safety. Propagation of Lightning time-sensitive transactions shouldn&#39;t be&#xA;affected.&#xA;&#xA;A second mitigation is to define a new configurable limit&#xA;`max_dust_htlc_exposure` and apply this one at incoming and outgoing of&#xA;HTLC.&#xA;&#xA;For LDK, we choose the value of 5 000 000 milli-satoshis as we gauged this&#xA;value as a substantial loss for our class of users. Setting this too low&#xA;may prevent the sending or receipt of low-value HTLCs on high-traffic&#xA;nodes. A node operator should fine-tune this value in function of what&#xA;qualifies as an acceptable loss.&#xA;&#xA;We would like to ensure that the node isn&#39;t suddenly exposed to&#xA;significantly more trimmed balance if the feerate increases when we have&#xA;several HTLCs pending which are near the dust limit.&#xA;&#xA;To achieve this goal, we introduce a new `dust_buffer_feerate` defined as&#xA;the maximum of either 2530 sats per kWU or 125% of the current&#xA;`feerate_per_kw` (implementation-defined values).&#xA;&#xA;Then, upon an incoming HTLC, if the HTLC&#39;s `amount_msat` is inferior to the&#xA;counterparty&#39;s `dust_limit_satoshis` plus the HTLC-timeout fee at the&#xA;`dust_buffer_feerate`. If the `amount_msat` plus the&#xA;`dust_balance_on_counterparty_tx` is superior to `max_dust_htlc_exposure`,&#xA;the HTLC should be failed once it&#39;s committed.&#xA;&#xA;Upon an outgoing HTLC, if the HTLC&#39;s `amount_msat` is inferior to the&#xA;counterparty&#39;s `dust_limit_satoshis`  plus the HTLC-success fee at the&#xA;`dust_buffer_feerate`. If the `amount_msat` plus the&#xA;`dust_balance_on_counterparty_tx` is superior to `max_dust_htlc_exposure`,&#xA;the HTLC should not be sent and fail without forwarding.&#xA;&#xA;The check symmetry must also be applied on holder commitment transactions.&#xA;See PR #919 for more details.&#xA;&#xA;A last mitigation is ensuring that at `update_fee` reception, the pending&#xA;`dust_balance` at the new proposed feerate isn&#39;t superior to&#xA;`max_dust_htlc_exposure_msat`.&#xA;&#xA;# Background&#xA;&#xA;The dust limit is a base layer policy stopping the relay of a transaction&#xA;if one of its outputs is under a given threshold. The goal of this policy&#xA;is to prevent the pollution of the UTXO set with low-value outputs and as&#xA;such increase the amount of work done by full-nodes.&#xA;&#xA;Lightning commitment transactions should be able to propagate at any point&#xA;during the channel lifetime to unilaterally enforce on-chain a balance. A&#xA;Lightning commitment transaction with one of its outputs below the dust&#xA;limit would fail to relay and thus jeopardizes funds safety.&#xA;&#xA;To prevent this, BOLT2 requires counterparties to announce a&#xA;`dust_limit_satoshis` during channel opening (at&#xA;`open_channel`/`accept_channel` exchange). This `dust_limit_satoshis` must&#xA;be under the same party&#39;s `channel_reserve_satoshis`. This value is static&#xA;for the channel lifetime.&#xA;&#xA;During commitment signatures exchange, each counterparty&#39;s limit is applied&#xA;on each counterparty&#39;s commitment (e.g A&#39;s `dust_limit_satoshis` is applied&#xA;on A&#39;s commitment, though both A and B have to generate and sign the&#xA;transaction). An output below this limit is trimmed to fees and won&#39;t&#xA;materialize on the commitment.&#xA;&#xA;The specification didn&#39;t require that the `open_channel`/`accept_channel`&#xA;receiver verify that the announced `dust_limit_satoshis` isn&#39;t too large.&#xA;&#xA;The specification didn&#39;t require that the sum of the dust HTLC committed as&#xA;fees was verified against an upper bound.&#xA;&#xA;# Discovery&#xA;&#xA;Vulnerabilities around our dust HTLC processing have been known for years&#xA;by some LN developers/researchers.&#xA;&#xA;During Q1 2019, private discussions on the Rust-Lightning-side (LDK before&#xA;marketing rebranding) about potential safety risks around dust HTLC&#xA;processing.&#xA;&#xA;In November 2019, Rusty Russell (c-lightning) opened an issue against the&#xA;specification mentioning the lack of check of counterparty&#39;s dust limit&#xA;(#696).&#xA;&#xA;In May 2020, I published a high-level attack scenario &#34;Miners Dust&#xA;Inflation attacks on Lightning Network&#34;, leveraging this lack.&#xA;&#xA;In February 2021, I did a test of the first vulnerability against LND&#xA;software and successfully burnt the majority of the targeted node balance&#xA;in fees. As it sounds to me like a check missing in the specification, I&#xA;notified CL/LND/Eclair/LDK maintainers. Mitigations started to be developed&#xA;on the LDK-side.&#xA;&#xA;In July 2021, in the context of `option_dusty_htlcs_uncounted` discussions,&#xA;Eugene Spiegel (LND) reported on how to exploit the trimmed-to-dust&#xA;mechanism at `update_fee` reception. Discussions followed on the best way&#xA;to mitigate this new vector.&#xA;&#xA;During August 2021, mitigations were developed and released on the&#xA;LDK-side. vulnerabilities were disclosed to other Lightning projects (Muun&#xA;wallet, Electrum). From the LDK-side, a public disclosure date was proposed.&#xA;&#xA;Still during August 2021, the Bitcoin Core dust limit was actively&#xA;discussed on the mailing list. Changes of this dust limit would have&#xA;affected the ongoing development of the mitigations.&#xA;&#xA;While this report highlights the lack of well-defined communication process&#xA;across Lightning teams,  developers from 3 different implementations have&#xA;actively participated in the vulnerabilities diagnostic and mitigations&#xA;development of those long-standing specification issues affecting the whole&#xA;Lightning ecosystem.&#xA;&#xA;All mistakes and opinions are my own and please verify any information&#xA;reported.&#xA;&#xA;# Timeline&#xA;&#xA;* 2021-04-19: Working exploit of the vulnerability against LND,&#xA;CL/LND/Eclair/LDK maintainers notified&#xA;* 2021-07-21: Finding by Eugene Siegel on how to exploit the&#xA;trimmed-to-dust mechanism at `update_fee` reception&#xA;* 2021-08-11: BOLT PR #894 opened by Bastien Teinturier, covering the lack&#xA;of verification of counterparty per-HTLC `dust_limit_satoshis`&#xA;* 2021-08-16: Mitigations developed in LDK, communication of a public&#xA;disclosure date&#xA;* 2021-08-26: Notification to Muun wallet, non-affected&#xA;* 2021-08-27: Notification to Electrum wallet&#xA;* 2021-10-04: Full Disclosure of CVEs&#xA;* 2021-10-04: Submit BOLT PR #919 covering the remaining vulnerabilities&#xA;-------------- next part --------------&#xA;An HTML attachment was scrubbed...&#xA;URL: &lt;http://lists.linuxfoundation.org/pipermail/lightning-dev/attachments/20211004/9af032f2/attachment.html&gt;</html></oembed>