<oembed><type>rich</type><version>1.0</version><author_name>npub1ly5vrg5ylhdkxrkj824jhlnfsy2z8fvlg8wcc0jqc4aezma6majsycdx6n</author_name><author_url>https://nostr.ae/npub1ly5vrg5ylhdkxrkj824jhlnfsy2z8fvlg8wcc0jqc4aezma6majsycdx6n</author_url><provider_name>njump</provider_name><provider_url>https://nostr.ae</provider_url><html>📅 Original date posted:2018-12-04&#xA;📝 Original message:&#xA;Thanks Christian, that makes sense. Unfortunately it&#39;s not very clear&#xA;from the BOLT, at least not for me.&#xA;&#xA;Now that I think of this type of attack: *in general* the HMAC prevents&#xA;this kind of attack, but isn&#39;t the attack still possible in certain&#xA;specific cases?&#xA;&#xA;&#xA;For instance, the attacking intermediate node might guess that the next&#xA;node in the route is the final node; it can test this by completely&#xA;replacing the onion packet it sends to the next node with a self-written&#xA;onion packet that has the next hop as final node, with the same amount&#xA;and payment hash as instructed by the incoming payment. If that&#xA;succeeds, it has learned that the next node is indeed the final node&#xA;(and nobody gets to know about the attack); if that fails, it might&#xA;retry the payment with the original onion packet. In that case, it&#xA;learned that the next node is *not* the final node. In this case, the&#xA;attack is detectable by the next node though: it first receives an&#xA;incoming payment with a payment hash it doesn&#39;t recognize, and then it&#xA;receives a payment forwarding request with the same payment hash.&#xA;&#xA;&#xA;Given that the attacker has good knowledge of the shape of the Lightning&#xA;network, this type of attack can be generalized to test whether a&#xA;certain second-degree neighbor, third-degree neighbor etc. is the final&#xA;node; it scales pretty badly with increasing network distance though. An&#xA;additional advantage for the attacker is that this gives plausible&#xA;deniability: if the attack becomes visible, the attacker can always&#xA;claim it wasn&#39;t him, but some node upstream in the route. A practical&#xA;difficulty for the attacker might be that the exact amount forwarded in&#xA;further-away hops is unknown, but it&#39;s probably not that difficult to guess.&#xA;&#xA;&#xA;I think we could stop this type of attack by including some kind of&#xA;shared secret in the onion message to the final node:&#xA;&#xA;* Payee generates shared secret and passes this to payer, as part of the&#xA;invoice&#xA;&#xA;* Payer includes shared secret in the per hop data to payee&#xA;&#xA;* On receiving the incoming message, payee checks whether the received&#xA;shared secret corresponds to the generated one. If this is not the case,&#xA;behave in exactly the same way as when the payment hash is unrecognized&#xA;(including timing, to prevent timing side-channel attacks).&#xA;&#xA;If this shared secret is encrypted like the rest of the per hop data,&#xA;the attacker can&#39;t learn the shared secret, and can&#39;t include it in his&#xA;own replacement onion. He can&#39;t copy-paste the encrypted shared secret&#xA;from the original onion either, since he has to use his own, different&#xA;ephemeral key in his own onion. With this protocol in place, a final&#xA;node can no longer be distinguished from a non-final node with this attack.&#xA;&#xA;&#xA;The shared secret doesn&#39;t need to be very large: the number of attempts&#xA;per second (to guess the shared secret) is limited by network latency,&#xA;bandwidth and maybe some artificial rate limiting. If an attacker can do&#xA;100 attempts per second, then a 32-bit shared secret will take (on&#xA;average) 2^31 / (100*3600*24) = 248 days to crack, for a single guess of&#xA;which node is the final node. In the mean time, people will have noticed&#xA;the ongoing attack and will have taken countermeasures. Besides, the&#xA;transaction lock time will likely have expired in the mean time as well.&#xA;&#xA;&#xA;CJP&#xA;&#xA;&#xA;On 29-11-18 18:13, Christian Decker wrote:&#xA;&gt; Hi Corne,&#xA;&gt;&#xA;&gt; the HMACs are necessary in order to make sure that a hop cannot modify&#xA;&gt; the packet before forwarding, and the next node not detecting that&#xA;&gt; modification.&#xA;&gt;&#xA;&gt; One potential attack that could facilitate is that an attacker could&#xA;&gt; learn the path length by messing with different per-hop payloads: set&#xA;&gt; n=0 the attacker flips bits in the nth per-hop payload, and forwards&#xA;&gt; it. If the next node doesn&#39;t return an error it was the final recipient,&#xA;&gt; if if returns an error, increment n and flip bits in the (n+1)th per-hop&#xA;&gt; payload, until no error is returned. Congratulation you just learned the&#xA;&gt; path length after you. The same can probably be done with the error&#xA;&gt; packet, meaning you can learn the exact position in the route. Add to&#xA;&gt; that the information you already know about the network (cltv_deltas,&#xA;&gt; amounts, fees, ...) and you can probably detect sender and recipient.&#xA;&gt;&#xA;&gt; Adding HMACs solves this by ensuring that the next hop will return an&#xA;&gt; error if anything was changed, i.e., removing the leak about which node&#xA;&gt; would have failed the route.&#xA;&gt;&#xA;&gt; Cheers,&#xA;&gt; Christian</html></oembed>