Skip to content
LearnBitcoin

ResearchBitcoin Dev Archive lightning-dev list

Probing final receiver with refund timeout

8 messages, Mar 2 to 22, 2016. Started by Mats Jerratsch.

Mats Jerratsch (4), Rusty Russell (4)

Permalink First message in the Wayback Machine

Mats Jerratsch permalink original

Just discovered that it is possible to attack the onion routing with probing too short of an absolute CLTV refund timeout.

When accepting a payment, one will check if the remaining timeout > MIN_TIMEOUT.

When relaying the payment to the next node, one can either decide to check directly if the next node would accept it, or just relay and see what happens (the next node would then refuse to include the payment).

Checking directly is equivalent of checking for 2 * MIN_TIMEOUT before accepting it. However, as the next node will check for 2 * MIN_TIMEOUT again, this is running in circles and just blindly increasing the final MIN_TIMEOUT.

For an attacker it is now possible to choose a timeout that is lower than 2 * MIN_TIMEOUT. If the payment succeeds, he knows that the next node was the final receiver, if it doesn't he can redo the payment with a larger timeout without any drawback, basically probing all payments once.

As discussed above, testing for a larger timeout before accepting / relaying does not solve this problem. If all nodes only accept payments with timeout > 10 * MIN_TIMEOUT, you can still probe with 10.5 * MIN_TIMEOUT.

I think the only way to solve this would be to include (1) the timeout the previous node should have sent you (2) the timeout you should use for the next node into the onion object and test it accordingly.

If you discover that the previous node messed with the timeout, you directly refund it. It further complicates routing though, as the source of the payment needs to know all MIN_TIMEOUT of the nodes in the route. It also needs more coordination when doing RP-routing, as the receiver has to include the timeout he chose for the first hop of his route.

It probably also opens up another attack vector for attacking the network with unroutable payments.

Cheers

Rusty Russell in reply to Mats Jerratsch permalink original

Mats Jerratsch via Lightning-dev <lightning-dev at lists.linuxfoundation.org> writes:

Quoted text (5 lines)
> Just discovered that it is possible to attack the onion routing with
> probing too short of an absolute CLTV refund timeout.
>
> When accepting a payment, one will check if the remaining timeout >
> MIN_TIMEOUT.

One mitigation for this particular attack would be to remember the onion and always fail an identical one. That would allow a single probe, however (basically, "are you the final destination?").

Also the timeout for the next hop should probably be somewhat randomized, at least subtracting (MIN_TIMEOUT to MIN_TIMEOUT*2).

The question remains as to what HTLC timeout should be set to initially. Even if you randomize it, over time the pattern would reveal to your peer if you are originating all the HTLCS, for example.

Cheers, Rusty.

Mats Jerratsch in reply to Rusty Russell permalink original

Only mitigates it such that you can't do for free, and it adds some complexity and we might barricade some future feature with it (like having multiple payments to one R value, over the same route).

For now I start with

MAX_HOPS * MAX_OVERLAY * MIN_TIMEOUT

where MAX_OVERLAY is some 'consensus' value of how much buffer time each node should deduct from the refund time at most. That way each node can use the full range to randomize the refund time, without running out of time in the end. I do not see how a pattern should emerge from that though.

However, I am inclined to use those timestamps in the onion object, as the described attackvector still exists.

Cheers

Am 05/03/2016 um 09:28 schrieb Rusty Russell:

Quoted text (22 lines)
> Mats Jerratsch via Lightning-dev
> <lightning-dev at lists.linuxfoundation.org> writes:
>> Just discovered that it is possible to attack the onion routing with
>> probing too short of an absolute CLTV refund timeout.
>>
>> When accepting a payment, one will check if the remaining timeout >
>> MIN_TIMEOUT.
>
> One mitigation for this particular attack would be to remember the onion
> and always fail an identical one.  That would allow a single probe,
> however (basically, "are you the final destination?").
>
> Also the timeout for the next hop should probably be somewhat
> randomized, at least subtracting (MIN_TIMEOUT to MIN_TIMEOUT*2).
>
> The question remains as to what HTLC timeout should be set to initially.
> Even if you randomize it, over time the pattern would reveal to your
> peer if you are originating all the HTLCS, for example.
>
> Cheers,
> Rusty.
>
Rusty Russell in reply to Mats Jerratsch permalink original

Mats Jerratsch <mats at blockchain.com> writes:

Quoted text (3 lines)
> Only mitigates it such that you can't do for free, and it adds some
> complexity and we might barricade some future feature with it (like
> having multiple payments to one R value, over the same route).

No, not filtered the same R value, filtered on the bitwise identical onion routing information (the origin would generate a fresh onion for every payment, independent of R value). The malicious node can't manipulate the routing onion, or it won't decode.

(You can actually just save the authentication tag I think, for comparison).

Quoted text (8 lines)
> For now I start with
>
> MAX_HOPS * MAX_OVERLAY * MIN_TIMEOUT
>
> where MAX_OVERLAY is some 'consensus' value of how much buffer time each
> node should deduct from the refund time at most. That way each node can
> use the full range to randomize the refund time, without running out of
> time in the end. I do not see how a pattern should emerge from that though.

If A sends many HTLCs through B, B can simply plot what the timeouts are and know that A is likely originating the HTLCs rather than relaying them for someone else.

I can't come up a scheme which combats this kind of analysis, but there are cleverer people than me on this list...

Quoted text (2 lines)
> However, I am inclined to use those timestamps in the onion object, as
> the described attackvector still exists.

Doesn't including timestamps in the onion provide explicit information on the number of previous hops though?

Thanks, Rusty.

Mats Jerratsch in reply to Rusty Russell permalink original
Quoted text (3 lines)
> If A sends many HTLCs through B, B can simply plot what the timeouts
> are and know that A is likely originating the HTLCs rather than relaying
> them for someone else.

Hm, right. If all payments that come from A have a timeout larger than some minimum value X, he is generating all of them and is just trying to randomize those. However, if he creates a payment with an initial refund value lower than X, the payment might not succeed, because the intermediate nodes deducted too much.

However, if we take into account that the amount of nodes in the route is not a constant, and only known to the sender, this adds another degree of freedom to choose the initial value.

Quoted text (5 lines)
>> However, I am inclined to use those timestamps in the onion object, as
>> the described attackvector still exists.
>
> Doesn't including timestamps in the onion provide explicit information
> on the number of previous hops though?

Not if they are randomized. The initial sender will choose a good starting value (see above), and deduct MIN_TIMEOUT * MIN_OVERLAY * RANDOM from it. Actually it doesn't provide any additional data, as that is the very same mechanism the intermediate hops come to that value.

Rusty Russell in reply to Mats Jerratsch permalink original

Mats Jerratsch <mats at blockchain.com> writes:

Quoted text (13 lines)
>> If A sends many HTLCs through B, B can simply plot what the timeouts
>> are and know that A is likely originating the HTLCs rather than relaying
>> them for someone else.
>
> Hm, right. If all payments that come from A have a timeout larger than
> some minimum value X, he is generating all of them and is just trying to
> randomize those. However, if he creates a payment with an initial refund
> value lower than X, the payment might not succeed, because the
> intermediate nodes deducted too much.
>
> However, if we take into account that the amount of nodes in the route
> is not a constant, and only known to the sender, this adds another
> degree of freedom to choose the initial value.

Good point. But we still lose on the receiving side; if you ever see a small timeout you know the next hop is the final one.

I imagine we'll be spending some time getting more sophisticated with our value cloaking as attacks emerge, but I'm happy to start with something reasonable.

Quoted text (10 lines)
>>> However, I am inclined to use those timestamps in the onion object, as
>>> the described attackvector still exists.
>>
>> Doesn't including timestamps in the onion provide explicit information
>> on the number of previous hops though?
>
> Not if they are randomized. The initial sender will choose a good
> starting value (see above), and deduct MIN_TIMEOUT * MIN_OVERLAY *
> RANDOM from it. Actually it doesn't provide any additional data, as that
> is the very same mechanism the intermediate hops come to that value.

OK, let me get the proposal straight:

1.  Each node will publish its MIN_TIMEOUT (along
    with its other info as per Option 2 in
    https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2015/preventing-mitm-providing-new-nodes-with-real-pubkeys#m-1edddc68 )
2.  The payer sums the MIN_TIMEOUT to the payee, adds some random value
    (keeping it under the max value allowed by protocol) to give the
    initial HTLC timeout.
3.  The payer puts the 'expected_timeout' in each layer of the onion, by
    subtracting the last hops' MIN_TIMEOUT from the initial timeout.

eg. Say maximum allowed timeout is 20 * 12 hours, and route is:

        A (12 hours) -> B (6 hours) -> C (6 hours) -> D (4 hours)
     Initial timeout has to be at least 12 + 6 + 6 + 4 == 28 hours, plus
     some padding for transmission delays, say 29 hours.
     It picks a random timeout between 29 and 240 hours, say now+100 hours,
     and onion looks like:
     [ A: now+100 [ B: now+88 [ C: now+82 [ D: now+76 ] ] ] ]

Have I missed anything?

Rusty.

Mats Jerratsch in reply to Rusty Russell permalink original
Quoted text (19 lines)
> OK, let me get the proposal straight:
>
> 1.  Each node will publish its MIN_TIMEOUT (along
>    with its other info as per Option 2 in
>    https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2015/preventing-mitm-providing-new-nodes-with-real-pubkeys#m-1edddc68 )
>
> 2.  The payer sums the MIN_TIMEOUT to the payee, adds some random value
>    (keeping it under the max value allowed by protocol) to give the
>    initial HTLC timeout.
>
> 3.  The payer puts the 'expected_timeout' in each layer of the onion, by
>    subtracting the last hops' MIN_TIMEOUT from the initial timeout.
>
> eg.  Say maximum allowed timeout is 20 * 12 hours, and route is:
>
>        A (12 hours) -> B (6 hours) -> C (6 hours) -> D (4 hours)
>
>     Initial timeout has to be at least 12 + 6 + 6 + 4 == 28 hours, plus
>     some padding for transmission delays, say 29 hours.

I take a multiply of the MIN_TIMEOUT, a factor around 2, but yes, that sounds about right

Quoted text (5 lines)
>
>     It picks a random timeout between 29 and 240 hours, say now+100 hours,
>     and onion looks like:
>
>     [ A: now+100 [ B: now+88 [ C: now+82 [ D: now+76 ] ] ] ]

I would not use the MIN_TIMEOUT here, but use it as the minimum time I deduct each hop and add some randomness into it. It also means that you need two values in the onion object:

(1) the value you expect to receive
(2) the value you should use for the next hop (and therefore the (1) value of the next hop))
So somewhere along this:
    [ A: now+100;now+80 [ B: now+80;now+65 [ C: now+65;now+54 [ D: now+54;now+40 ] ] ] ]
which can obviously be saved in a less redundant way

Cheers Mats

Rusty Russell in reply to Mats Jerratsch permalink original

Mats Jerratsch <mats at blockchain.com> writes:

Quoted text (37 lines)
>> OK, let me get the proposal straight:
>>
>> 1.  Each node will publish its MIN_TIMEOUT (along
>>    with its other info as per Option 2 in
>>    https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2015/preventing-mitm-providing-new-nodes-with-real-pubkeys#m-1edddc68 )
>>
>> 2.  The payer sums the MIN_TIMEOUT to the payee, adds some random value
>>    (keeping it under the max value allowed by protocol) to give the
>>    initial HTLC timeout.
>>
>> 3.  The payer puts the 'expected_timeout' in each layer of the onion, by
>>    subtracting the last hops' MIN_TIMEOUT from the initial timeout.
>>
>> eg.  Say maximum allowed timeout is 20 * 12 hours, and route is:
>>
>>        A (12 hours) -> B (6 hours) -> C (6 hours) -> D (4 hours)
>>
>>     Initial timeout has to be at least 12 + 6 + 6 + 4 == 28 hours, plus
>>     some padding for transmission delays, say 29 hours.
>
> I take a multiply of the MIN_TIMEOUT, a factor around 2, but yes, that sounds about right
>
>>
>>     It picks a random timeout between 29 and 240 hours, say now+100 hours,
>>     and onion looks like:
>>
>>     [ A: now+100 [ B: now+88 [ C: now+82 [ D: now+76 ] ] ] ]
>
> I would not use the MIN_TIMEOUT here, but use it as the minimum time I deduct each hop and add some randomness into it.
> It also means that you need two values in the onion object:
>
> (1) the value you expect to receive
> (2) the value you should use for the next hop (and therefore the (1) value of the next hop))
>
> So somewhere along this:
>     [ A: now+100;now+80 [ B: now+80;now+65 [ C: now+65;now+54 [ D: now+54;now+40 ] ] ] ]
> which can obviously be saved in a less redundant way

OK, does that randomness add anything useful? Maybe I need another coffee to see it?

Thanks, Rusty.