<oembed><type>rich</type><version>1.0</version><author_name>npub17fjkngg0s0mfx4uhhz6n4puhflwvrhn2h5c78vdr5xda4mvqx89swntr0s</author_name><author_url>https://nostr.ae/npub17fjkngg0s0mfx4uhhz6n4puhflwvrhn2h5c78vdr5xda4mvqx89swntr0s</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;During the recent Oakland Dev Summit, some lightning engineers got&#xA;together to discuss DoS&#xA;protection for onion messages. Rusty proposed a very simple&#xA;rate-limiting scheme that&#xA;statistically propagates back to the correct sender, which we describe&#xA;in details below.&#xA;&#xA;You can also read this in gist format if that works better for you [1].&#xA;&#xA;Nodes apply per-peer rate limits on _incoming_ onion messages that&#xA;should be relayed (e.g.&#xA;N/seconds with some burst tolerance). It is recommended to allow more&#xA;onion messages from&#xA;peers with whom you have channels, for example 10/seconds when you&#xA;have a channel and 1/second&#xA;when you don&#39;t.&#xA;&#xA;When relaying an onion message, nodes keep track of where it came from&#xA;(by using the `node_id` of&#xA;the peer who sent that message). Nodes only need the last such&#xA;`node_id` per outgoing connection,&#xA;which ensures the memory footprint is very small. Also, this data&#xA;doesn&#39;t need to be persisted.&#xA;&#xA;Let&#39;s walk through an example to illustrate this mechanism:&#xA;&#xA;* Bob receives an onion message from Alice that should be relayed to Carol&#xA;* After relaying that message, Bob stores Alice&#39;s `node_id` in its&#xA;per-connection state with Carol&#xA;* Bob receives an onion message from Eve that should be relayed to Carol&#xA;* After relaying that message, Bob replaces Alice&#39;s `node_id` with&#xA;Eve&#39;s `node_id` in its&#xA;per-connection state with Carol&#xA;* Bob receives an onion message from Alice that should be relayed to Dave&#xA;* After relaying that message, Bob stores Alice&#39;s `node_id` in its&#xA;per-connection state with Dave&#xA;* ...&#xA;&#xA;We introduce a new message that will be sent when dropping an incoming&#xA;onion message because it&#xA;reached rate limits:&#xA;&#xA;1. type: 515 (`onion_message_drop`)&#xA;2. data:&#xA;   * [`rate_limited`:`u8`]&#xA;   * [`shared_secret_hash`:`32*byte`]&#xA;&#xA;Whenever an incoming onion message reaches the rate limit, the&#xA;receiver sends `onion_message_drop`&#xA;to the sender. The sender looks at its per-connection state to find&#xA;where the message was coming&#xA;from and relays `onion_message_drop` to the last sender, halving their&#xA;rate limits with that peer.&#xA;&#xA;If the sender doesn&#39;t overflow the rate limit again, the receiver&#xA;should double the rate limit&#xA;after 30 seconds, until it reaches the default rate limit again.&#xA;&#xA;The flow will look like:&#xA;&#xA;Alice                      Bob                      Carol&#xA;  |                         |                         |&#xA;  |      onion_message      |                         |&#xA;  |------------------------&gt;|                         |&#xA;  |                         |      onion_message      |&#xA;  |                         |------------------------&gt;|&#xA;  |                         |    onion_message_drop   |&#xA;  |                         |&lt;------------------------|&#xA;  |    onion_message_drop   |                         |&#xA;  |&lt;------------------------|                         |&#xA;&#xA;The `shared_secret_hash` field contains a BIP 340 tagged hash of the&#xA;Sphinx shared secret of the&#xA;rate limiting peer (in the example above, Carol):&#xA;&#xA;* `shared_secret_hash = SHA256(SHA256(&#34;onion_message_drop&#34;) ||&#xA;SHA256(&#34;onion_message_drop&#34;) || sphinx_shared_secret)`&#xA;&#xA;This value is known by the node that created the onion message: if&#xA;`onion_message_drop` propagates&#xA;all the way back to them, it lets them know which part of the route is&#xA;congested, allowing them&#xA;to retry through a different path.&#xA;&#xA;Whenever there is some latency between nodes and many onion messages,&#xA;`onion_message_drop` may&#xA;be relayed to the incorrect incoming peer (since we only store the&#xA;`node_id` of the _last_ incoming&#xA;peer in our outgoing connection state). The following example highlights this:&#xA;&#xA; Eve                       Bob                      Carol&#xA;  |      onion_message      |                         |&#xA;  |------------------------&gt;|      onion_message      |&#xA;  |      onion_message      |------------------------&gt;|&#xA;  |------------------------&gt;|      onion_message      |&#xA;  |      onion_message      |------------------------&gt;|&#xA;  |------------------------&gt;|      onion_message      |&#xA;                            |------------------------&gt;|&#xA;Alice                       |    onion_message_drop   |&#xA;  |      onion_message      |                    +----|&#xA;  |------------------------&gt;|      onion_message |    |&#xA;  |                         |--------------------|---&gt;|&#xA;  |                         |                    |    |&#xA;  |                         |                    |    |&#xA;  |                         |                    |    |&#xA;  |    onion_message_drop   |&lt;-------------------+    |&#xA;  |&lt;------------------------|                         |&#xA;&#xA;In this example, Eve is spamming but `onion_message_drop` is&#xA;propagated back to Alice instead.&#xA;However, this scheme will _statistically_ penalize the right incoming&#xA;peer (with a probability&#xA;depending on the volume of onion messages that the spamming peer is&#xA;generating compared to the&#xA;volume of legitimate onion messages).&#xA;&#xA;It is an interesting research problem to find formulas for those&#xA;probabilities to evaluate how&#xA;efficient this will be against various types of spam. We hope&#xA;researchers on this list will be&#xA;interested in looking into it and will come up with a good model to&#xA;evaluate that scheme.&#xA;&#xA;To increase the accuracy of attributing `onion_message_drop`, more&#xA;data could be stored in the&#xA;future if it becomes necessary. We need more research to quantify how&#xA;much accuracy would be&#xA;gained by storing more data and making the protocol more complex.&#xA;&#xA;Cheers,&#xA;Bastien&#xA;&#xA;[1] https://gist.github.com/t-bast/e37ee9249d9825e51d260335c94f0fcf&#xA;-------------- next part --------------&#xA;An HTML attachment was scrubbed...&#xA;URL: &lt;http://lists.linuxfoundation.org/pipermail/lightning-dev/attachments/20220629/513b6829/attachment.html&gt;</html></oembed>