Skip to content
LearnBitcoin

ResearchBitcoin Dev Archive lightning-dev list

BOLT #3: Shouldn't timeout be included in the script of "Offered HTLC Outputs" for the local node?

6 messages, Jun 5, 2019. Started by Ugam Kamat.

Ugam Kamat (4), Pierre, Nadav Kohen

Permalink First message in the Wayback Machine

Ugam Kamat permalink original

Hey guys,

I know this question is not right for this mailing list, but I have tried asking it on Stackexchange <https://bitcoin.stackexchange.com/questions/88100/bolt-3-shouldnt-timeout-b e-included-in-the-script-of-offered-htlc-outputs-f> (even offered a bounty) and didn't get a response as of yet. So here's the question: According to the BOLT #3 documentation, <https://github.com/lightningnetwork/lightning-rfc/blob/master/03-transactio ns.md#offered-htlc-outputs> the offered HTLC output has the following script that allows the remote node to claim the funds with the payment pre-image and the local node to claim it after a HTLC timeout.

1.  # To remote node with revocation key
2.  OP_DUP OP_HASH160 <RIPEMD160(SHA256(revocationpubkey))> OP_EQUAL
3.  OP_IF
4.      OP_CHECKSIG
5.  OP_ELSE
6.      <remote_htlcpubkey> OP_SWAP OP_SIZE 32 OP_EQUAL
7.      OP_NOTIF
8.          # To local node via HTLC-timeout transaction (timelocked).
9.          OP_DROP 2 OP_SWAP <local_htlcpubkey> 2 OP_CHECKMULTISIG
10.      OP_ELSE
11.         # To remote node with preimage.
12.         OP_HASH160 <RIPEMD160(payment_hash)> OP_EQUALVERIFY
13.         OP_CHECKSIG
14.      OP_ENDIF
15. OP_ENDIF

If you see the output that sends the funds to the local node (line 7-9), it is not timelocked in the script. What is said is that that part is delayed in the second stage using to_self_delay. However, a local node after signing this commitment transaction, which includes the HTLC he offered, can broadcast it to claim the bitcoins from the HTLC-timeout (he already has the signatures) and pays to an address although with to_self_delay.

Although the delay exists in the 2nd stage (CSV locked with to_self_delay), nothing stops me from offering a htlc to my peer node, sign the updated commitment transaction and a second later broadcast the commitment transaction on mainchain and spend the HTLC to an address locked with CSV. The remote node will still forward the htlc because from its viewpoint it is still within the bounds of the cltv_expiry as specified by BOLTs. Now, when the remote node gets the pre-image it doesn't have any transaction to settle with. Where is the shortcoming in my though process and isn't timelock expiry something that should be included in the script itself?

Ugam

Pierre in reply to Ugam Kamat permalink original

Hello Ugam,

The HTLC-Timeout transaction <https://github.com/lightningnetwork/lightning-rfc/blob/master/03-transactions.md#htlc-timeout-and-htlc-success-transactions> is timelocked (with locktime=cltv_expiry).

Cheers,

Pierre

Ugam Kamat in reply to Pierre permalink original

Hey Pierre,

That’s what I am having a hard time understanding. Although it is timelocked in the second stage HTLC-timeout, I can still spend the original commitment transaction although after some time. This is what my thought process is:

*	Offer the Htlc output and sign the commitment transactions
*	Broadcast the commitment transaction containing the offered HTLC outputs to the main chain. The outputs of commitment tx are: (1) to remote; (2) to local with to_self_delay and (3) to P2WSH (the script I pasted earlier)
*	Commitment transaction gets mined
*	Spend the third output using 0 <remotehtlcsig> <localhtlcsig> 0 in the witness stack which will send the outputs to <local_delayed_pubkey> using to_self_delay

