<oembed><type>rich</type><version>1.0</version><author_name>npub19helcfnqgk2jrwzjex2aflq6jwfc8zd9uzzkwlgwhve7lykv23mq5zkvn4</author_name><author_url>https://nostr.ae/npub19helcfnqgk2jrwzjex2aflq6jwfc8zd9uzzkwlgwhve7lykv23mq5zkvn4</author_url><provider_name>njump</provider_name><provider_url>https://nostr.ae</provider_url><html>📅 Original date posted:2022-06-29&#xA;📝 Original message:&#xA;Hi t-bast,&#xA;&#xA;Happy to see this finally written up! With this, we have two classes of&#xA;proposals for rate limiting onion messaging:&#xA;&#xA;  1. Back propagation based rate limiting as described here.&#xA;&#xA;  2. Allowing nodes to express a per-message cost for their forwarding&#xA;  services, which is described here [1].&#xA;&#xA;I still need to digest everything proposed here, but personally I&#39;m more&#xA;optimistic about the 2nd category than the 1st.&#xA;&#xA;One issue I see w/ the first category is that a single party can flood the&#xA;network and cause nodes to trigger their rate limits, which then affects the&#xA;usability of the onion messages for all other well-behaving parties. An&#xA;example, this might mean I can&#39;t fetch invoices, give up after a period of&#xA;time (how long?), then result to a direct connection (perceived payment&#xA;latency accumulated along the way).&#xA;&#xA;With the 2nd route, if an attacker floods the network, they need to directly&#xA;pay for the forwarding usage themselves, though they may also directly cause&#xA;nodes to adjust their forwarding rate accordingly. However in this case, the&#xA;attacker has incurred a concrete cost, and even if the rates rise, then&#xA;those that really need the service (notifying an LSP that a user is online&#xA;or w/e) can continue to pay that new rate. In other words, by _pricing_ the&#xA;resource utilization, demand preferences can be exchanged, leading to more&#xA;efficient long term resource allocation.&#xA;&#xA;W.r.t this topic, one event that imo is worth pointing out is that a very&#xA;popular onion routing system, Tor, has been facing a severe DDoS attack that&#xA;has lasted weeks, and isn&#39;t yet fully resolved [2]. The on going flooding&#xA;attack on Tor has actually started to affect LN (iirc over half of all&#xA;public routing nodes w/ an advertised address are tor-only), and other&#xA;related systems like Umbrel that 100% rely on tor for networking traversal.&#xA;Funnily enough, Tor developers have actually suggested adding some PoW to&#xA;attempt to mitigate DDoS attacks [3]. In that same post they throw around&#xA;the idea of using anonymous tokens to allow nodes to give them to &#34;good&#34;&#xA;clients, which is pretty similar to my lofty Forwarding Pass idea as relates&#xA;to onion messaging, and also general HTLC jamming mitigation.&#xA;&#xA;In summary, we&#39;re not the first to attempt to tackle the problem of rate&#xA;limiting relayed message spam in an anonymous/pseudonymous network, and we&#xA;can probably learn a lot from what is and isn&#39;t working w.r.t how Tor&#xA;handles things. As you note near the end of your post, this might just be&#xA;the first avenue in a long line of research to best figure out how to handle&#xA;the spam concerns introduced by onion messaging. From my PoV, it still seems&#xA;to be an open question if the same network can be _both_ a reliable&#xA;micro-payment system _and_ also a reliable arbitrary message transport&#xA;layer. I guess only time will tell...&#xA;&#xA;&gt; The `shared_secret_hash` field contains a BIP 340 tagged hash&#xA;&#xA;Any reason to use the tagged hash here vs just a plain ol HMAC? Under the&#xA;hood, they have a pretty similar construction [4].&#xA;&#xA;[1]:&#xA;https://lists.linuxfoundation.org/pipermail/lightning-dev/2022-February/003498.html&#xA;[2]: https://status.torproject.org/issues/2022-06-09-network-ddos/&#xA;[3]: https://blog.torproject.org/stop-the-onion-denial/&#xA;[4]: https://datatracker.ietf.org/doc/html/rfc2104&#xA;&#xA;-- Laolu&#xA;&#xA;&#xA;&#xA;On Wed, Jun 29, 2022 at 1:28 AM Bastien TEINTURIER &lt;bastien at acinq.fr&gt; wrote:&#xA;&#xA;&gt; During the recent Oakland Dev Summit, some lightning engineers got together to discuss DoS&#xA;&gt; protection for onion messages. Rusty proposed a very simple rate-limiting scheme that&#xA;&gt; statistically propagates back to the correct sender, which we describe in details below.&#xA;&gt;&#xA;&gt; You can also read this in gist format if that works better for you [1].&#xA;&gt;&#xA;&gt; Nodes apply per-peer rate limits on _incoming_ onion messages that should be relayed (e.g.&#xA;&gt; N/seconds with some burst tolerance). It is recommended to allow more onion messages from&#xA;&gt; peers with whom you have channels, for example 10/seconds when you have a channel and 1/second&#xA;&gt; when you don&#39;t.&#xA;&gt;&#xA;&gt; When relaying an onion message, nodes keep track of where it came from (by using the `node_id` of&#xA;&gt; the peer who sent that message). Nodes only need the last such `node_id` per outgoing connection,&#xA;&gt; which ensures the memory footprint is very small. Also, this data doesn&#39;t need to be persisted.&#xA;&gt;&#xA;&gt; Let&#39;s walk through an example to illustrate this mechanism:&#xA;&gt;&#xA;&gt; * Bob receives an onion message from Alice that should be relayed to Carol&#xA;&gt; * After relaying that message, Bob stores Alice&#39;s `node_id` in its per-connection state with Carol&#xA;&gt; * Bob receives an onion message from Eve that should be relayed to Carol&#xA;&gt; * After relaying that message, Bob replaces Alice&#39;s `node_id` with Eve&#39;s `node_id` in its&#xA;&gt; per-connection state with Carol&#xA;&gt; * Bob receives an onion message from Alice that should be relayed to Dave&#xA;&gt; * After relaying that message, Bob stores Alice&#39;s `node_id` in its per-connection state with Dave&#xA;&gt; * ...&#xA;&gt;&#xA;&gt; We introduce a new message that will be sent when dropping an incoming onion message because it&#xA;&gt; reached rate limits:&#xA;&gt;&#xA;&gt; 1. type: 515 (`onion_message_drop`)&#xA;&gt; 2. data:&#xA;&gt;    * [`rate_limited`:`u8`]&#xA;&gt;    * [`shared_secret_hash`:`32*byte`]&#xA;&gt;&#xA;&gt; Whenever an incoming onion message reaches the rate limit, the receiver sends `onion_message_drop`&#xA;&gt; to the sender. The sender looks at its per-connection state to find where the message was coming&#xA;&gt; from and relays `onion_message_drop` to the last sender, halving their rate limits with that peer.&#xA;&gt;&#xA;&gt; If the sender doesn&#39;t overflow the rate limit again, the receiver should double the rate limit&#xA;&gt; after 30 seconds, until it reaches the default rate limit again.&#xA;&gt;&#xA;&gt; The flow will look like:&#xA;&gt;&#xA;&gt; Alice                      Bob                      Carol&#xA;&gt;   |                         |                         |&#xA;&gt;   |      onion_message      |                         |&#xA;&gt;   |------------------------&gt;|                         |&#xA;&gt;   |                         |      onion_message      |&#xA;&gt;   |                         |------------------------&gt;|&#xA;&gt;   |                         |    onion_message_drop   |&#xA;&gt;   |                         |&lt;------------------------|&#xA;&gt;   |    onion_message_drop   |                         |&#xA;&gt;   |&lt;------------------------|                         |&#xA;&gt;&#xA;&gt; The `shared_secret_hash` field contains a BIP 340 tagged hash of the Sphinx shared secret of the&#xA;&gt; rate limiting peer (in the example above, Carol):&#xA;&gt;&#xA;&gt; * `shared_secret_hash = SHA256(SHA256(&#34;onion_message_drop&#34;) || SHA256(&#34;onion_message_drop&#34;) || sphinx_shared_secret)`&#xA;&gt;&#xA;&gt; This value is known by the node that created the onion message: if `onion_message_drop` propagates&#xA;&gt; all the way back to them, it lets them know which part of the route is congested, allowing them&#xA;&gt; to retry through a different path.&#xA;&gt;&#xA;&gt; Whenever there is some latency between nodes and many onion messages, `onion_message_drop` may&#xA;&gt; be relayed to the incorrect incoming peer (since we only store the `node_id` of the _last_ incoming&#xA;&gt; peer in our outgoing connection state). The following example highlights this:&#xA;&gt;&#xA;&gt;  Eve                       Bob                      Carol&#xA;&gt;   |      onion_message      |                         |&#xA;&gt;   |------------------------&gt;|      onion_message      |&#xA;&gt;   |      onion_message      |------------------------&gt;|&#xA;&gt;   |------------------------&gt;|      onion_message      |&#xA;&gt;   |      onion_message      |------------------------&gt;|&#xA;&gt;   |------------------------&gt;|      onion_message      |&#xA;&gt;                             |------------------------&gt;|&#xA;&gt; Alice                       |    onion_message_drop   |&#xA;&gt;   |      onion_message      |                    +----|&#xA;&gt;   |------------------------&gt;|      onion_message |    |&#xA;&gt;   |                         |--------------------|---&gt;|&#xA;&gt;   |                         |                    |    |&#xA;&gt;   |                         |                    |    |&#xA;&gt;   |                         |                    |    |&#xA;&gt;   |    onion_message_drop   |&lt;-------------------+    |&#xA;&gt;   |&lt;------------------------|                         |&#xA;&gt;&#xA;&gt; In this example, Eve is spamming but `onion_message_drop` is propagated back to Alice instead.&#xA;&gt; However, this scheme will _statistically_ penalize the right incoming peer (with a probability&#xA;&gt; depending on the volume of onion messages that the spamming peer is generating compared to the&#xA;&gt; volume of legitimate onion messages).&#xA;&gt;&#xA;&gt; It is an interesting research problem to find formulas for those probabilities to evaluate how&#xA;&gt; efficient this will be against various types of spam. We hope researchers on this list will be&#xA;&gt; interested in looking into it and will come up with a good model to evaluate that scheme.&#xA;&gt;&#xA;&gt; To increase the accuracy of attributing `onion_message_drop`, more data could be stored in the&#xA;&gt; future if it becomes necessary. We need more research to quantify how much accuracy would be&#xA;&gt; gained by storing more data and making the protocol more complex.&#xA;&gt;&#xA;&gt; Cheers,&#xA;&gt; Bastien&#xA;&gt;&#xA;&gt; [1] https://gist.github.com/t-bast/e37ee9249d9825e51d260335c94f0fcf&#xA;&gt;&#xA;&gt; _______________________________________________&#xA;&gt; Lightning-dev mailing list&#xA;&gt; Lightning-dev at lists.linuxfoundation.org&#xA;&gt; https://lists.linuxfoundation.org/mailman/listinfo/lightning-dev&#xA;&gt;&#xA;-------------- next part --------------&#xA;An HTML attachment was scrubbed...&#xA;URL: &lt;http://lists.linuxfoundation.org/pipermail/lightning-dev/attachments/20220629/be1c82d7/attachment-0001.html&gt;</html></oembed>