Skip to content
LearnBitcoin

ResearchBitcoin Dev Archive lightning-dev list

Difference between ignoring htlc request due to wrong payment hash vs refusing to release preimage in LND

7 messages, Mar 24, 2020. Started by Subhra Mazumdar.

Subhra Mazumdar (4), ZmnSCPxj (3)

Permalink First message in the Wayback Machine

Subhra Mazumdar permalink original
Hi,
    I was just playing around with LND and established a channel between 2
parties A and B. When sending a payment to B via HTLC, B adds an invoice
and over here I used a different payment hash for A for sendpayment with a
delta of 144 blocks. The error I got on initiating send payment is
"incorrect or unknown payment details". So what is exactly happening here?
Is B ignoring any formation of HTLC between them? I hope in this case no
money gets locked in this case. Then how can one mimic griefing attack
scenario (B refusing to release the correct preimage) in LND?
ZmnSCPxj in reply to Subhra Mazumdar permalink original

Good morning Subhra,

Quoted text (2 lines)
> Hi,
>     I was just playing around with LND and established a channel between 2 parties A and B. When sending a payment to B via HTLC, B adds an invoice and over here I used a different payment hash for A for sendpayment with a delta of 144 blocks. The error I got on initiating send payment is "incorrect or unknown payment details". So what is exactly happening here? Is B ignoring any formation of HTLC between them?

A and B form an HTLC in them, to the point that it is "irrevocably committed". It is a recommendation of BOLT spec that you pretty much do not do anything until an incoming HTLC reaches "irrevocably committed" state.

Then, B looks at the HTLC data. If B knows the preimage to the payment hash, it claims the HTLC immediately as soon as it is irrevocably committed.

If B does not know the preimage, it checks if there is forwarding data. If there is no forwarding data (B is the final hop) then B responds with "incorrect or unknown payment details", then A waits for the channel state to advance so that the HTLC getting removed reaches "irrevocably committed", then reports the failure to the user.

Quoted text (1 line)
> I hope in this case no money gets locked in this case.

Money got locked temporarily int the HTLC, but was freed very soon afterwards, as fast as B and A can advance the channel state (which is limited by your hardware and network speeds).

Quoted text (1 line)
> Then how can one mimic griefing attack scenario (B refusing to release the correct preimage) in LND?

You may need to modify LND code directly, or ask LND devs if there are any such hooks available.

In C-Lightning, you will have to install a plugin, devise some way for the plugin to know of what payment hash you want to grief, then have the plugin hook into `htlc_accepted`. In `htlc_accepted` handler, if the incoming HTLC has a payment hash matching what you want to grief, you then perform a `waitblockheight` command to wait for the target block height you want to grief for, then return from the `htlc_accepted` handler. (This can be complicated by the exact language you use to implement the plugin, remember the plugin should be async so it should still respond with `{"result":"continue"}` immediately to other incoming `htlc_accepted` as normal, if you implement the plugin in Python the Python C-Lightning plugin library should "just work" as far as I know as it transforms the Python into an async language, but ask cdecker for that; but if you have a sufficiently monadic framework for asynchronicity (a la Javascript `Promise`/Haskell `IO`) it should work like that.)

Regards, ZmnSCPxj

Subhra Mazumdar in reply to ZmnSCPxj permalink original

Thanks ZmnSCPxj. Just a clarification on the idea proposed so that means here B needs to delay the HTLC acceptance? Pardon my knowledge on c-lightning, but what exactly happens upon htlc_acceptance? Release of preimage or just an acknowledgment by B reaching to the point of irrevocably committed?

On Tue, Mar 24, 2020 at 1:57 PM ZmnSCPxj <ZmnSCPxj at protonmail.com> wrote:

Quoted text (57 lines)
> Good morning Subhra,
>
> > Hi,
> >     I was just playing around with LND and established a channel between
> 2 parties A and B. When sending a payment to B via HTLC, B adds an invoice
> and over here I used a different payment hash for A for sendpayment with a
> delta of 144 blocks. The error I got on initiating send payment is
> "incorrect or unknown payment details". So what is exactly happening here?
> Is B ignoring any formation of HTLC between them?
>
> A and B form an HTLC in them, to the point that it is "irrevocably
> committed".
> It is a recommendation of BOLT spec that you pretty much do not do
> anything until an incoming HTLC reaches "irrevocably committed" state.
>
> Then, B looks at the HTLC data.
> If B knows the preimage to the payment hash, it claims the HTLC
> immediately as soon as it is irrevocably committed.
>
> If B does not know the preimage, it checks if there is forwarding data.
> If there is no forwarding data (B is the final hop) then B responds with
> "incorrect or unknown payment details", then A waits for the channel state
> to advance so that the HTLC getting removed reaches "irrevocably
> committed", then reports the failure to the user.
>
> > I hope in this case no money gets locked in this case.
>
> Money got locked temporarily int the HTLC, but was freed very soon
> afterwards, as fast as B and A can advance the channel state (which is
> limited by your hardware and network speeds).
>
>
> > Then how can one mimic griefing attack scenario (B refusing to release
> the correct preimage) in LND?
>
> You may need to modify LND code directly, or ask LND devs if there are any
> such hooks available.
>
> In C-Lightning, you will have to install a plugin, devise some way for the
> plugin to know of what payment hash you want to grief, then have the plugin
> hook into `htlc_accepted`.
> In `htlc_accepted` handler, if the incoming HTLC has a payment hash
> matching what you want to grief, you then perform a `waitblockheight`
> command to wait for the target block height you want to grief for, then
> return from the `htlc_accepted` handler.
> (This can be complicated by the exact language you use to implement the
> plugin, remember the plugin should be async so it should still respond with
> `{"result":"continue"}` immediately to other incoming `htlc_accepted` as
> normal, if you implement the plugin in Python the Python C-Lightning plugin
> library should "just work" as far as I know as it transforms the Python
> into an async language, but ask cdecker for that; but if you have a
> sufficiently monadic framework for asynchronicity (a la Javascript
> `Promise`/Haskell `IO`) it should work like that.)
>
> Regards,
> ZmnSCPxj
>
Subhra Mazumdar in reply to ZmnSCPxj permalink original

Another question related to the paper https://arxiv.org/abs/2003.00003. Over here, it is stated in page 13, "Surge of unresolved HTLCs while probing: Recalling steps 5-7 in Figure 4, each probe sets up a chain of irredeemable HTLCs (since a matching preimage would have to be brute-forced). Eventually, running multiple probes over the same channels will escrow its funds in these HTLCs, effectively DOSing the probe route and forcing the nodes to wait until the HTLCs time out before being able to forward other payments. This is an issue we encountered over and over during 4.2 and 4.3, often giving us one shot at probing before having to wait multiple hours for the HTLCs to expire. This is also why we chose the channels leading up to our final target to have a much higher balance, so that we would have enough.." So there was no matching preimage with receiver as per Fig 4. So that means in the route say A->B->C->D, if D doesn't have a matching preimage and suppose C->D uses lock time of 144 blocks, B->C 288 blocks and A->B uses a locktime of 432 blocks, so won't be the case funds in A->B and B->C still remains locked for the mentioned locktime? I know this is not the definition of griefing attack but then can this possibly mimic the situation where receiver denies having the correct preimage?

On Tue, Mar 24, 2020 at 1:57 PM ZmnSCPxj <ZmnSCPxj at protonmail.com> wrote:

Quoted text (57 lines)
> Good morning Subhra,
>
> > Hi,
> >     I was just playing around with LND and established a channel between
> 2 parties A and B. When sending a payment to B via HTLC, B adds an invoice
> and over here I used a different payment hash for A for sendpayment with a
> delta of 144 blocks. The error I got on initiating send payment is
> "incorrect or unknown payment details". So what is exactly happening here?
> Is B ignoring any formation of HTLC between them?
>
> A and B form an HTLC in them, to the point that it is "irrevocably
> committed".
> It is a recommendation of BOLT spec that you pretty much do not do
> anything until an incoming HTLC reaches "irrevocably committed" state.
>
> Then, B looks at the HTLC data.
> If B knows the preimage to the payment hash, it claims the HTLC
> immediately as soon as it is irrevocably committed.
>
> If B does not know the preimage, it checks if there is forwarding data.
> If there is no forwarding data (B is the final hop) then B responds with
> "incorrect or unknown payment details", then A waits for the channel state
> to advance so that the HTLC getting removed reaches "irrevocably
> committed", then reports the failure to the user.
>
> > I hope in this case no money gets locked in this case.
>
> Money got locked temporarily int the HTLC, but was freed very soon
> afterwards, as fast as B and A can advance the channel state (which is
> limited by your hardware and network speeds).
>
>
> > Then how can one mimic griefing attack scenario (B refusing to release
> the correct preimage) in LND?
>
> You may need to modify LND code directly, or ask LND devs if there are any
> such hooks available.
>
> In C-Lightning, you will have to install a plugin, devise some way for the
> plugin to know of what payment hash you want to grief, then have the plugin
> hook into `htlc_accepted`.
> In `htlc_accepted` handler, if the incoming HTLC has a payment hash
> matching what you want to grief, you then perform a `waitblockheight`
> command to wait for the target block height you want to grief for, then
> return from the `htlc_accepted` handler.
> (This can be complicated by the exact language you use to implement the
> plugin, remember the plugin should be async so it should still respond with
> `{"result":"continue"}` immediately to other incoming `htlc_accepted` as
> normal, if you implement the plugin in Python the Python C-Lightning plugin
> library should "just work" as far as I know as it transforms the Python
> into an async language, but ask cdecker for that; but if you have a
> sufficiently monadic framework for asynchronicity (a la Javascript
> `Promise`/Haskell `IO`) it should work like that.)
>
> Regards,
> ZmnSCPxj
>
ZmnSCPxj in reply to Subhra Mazumdar permalink original

Good morning Subhra,

Quoted text (1 line)
> Thanks ZmnSCPxj. Just a clarification on the idea proposed so that means here B needs to delay the HTLC acceptance?  Pardon my knowledge on c-lightning, but what exactly happens upon htlc_acceptance? Release of preimage or just an acknowledgment by B reaching to the point of irrevocably committed?

This event is emitted when an incoming HTLC is irrevocably committed. This is a hook, and what happens will depend on what the hook returns:

* It returns `{"result":"continue"}`: normal processing of the HTLC (forward, fail, or claim as normal operation).
* It returns `{"result":"fail", "failure_message": "2002"}`: fail the HTLC with the given failure message, failure message is a hex-encoded failure blob, see BOLT 4 for how.
* It returns `{"result": "resolve", "payment_key": "0000000000000000000000000000000000000000000000000000000000000000"}`: claim the HTLC regardless of whether it is a forward or terminates here, the given `payment_key` is the 64-hex-digits encoding of the preimage.

For the most part, for purposes of griefing, you can just delay the default `{"result":"continue"}` for as long as you want to grief the payment, this will work for both forwards and payment receives correctly, except griefed.