Now I think when you say the HTLC time out transaction is timelocked, you are referring the to the to_self_delay when spending the htlc-timeout. But although there is that timeout, the commitment transaction is already broadcasted, and the P2WSH output is already sent to my public key (although with a delay I can still spend that without my counterparty’s assent). Now, my counterparty on the other hand when he gets the pre-image, does not have the P2WSH output to claim his bitcoins with the pre-image because it has been already locked with my <local_delayed_pubkey> which I can spend when the to_senf_delay` is over

Ugam

From: Pierre <pm+lists at acinq.fr> Sent: Wednesday, June 5, 2019 9:35 PM To: Ugam Kamat <ugamkamat1 at gmail.com> Cc: lightning-dev <lightning-dev at lists.linuxfoundation.org> Subject: Re: [Lightning-dev] BOLT #3: Shouldn't timeout be included in the script of "Offered HTLC Outputs" for the local node?

Quoted text (3 lines, sent without quote marks)
Hello Ugam,

The HTLC-Timeout transaction <https://github.com/lightningnetwork/lightning-rfc/blob/master/03-transactions.md#htlc-timeout-and-htlc-success-transactions>  is timelocked (with locktime=cltv_expiry).

Cheers,

Pierre

Ugam Kamat in reply to Ugam Kamat permalink original

Ah, now I see what you mean, it is locked with absolute timelock and hence I cannot broadcast that transaction. My apologies and thanks for the help!

Ugam

From: Ugam Kamat <ugamkamat1 at gmail.com> Sent: Wednesday, June 5, 2019 10:00 PM To: 'Pierre' <pm+lists at acinq.fr> Cc: 'lightning-dev' <lightning-dev at lists.linuxfoundation.org> Subject: RE: [Lightning-dev] BOLT #3: Shouldn't timeout be included in the script of "Offered HTLC Outputs" for the local node?

Hey Pierre,

That’s what I am having a hard time understanding. Although it is timelocked in the second stage HTLC-timeout, I can still spend the original commitment transaction although after some time. This is what my thought process is:

*	Offer the Htlc output and sign the commitment transactions
*	Broadcast the commitment transaction containing the offered HTLC outputs to the main chain. The outputs of commitment tx are: (1) to remote; (2) to local with to_self_delay and (3) to P2WSH (the script I pasted earlier)
*	Commitment transaction gets mined
*	Spend the third output using 0 <remotehtlcsig> <localhtlcsig> 0 in the witness stack which will send the outputs to <local_delayed_pubkey> using to_self_delay

Now I think when you say the HTLC time out transaction is timelocked, you are referring the to the to_self_delay when spending the htlc-timeout. But although there is that timeout, the commitment transaction is already broadcasted, and the P2WSH output is already sent to my public key (although with a delay I can still spend that without my counterparty’s assent). Now, my counterparty on the other hand when he gets the pre-image, does not have the P2WSH output to claim his bitcoins with the pre-image because it has been already locked with my <local_delayed_pubkey> which I can spend when the to_senf_delay` is over

Ugam

From: Pierre <pm+lists at acinq.fr <mailto:pm+lists at acinq.fr> > Sent: Wednesday, June 5, 2019 9:35 PM To: Ugam Kamat <ugamkamat1 at gmail.com <mailto:ugamkamat1 at gmail.com> > Cc: lightning-dev <lightning-dev at lists.linuxfoundation.org <mailto:lightning-dev at lists.linuxfoundation.org> > Subject: Re: [Lightning-dev] BOLT #3: Shouldn't timeout be included in the script of "Offered HTLC Outputs" for the local node?

Quoted text (3 lines, sent without quote marks)
Hello Ugam,

The HTLC-Timeout transaction <https://github.com/lightningnetwork/lightning-rfc/blob/master/03-transactions.md#htlc-timeout-and-htlc-success-transactions>  is timelocked (with locktime=cltv_expiry).

Cheers,

Pierre

Nadav Kohen in reply to Ugam Kamat permalink original

Hi Ugam,

I also ran into an issue understanding this a while back, here's a PR I opened to try and make things more clear: https://github.com/lightningnetwork/lightning-rfc/pull/601 Feel free to add to it or comment if you think things could be improved :)

Best, Nadav

On Wed, Jun 5, 2019 at 11:33 AM Ugam Kamat <ugamkamat1 at gmail.com> wrote:

