<oembed><type>rich</type><version>1.0</version><author_name>npub1zlxd3xlzjhq2ue03e5m5p2w6mp8v3dkhq5r39flsftjjsje04wvsdd2k4w</author_name><author_url>https://nostr.ae/npub1zlxd3xlzjhq2ue03e5m5p2w6mp8v3dkhq5r39flsftjjsje04wvsdd2k4w</author_url><provider_name>njump</provider_name><provider_url>https://nostr.ae</provider_url><html>📅 Original date posted:2020-06-17&#xA;📝 Original message:&#xA;Hey everyone and of course good morning ZmnSCPxj (:&#xA;&#xA;about 11 months ago I discovered a potential blackmail attack with HTLCs&#xA;after answering this question on stack exchange (c.f&#xA;https://bitcoin.stackexchange.com/questions/89232/why-is-my-spendable-msat-much-lower-than-msatoshi-to-us/89235#89235).&#xA;This attack is similar to the one that was possible with tx malleability on&#xA;the funding transaction without the segwit upgrade (c.f.&#xA;https://commons.wikimedia.org/w/index.php?title=File:Introduction_to_the_Lightning_Network_Protocol_and_the_Basics_of_Lightning_Technology_(BOLT_aka_Lightning-rfc).pdf&amp;page=126).&#xA;Meaning an attacker can force a victim to lose money and use this fact to&#xA;blackmail the victim, to potentially gain / steal some of the lost funds.&#xA;&#xA;TL;DR:&#xA;=====&#xA;* Depending on the circumstances this attack allows an attacker to make&#xA;channel partners lose a substantial amount of BTC without substantial costs&#xA;for the attacker.&#xA;* Depending on the exact circumstances this could be for example ~0.15 BTC.&#xA;In particular it demonstrates why opening a channel is not an entirely&#xA;trustless activity.&#xA;* The attacker will reliably only be able to force the victim to lose this&#xA;amount of Bitcoin.&#xA;* It is not clear how in practice the attacker could gain this amount or&#xA;parts of it as this would involve not only game theory but also rather&#xA;quick communication between attacker and victim and customized Lightning&#xA;nodes which at least for the victim would be unlikely to exist.&#xA;* None of the suggested fixes seems to be satisfying though the current&#xA;solution of lowering the maximum amount of HTLCs that can concurrently be&#xA;in flight seems to be a reasonable start for now.&#xA;&#xA;&#xA;Timeline on Disclosure&#xA;=================&#xA;I have disclosed this attack on Sunday July 21st 2019 to Fabrice Drouin&#xA;(and shortly after to Christian Decker) in a phone call who in turn has&#xA;discussed it with people from the other implementations. From his feedback&#xA;I understood that people working on implementations have been more or less&#xA;aware of the possibility of this attack. Fabrice also mentioned that he&#xA;believed implementations currently try to mitigate this by setting low&#xA;limits of allowed / accepted HTLCs in flight. However at that time this was&#xA;only true for e-clair. It is now also true for c-lightning and as far as I&#xA;know still not true for lnd. Fabrice said that the people he talked to have&#xA;suggested that I should eventually describe the attack in public to raise&#xA;awareness (also from the group of node operators) for the problems related&#xA;to this attack. He also suggested that - if I wanted to - I should update&#xA;the rfc with recommendations  and warnings. While I already have in mind&#xA;how to change the rfc I wanted to start the discussion first. Maybe some&#xA;people find better fixes than just a warning that I have in mind. So far I&#xA;didn&#39;t do anything because I wanted to also give lnd the chance to handle&#xA;the problem.&#xA;&#xA;There are two reasons I disclose this attack today:&#xA;1.) I think almost 1 year is enough time to do something about it. The only&#xA;implementation that afaik didn&#39;t yet is lnd (see below) but I got roasbeefs&#xA;ok last week to go ahead and publish the attack anyway so that we can have&#xA;a broader discussion on mitigation strategies.&#xA;2.) The attack seems actually very similar to the one described in the&#xA;&#34;Flood &amp; Loot: A Systemic Attack On The Lightning Network&#34; - paper which&#xA;came out 2 days ago (c.f.: https://arxiv.org/abs/2006.08513 ). I believe&#xA;any person reading that paper will understand the possibility of the attack&#xA;that I describe anyway so I believe it is now more or less public anyway&#xA;and thus time for an open / public discussion.&#xA;&#xA;The main difference between the two attacks (if I understand this novel&#xA;paper correctly) is: In the &#34;flood and loot&#34;-attack one tries to steal the&#xA;HTLC output of the victims. Where in the &#34;flood and blackmail&#34;-attack that&#xA;I describe I try to to force the victim to lose almost all its funds due to&#xA;high on chain fees (Which I could use to blackmail the victim)&#xA;&#xA;Description of the attack&#xA;===================&#xA;Let us assume the victim has funded a channel with an attacker meaning it&#xA;will have to pay the fees for the commitment transaction in case of a force&#xA;close.&#xA;&#xA;During a fee spike (let us assume fee estimators suggest 150 sat / byte)&#xA;the attacker spams this channel with the maximum possible amount of HTLCs&#xA;that the protocol allows. The HTLCs can be of a small value but need to be&#xA;bigger than the dust limit so that additional outputs are actually added to&#xA;the commitment transaction which makes it quite large in Bytes. According&#xA;to the BOLTs these are 483 additional outputs to the commitment&#xA;transaction.&#xA;The direction of HTLCs are chosen so that the amount is taken from the&#xA;`to_remote` output of the attacker (obviously on the victims side it will&#xA;be the `to_local` output) For the actual attack it does not matter in which&#xA;direction the HTLCs are spammed but economically the direction I propose&#xA;makes even more sense for the attacker and can be achieved with circular&#xA;onions.&#xA;&#xA;The attacked channel partner will happily - according to the protocol - use&#xA;a higher fee than the current fee rate. I quote from BOLT 02 which suggests&#xA;a buffer of a factor of 5&#xA;https://github.com/lightningnetwork/lightning-rfc/blob/master/02-peer-protocol.md#updating-fees-update_fee:&#xA;&#xA;&#xA;&gt; The node responsible for paying the Bitcoin fee [...] SHOULD send&#xA;update_fee to ensure the current fee rate is sufficient (by a significant&#xA;margin) for timely processing of the commitment transaction. [...] Given&#xA;the variance in fees, and the fact that the transaction may be spent in the&#xA;future, it&#39;s a good idea for the fee payer to keep a good margin (say 5x&#xA;the expected fee requirement); but, due to differing methods of fee&#xA;estimation, an exact value is not specified.&#xA;&#xA;This overpayment of fees will result in 750 sat / byte for this fee spike&#xA;scenario. This is by the way not completely unrealistic [I recently opened&#xA;a channel with 2.56 sat / byte (c.f.:&#xA;https://www.smartbit.com.au/tx/c0ac6cfe15e0d0c921362ab9fad998a8a8e16cd8d9d4159487dd69141ea2b9b0)&#xA;and the channel was force closed a couple minutes later due to an&#xA;implementation bug resulting in fees of 101.17 sat / byte (c.f.:&#xA;https://www.smartbit.com.au/tx/e32135315ec147bb27f771b2e15c7178ea573afd16cd4970bf814c9b18bc46e3&#xA;)&#xA;&#xA;As far as I understand the appendix of BOLT 03 offered HTLCs are 43 Byte in&#xA;size (c.f.:&#xA;https://github.com/lightningnetwork/lightning-rfc/blob/master/03-transactions.md#appendix-a-expected-weights)&#xA;resulting in the following additional fees for the spammed commitment&#xA;transaction:&#xA;&#xA;fee (for 483 htlcs)  = 483 * 43 byte * 750 sat / byte = 15576750 sat =&#xA;0.1557675 BTC&#xA;&#xA;Additionally the victim will also have to swipe all offered HTLCs (which&#xA;will be additional costs but could be done once the fees came down) so we&#xA;neglect them.&#xA;&#xA;Once all HTLCs are set up the attacker will stop signing commitment&#xA;transactions. In the beginning this is not suspicious as the HTLCs will&#xA;take some time to settle anyway. But also when fees go down and the victim&#xA;who funded the channel wants to update the fees the attacker will just not&#xA;be responsive. Eventually the victim will dare to force close the channel&#xA;with all those expensive HTLCs.&#xA;&#xA;Knowing that this will happen and that the victim has to spend those funds&#xA;(publishing old state obviously does not work!) the attacker has a time&#xA;window to blackmail the victim outside of the lightning network protocol:&#xA;&#34;Either you will pay those 0.1557675 BTC of fees or we will collaboratively&#xA;close the channel but that will cost you part of the amount you lost.&#34; Game&#xA;theory suggests that the attacker will be able to claim the major fraction&#xA;of the BTC (c.f. https://en.wikipedia.org/wiki/Ultimatum_game that are&#xA;frozen in tx fees as the victim effectively already has lost that money and&#xA;can only gain something back.&#xA;&#xA;&#xA;Thoughts&#xA;=======&#xA;You might say that the blackmail part of this attack is unrealistic as the&#xA;blackmailing person will not have enough time to successfully do the&#xA;blackmail as the channel that is not operational will fail.&#xA;&#xA;1.) The only thing that lightning nodes might do is a fee update as the&#xA;htlcs stuffed the channel so I believe there is actually some time to&#xA;contact the victim.&#xA;2.) What if the attacker is a mining pool who is just interested in high&#xA;fees who does not even need to do the blackmailing stuff but will just&#xA;force close the channel once the htlcs are set up?&#xA;3.) The attacker might not even be interested in blackmailing the victim.&#xA;The attacker could just be interested in harming the victim. Though it&#xA;might certainly be a challenge to target a specific victim and trick it&#xA;into opening a channel with an attacker.&#xA;&#xA;Also you might say that an attacker needs many incoming channels to execute&#xA;this attack. This can be achieved by gaming the autopilot. an attacker can&#xA;start by creating many channels making him a highly likely channel partner&#xA;for autopilot users (who will also fund the channel). Such a highly&#xA;connected node might also be interesting for non autopilot users.&#xA;&#xA;Implementations&#xA;============&#xA;&#xA;I looked at the code myself. I hope I do oversee things but to me it looks&#xA;like only eclaire was somehow mitigating this attack from being exploited.&#xA;(by a default config of 30 accepted htlcs which will protect the average&#xA;user and is much lower than the 483) and c-lightning has merged a patch&#xA;from me which I provided after I disclosed the attack:&#xA;&#xA;## clightning:&#xA;&#xA;c-lightning did not by default set a hard cap on htlcs before version 0.7.2&#xA;but then merged my patch&#xA;https://github.com/ElementsProject/lightning/pull/2858 which tried to&#xA;resemble the eclair defaults&#xA;&#xA;## eclaire:&#xA;&#xA;the max accepted htlc value per channel is set as a constant to 483 which&#xA;follows the recommendation of the BOLTs:&#xA;https://github.com/ACINQ/eclair/blob/e62adf2deae213d2cd0f2a6874227dcfc57880ae/eclair-core/src/main/scala/fr/acinq/eclair/channel/Channel.scala#L52&#xA;&#xA;The value is tested against at:&#xA;https://github.com/ACINQ/eclair/blob/f724efaa76b256048de18f706e9cb58ecbebd6aa/eclair-core/src/main/scala/fr/acinq/eclair/channel/Helpers.scala#L99&#xA;&#xA;and:&#xA;https://github.com/ACINQ/eclair/blob/f724efaa76b256048de18f706e9cb58ecbebd6aa/eclair-core/src/main/scala/fr/acinq/eclair/channel/Helpers.scala#L132&#xA;&#xA;and:&#xA;https://github.com/ACINQ/eclair/blob/93d9369f900766171f2ddf579e8b12e28d8f0d25/eclair-core/src/main/scala/fr/acinq/eclair/channel/Commitments.scala#L154&#xA;&#xA;However the default config file specifies a maximum amount of 30 accepted&#xA;htlcs at:&#xA;https://github.com/ACINQ/eclair/blob/9afb26e09c69dd5d6a14732baf5dcdf2b7a9142b/eclair-core/src/main/resources/reference.conf#L62&#xA;&#xA;&#xA;## lnd&#xA;It seems like lnd did not and last time I checked (maybe I oversaw&#xA;something) does not set a hard cap on htlcs by default. The way how I&#xA;understand the code they allow up to 483 htlcs by default:&#xA;&#xA;The test when adding an htlc if it is beyond the maximum accepted values is&#xA;here:&#xA;https://github.com/lightningnetwork/lnd/blob/970d7604071baae227db42d4665ef9d1b56988e8/lnwallet/channel.go#L3795&#xA;&#xA;the default configuration seems to be here (and in the most recent commit&#xA;the line still exists):&#xA;https://github.com/lightningnetwork/lnd/blob/8b04cfbf12f460853e8c55611cd1bba21b1510ef/input/size.go#L187&#xA;&#xA;the software will accept up to 483 htlcs according to this line:&#xA;https://github.com/lightningnetwork/lnd/blob/111cbeaa990cba78563d6cc8c19b152e2d3042f6/lnwallet/reservation.go#L314&#xA;&#xA;I could not find any spec lower than that in the suggested sample config&#xA;at:&#xA;https://github.com/lightningnetwork/lnd/blob/master/sample-lnd.conf&#xA;&#xA;&#xA;Ideas for Fixes&#xA;===========&#xA;&#xA;I am completely unhappy with each of the following ideas. I hope you will&#xA;come up with smarter solutions. I believe the solution is not obvious. Thus&#xA;I thought it makes sense in the brainstorm phase to even post some ideas&#xA;with obvious drawbacks.&#xA;&#xA;1. The current solution is to just not use up the max value of&#xA;htlc&#39;s. Eclaire and c-lightning by default only use up to 30 htlcs.&#xA;2. Probably the best fix (not sure if I understand the consequences&#xA;correctly) is coming from this PR to bitcoin core (c.f.&#xA;https://github.com/bitcoin/bitcoin/pull/15681 by @TheBlueMatt . If I get it&#xA;correctly with that we could always have low fees and ask the person who&#xA;want to claim their outputs to pay fees. This excludes overpayment and&#xA;could happen at a later stage when fees are not spiked. Still the victim&#xA;who offered the htlcs would have to spend those outputs at some time.&#xA;3. Don&#39;t overpay fees in commitment transactions. We can&#39;t foresee the&#xA;future anyway&#xA;4. Don&#39;t add htlcs for which the on chain fee is higher than the HTLCs&#xA;value (like we do with sub dust amounts and sub satoshi amounts. This would&#xA;at least make the attack expensive as the attacker would have to bind a lot&#xA;of liquidity.&#xA;5. Somehow be able to aggregate htlc&#39;s. In a world where we use payment&#xA;points instead of preimages we might be able to do so. It would be really&#xA;cool if separate HTLC&#39;s could be combined to 1 single output. I played&#xA;around a little bit but I have not come up with a scheme that is more&#xA;compact in all cases. Thus I just threw in the idea.&#xA;6. Split onchain fees differently (now the attacker would also lose fees by&#xA;conducting this attack) - No I don&#39;t want to start yet another fee&#xA;bikeshadding debate. (In particular I believe that a different split of&#xA;fees might make the Flood &amp; Loot attack economically more viable which&#xA;relies on the same principle)&#xA;&#xA;Independently I think we should have a hint in our readme file about where&#xA;and how people can disclose attacks and vulnerabilities. Implementations&#xA;have this but the BOLTs do not.&#xA;&#xA;with kind regards Rene&#xA;&#xA;-- &#xA;&#xA;https://www.rene-pickhardt.de&#xA;&#xA;Skype: rene.pickhardt&#xA;-------------- next part --------------&#xA;An HTML attachment was scrubbed...&#xA;URL: &lt;http://lists.linuxfoundation.org/pipermail/lightning-dev/attachments/20200617/07158fbc/attachment-0001.html&gt;</html></oembed>