See [our docs](https://lightning.readthedocs.io/PLUGINS.html#htlc-accepted) for more.

Regards, ZmnSCPxj

Quoted text (35 lines)
>
> On Tue, Mar 24, 2020 at 1:57 PM ZmnSCPxj <ZmnSCPxj at protonmail.com> wrote:
>
> > Good morning Subhra,
> >
> > > Hi,
> > >     I was just playing around with LND and established a channel between 2 parties A and B. When sending a payment to B via HTLC, B adds an invoice and over here I used a different payment hash for A for sendpayment with a delta of 144 blocks. The error I got on initiating send payment is "incorrect or unknown payment details". So what is exactly happening here? Is B ignoring any formation of HTLC between them?
> >
> > A and B form an HTLC in them, to the point that it is "irrevocably committed".
> > It is a recommendation of BOLT spec that you pretty much do not do anything until an incoming HTLC reaches "irrevocably committed" state.
> >
> > Then, B looks at the HTLC data.
> > If B knows the preimage to the payment hash, it claims the HTLC immediately as soon as it is irrevocably committed.
> >
> > If B does not know the preimage, it checks if there is forwarding data.
> > If there is no forwarding data (B is the final hop) then B responds with "incorrect or unknown payment details", then A waits for the channel state to advance so that the HTLC getting removed reaches "irrevocably committed", then reports the failure to the user.
> >
> > > I hope in this case no money gets locked in this case.
> >
> > Money got locked temporarily int the HTLC, but was freed very soon afterwards, as fast as B and A can advance the channel state (which is limited by your hardware and network speeds).
> >
> > > Then how can one mimic griefing attack scenario (B refusing to release the correct preimage) in LND?
> >
> > You may need to modify LND code directly, or ask LND devs if there are any such hooks available.
> >
> > In C-Lightning, you will have to install a plugin, devise some way for the plugin to know of what payment hash you want to grief, then have the plugin hook into `htlc_accepted`.
> > In `htlc_accepted` handler, if the incoming HTLC has a payment hash matching what you want to grief, you then perform a `waitblockheight` command to wait for the target block height you want to grief for, then return from the `htlc_accepted` handler.
> > (This can be complicated by the exact language you use to implement the plugin, remember the plugin should be async so it should still respond with `{"result":"continue"}` immediately to other incoming `htlc_accepted` as normal, if you implement the plugin in Python the Python C-Lightning plugin library should "just work" as far as I know as it transforms the Python into an async language, but ask cdecker for that; but if you have a sufficiently monadic framework for asynchronicity (a la Javascript `Promise`/Haskell `IO`) it should work like that.)
> >
> > Regards,
> > ZmnSCPxj
>
> --
> Yours sincerely,
> Subhra Mazumdar.
ZmnSCPxj in reply to Subhra Mazumdar permalink original

Good morning Subhra,

Quoted text (1 line)
> Another question related to the paper https://arxiv.org/abs/2003.00003. Over here, it is stated in page 13, "Surge of unresolved HTLCs while probing: Recalling steps 5-7 in Figure 4, each probe sets up a chain of irredeemable HTLCs (since a matching preimage would have to be brute-forced). Eventually, running multiple probes over the same channels will escrow its funds in these HTLCs, effectively DOSing the probe route and forcing the nodes to wait until the HTLCs time out before being able to forward other payments. This is an issue we encountered over and over during 4.2 and 4.3, often giving us one shot at probing before having to wait multiple hours for the HTLCs to expire. This is also why we chose the channels leading up to our final target to have a much higher balance, so that we would have enough.." So there was no matching preimage with receiver as per Fig 4. So that means in the route say A->B->C->D, if D doesn't have a matching preimage and suppose C->D uses lock time of 144 blocks, B->C 288 blocks and A->B uses a locktime of 432 blocks, so won't be the case funds in A->B and B->C still remains locked for the mentioned locktime?

It is helpful to remember that inside a channel, every contract has an implicit branch "if both of us in this channel agree, we can spend this contract funds any way we want".

This is because every contract is dependent on a transaction spending from a 2-of-2, and both parties can always sign a new 2-of-2 transaction without that contract --- it is just that both have to agree to do this.

In case of a reported failure, the receiving node in the channel basically says "just between the two of us, I will not be able to claim this HTLC using the hashlock branch anyway because <BOLT 4 failure code reason>, so this will inevitably be claimable to you in the timelock anyway, so we might as well just agree to re-assign the HTLC funds back to you right now".

The sending node is then willing to sign off on this outside-of-the-contract agreement, since it lets it get the funds back before the timelock expires, and to reuse those funds otherwise.

Thus, even if D griefs up to 143 blocks it wants, at the 144th block C can report immediately back to B and then A with the above failure mechanism.

B and C are incentivized to do this quickly since it would allow the funds to be reused again in a different, probably-will-not-be-griefed near-future payment, which might earn them fees in the future.

Thus if B and C are not controlled by the A+D conglomerate then they have no incentive to extend the griefing attack further.

Of course, if either B or C is offline at the time, then the new state where the HTLC is removed out-of-contract is not possible to sign with both parties.

Quoted text (1 line)
> I know this is not the definition of griefing attack but then can this possibly mimic the situation where receiver denies having the correct preimage?

No, since B and C are incentivized to report this immediately in order to free up the funds in order for them to forward "soon".

Regards, ZmnSCPxj

Subhra Mazumdar in reply to ZmnSCPxj permalink original
Hi ZmnSCPxj,
      Thank you for the explanation. So I went through BOLT 04
specification and quoting a few error possibilities:

An *intermediate hop* MUST NOT, but the *final node*:

   - if the payment_secret doesn't match the expected value for that
   payment_hash, or the payment_secret is required and is not present:
      - MUST fail the HTLC.
      - MUST return an incorrect_or_unknown_payment_details error.
   - if the payment hash is unknown:
      - MUST fail the HTLC.
      - MUST return an incorrect_or_unknown_payment_details error.
      So it is the final node which is expected to fail the htlc in these 2
   cases. But then what if final node denies revealing the secret?  Say in the
   scenario A->B->C->D, D doesn't reveal the secret. So in such a case, what
   is C supposed to do? Shall it resort to condition no. 1( secret doesn't
   match), generate an error message and unlock funds of A->B and B->C as soon
   as possible?

On Tue, Mar 24, 2020 at 4:57 PM ZmnSCPxj <ZmnSCPxj at protonmail.com> wrote:

Quoted text (63 lines)
> Good morning Subhra,
>
> > Another question related to the paper https://arxiv.org/abs/2003.00003.
> Over here, it is stated in page 13, "Surge of unresolved HTLCs while
> probing: Recalling steps 5-7 in Figure 4, each probe sets up a chain of
> irredeemable HTLCs (since a matching preimage would have to be
> brute-forced). Eventually, running multiple probes over the same channels
> will escrow its funds in these HTLCs, effectively DOSing the probe route
> and forcing the nodes to wait until the HTLCs time out before being able to
> forward other payments. This is an issue we encountered over and over
> during 4.2 and 4.3, often giving us one shot at probing before having to
> wait multiple hours for the HTLCs to expire. This is also why we chose the
> channels leading up to our final target to have a much higher balance, so
> that we would have enough.." So there was no matching preimage with
> receiver as per Fig 4. So that means in the route say A->B->C->D, if D
> doesn't have a matching preimage and suppose C->D uses lock time of 144
> blocks, B->C 288 blocks and A->B uses a locktime of 432 blocks, so won't be
> the case funds in A->B and B->C still remains locked for the mentioned
> locktime?
>
> It is helpful to remember that inside a channel, every contract has an
> implicit branch "if both of us in this channel agree, we can spend this
> contract funds any way we want".
>
> This is because every contract is dependent on a transaction spending from
> a 2-of-2, and both parties can always sign a new 2-of-2 transaction without
> that contract --- it is just that both have to agree to do this.
>
> In case of a reported failure, the receiving node in the channel basically
> says "just between the two of us, I will not be able to claim this HTLC
> using the hashlock branch anyway because <BOLT 4 failure code reason>, so
> this will inevitably be claimable to you in the timelock anyway, so we
> might as well just agree to re-assign the HTLC funds back to you right now".
>
> The sending node is then willing to sign off on this
> outside-of-the-contract agreement, since it lets it get the funds back
> before the timelock expires, and to reuse those funds otherwise.
>
> Thus, even if D griefs up to 143 blocks it wants, at the 144th block C can
> report immediately back to B and then A with the above failure mechanism.
>
> B and C are incentivized to do this quickly since it would allow the funds
> to be reused again in a different, probably-will-not-be-griefed near-future
> payment, which might earn them fees in the future.
>
> Thus if B and C are not controlled by the A+D conglomerate then they have
> no incentive to extend the griefing attack further.
>
> Of course, if either B or C is offline at the time, then the new state
> where the HTLC is removed out-of-contract is not possible to sign with both
> parties.
>
> > I know this is not the definition of griefing attack but then can this
> possibly mimic the situation where receiver denies having the correct
> preimage?
>
> No, since B and C are incentivized to report this immediately in order to
> free up the funds in order for them to forward "soon".
>
> Regards,
> ZmnSCPxj
>
>