Quoted text (86 lines)
> Ah, now I see what you mean, it is locked with absolute timelock and hence
> I cannot broadcast that transaction. My apologies and thanks for the help!
>
>
>
> Ugam
>
>
>
> *From:* Ugam Kamat <ugamkamat1 at gmail.com>
> *Sent:* Wednesday, June 5, 2019 10:00 PM
> *To:* 'Pierre' <pm+lists at acinq.fr>
> *Cc:* 'lightning-dev' <lightning-dev at lists.linuxfoundation.org>
> *Subject:* RE: [Lightning-dev] BOLT #3: Shouldn't timeout be included in
> the script of "Offered HTLC Outputs" for the local node?
>
>
>
> Hey Pierre,
>
>
>
> That’s what I am having a hard time understanding. Although it is
> timelocked in the second stage HTLC-timeout, I can still spend the original
> commitment transaction although after some time. This is what my thought
> process is:
>
>
>
>    - Offer the Htlc output and sign the commitment transactions
>    - Broadcast the commitment transaction containing the offered HTLC
>    outputs to the main chain. The outputs of commitment tx are: (1) to remote;
>    (2) to local with to_self_delay and (3) to P2WSH (the script I pasted
>    earlier)
>    - Commitment transaction gets mined
>    - Spend the third output using 0 <remotehtlcsig> <localhtlcsig> 0 in
>    the witness stack which will send the outputs to <local_delayed_pubkey>
>    using to_self_delay
>
> Now I think when you say the HTLC time out transaction is timelocked, you
> are referring the to the to_self_delay when spending the htlc-timeout. But
> although there is that timeout, the commitment transaction is already
> broadcasted, and the P2WSH output is already sent to my public key
> (although with a delay I can still spend that without my counterparty’s
> assent). Now, my counterparty on the other hand  when he gets the
> pre-image, does not have the P2WSH output to claim his bitcoins with the
> pre-image because it has been already locked with my <local_delayed_pubkey>
> which I can spend when the to_senf_delay` is over
>
>
>
> Ugam
>
>
>
> *From:* Pierre <pm+lists at acinq.fr>
> *Sent:* Wednesday, June 5, 2019 9:35 PM
> *To:* Ugam Kamat <ugamkamat1 at gmail.com>
> *Cc:* lightning-dev <lightning-dev at lists.linuxfoundation.org>
> *Subject:* Re: [Lightning-dev] BOLT #3: Shouldn't timeout be included in
> the script of "Offered HTLC Outputs" for the local node?
>
>
>
> Hello Ugam,
>
>
>
> The HTLC-Timeout transaction
> <https://github.com/lightningnetwork/lightning-rfc/blob/master/03-transactions.md#htlc-timeout-and-htlc-success-transactions>
> is timelocked (with locktime=cltv_expiry).
>
>
>
> Cheers,
>
>
>
> Pierre
>
>
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
>
Ugam Kamat in reply to Nadav Kohen permalink original

Hey Nadav, that’s a good call as it’s not particularly intuitive when you try to read it. I’ll try to add to it if I can. Thanks!

Ugam

From: Nadav Kohen <nadav at suredbits.com> Sent: Wednesday, June 5, 2019 10:08 PM To: Ugam Kamat <ugamkamat1 at gmail.com> Cc: Pierre <pm+lists at acinq.fr>; lightning-dev <lightning-dev at lists.linuxfoundation.org> Subject: Re: [Lightning-dev] BOLT #3: Shouldn't timeout be included in the script of "Offered HTLC Outputs" for the local node?

Quoted text (4 lines, sent without quote marks)
Hi Ugam,

I also ran into an issue understanding this a while back, here's a PR I opened to try and make things more clear: https://github.com/lightningnetwork/lightning-rfc/pull/601

Feel free to add to it or comment if you think things could be improved :)

Best,

Nadav

On Wed, Jun 5, 2019 at 11:33 AM Ugam Kamat <ugamkamat1 at gmail.com <mailto:ugamkamat1 at gmail.com> > wrote:

Ah, now I see what you mean, it is locked with absolute timelock and hence I cannot broadcast that transaction. My apologies and thanks for the help!

Ugam

From: Ugam Kamat <ugamkamat1 at gmail.com <mailto:ugamkamat1 at gmail.com> > Sent: Wednesday, June 5, 2019 10:00 PM To: 'Pierre' <pm+lists at acinq.fr <mailto:pm%2Blists at acinq.fr> > Cc: 'lightning-dev' <lightning-dev at lists.linuxfoundation.org <mailto:lightning-dev at lists.linuxfoundation.org> > Subject: RE: [Lightning-dev] BOLT #3: Shouldn't timeout be included in the script of "Offered HTLC Outputs" for the local node?

Hey Pierre,

That’s what I am having a hard time understanding. Although it is timelocked in the second stage HTLC-timeout, I can still spend the original commitment transaction although after some time. This is what my thought process is:

*	Offer the Htlc output and sign the commitment transactions
*	Broadcast the commitment transaction containing the offered HTLC outputs to the main chain. The outputs of commitment tx are: (1) to remote; (2) to local with to_self_delay and (3) to P2WSH (the script I pasted earlier)
*	Commitment transaction gets mined
*	Spend the third output using 0 <remotehtlcsig> <localhtlcsig> 0 in the witness stack which will send the outputs to <local_delayed_pubkey> using to_self_delay

Now I think when you say the HTLC time out transaction is timelocked, you are referring the to the to_self_delay when spending the htlc-timeout. But although there is that timeout, the commitment transaction is already broadcasted, and the P2WSH output is already sent to my public key (although with a delay I can still spend that without my counterparty’s assent). Now, my counterparty on the other hand when he gets the pre-image, does not have the P2WSH output to claim his bitcoins with the pre-image because it has been already locked with my <local_delayed_pubkey> which I can spend when the to_senf_delay` is over

Ugam

From: Pierre <pm+lists at acinq.fr <mailto:pm+lists at acinq.fr> > Sent: Wednesday, June 5, 2019 9:35 PM To: Ugam Kamat <ugamkamat1 at gmail.com <mailto:ugamkamat1 at gmail.com> > Cc: lightning-dev <lightning-dev at lists.linuxfoundation.org <mailto:lightning-dev at lists.linuxfoundation.org> > Subject: Re: [Lightning-dev] BOLT #3: Shouldn't timeout be included in the script of "Offered HTLC Outputs" for the local node?

Quoted text (3 lines, sent without quote marks)
Hello Ugam,

The HTLC-Timeout transaction <https://github.com/lightningnetwork/lightning-rfc/blob/master/03-transactions.md#htlc-timeout-and-htlc-success-transactions>  is timelocked (with locktime=cltv_expiry).

Cheers,

Pierre