Skip to content
LearnBitcoin

ResearchBitcoin Dev Archive lightning-dev list

PTLCs early draft specification

16 messages, Dec 6 to 22, 2021. Started by Bastien TEINTURIER.

Bastien TEINTURIER (7), Anthony Towns (4), ZmnSCPxj (3), Lloyd Fournier (2)

Permalink First message in the Wayback Machine

Bastien TEINTURIER permalink original

Good morning list,

There was a great recent post on the mailing list detailing how we could do PTLCs on lightning with a lot of other goodies [0]. This proposal contained heavy changes to the transaction structure and the update protocol. While it's certainly something we'll want to do in the long run, I wanted to explore the minimal set of changes we would need to be able to deploy PTLCs as soon as possible.

The current result is a somewhat high-level article, where each section could be a separate update of the lightning protocol [1].

I tried to make PTLCs work with minimal changes to the transaction structure and the update protocol, but they introduce a fundamental change which forces us to make more changes than I'd like.

With HTLCs, the payment secret (the preimage of the payment hash) was directly revealed in the witness of a spending transaction.

With PTLCs, this isn't the case anymore. The payment secret is a private key, and a spending transaction only reveals that key if you have a matching adaptor signature. This forces us to make two changes:

1. We must obtain adaptor signatures before sending our commit_sig 2. We must use a pre-signed HTLC-success transaction not only with our local commit, but also with the remote commit

This means that we will need more round-trips whenever we update our commitment. I'd like to find the right design trade-off where we don't introduce too many changes in the protocol while minimizing the number of additional round-trips.

We currently exchange the following messages:

Alice                       Bob
      update_add_htlc
  --------------------------->
      update_add_htlc
  --------------------------->
      update_add_htlc
  --------------------------->
        commit_sig
  --------------------------->
       revoke_and_ack
  <---------------------------
        commit_sig
  <---------------------------
       revoke_and_ack
  --------------------------->

It works well because the commit_sig sent by Alice only contains signatures for Bob's transactions (commit and htlc transactions), and the commit_sig sent by Bob only contains signatures for Alice's transactions, and Alice and Bob don't need anything else to spend outputs from either commitment.

But with PTLCs, Bob needs a signature from Alice to be able to fulfill a PTLC from Alice's commitment. And Alice needs Bob to provide an adaptor signature for that transaction before she can give him her signature. We don't have the clean ordering that we had before.

The designs I came up with that keep the current messages and just insert new ones are either too costly (too many additional round-trips) or too complex (most likely broken in some edge cases).

I believe we need to change the commit_sig / revoke_and_ack protocol if we want to find the sweet spot I'm looking for. I'd like to collect ideas from this list's participants on how we could do that. This is probably something that should be bundled with option_simplified_commitment [2] (or at least we must ensure that option_simplified_commitment is a first step towards the protocol we'll need for PTLCs). It's also important to note that the protocol changes must work for both HTLCs and PTLCs, and shouldn't change the structure of the transactions (not more than the simple addition of PTLC outputs done in [1]).

Cheers, Bastien

[0] https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2021/lightning-over-taproot-with-ptlcs#m-40a44f51 [1] https://github.com/t-bast/lightning-docs/pull/16 [2] https://github.com/lightning/bolts/pull/867

ZmnSCPxj in reply to Bastien TEINTURIER permalink original

Good morning t-bast,

Long ago: https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2019/lightning-in-a-taproot-future#m-33c416be

And I quote:

Quoted text (39 lines)
>> A potential issue with MuSig is the increased number of communication rounds needed to generate signatures.
>
>I think you can reduce this via an alternative script path. In
>particular, if you want a script that the other guy can spend if they
>reveal the discrete log of point X, with musig you do:
>
>   P = H(H(A,B),1)*A + H(H(A,B),2)*B
>   [exchange H(RA),H(RB),RA,RB]
>
>   [send X]
>
>   sb = rb + H(RA+RB+X,P,m)*H(H(A,B),2)*b
>
>   [wait for sb]
>
>   sa = ra + H(RA+RB+X,P,m)*H(H(A,B),1)*a
>
>   [store RA+RB+X, sa+sb, supply sa, watch for sig]
>
>   sig = (RA+RB+X, sa+sb+x)
>
>So the 1.5 round trips are "I want to do a PTLC for X", "okay here's
>sb", "great, here's sa".
>
>But with taproot you can have a script path as well, so you could have a
>script:
>
>   A CHECKSIGVERIFY B CHECKSIG
>
>and supply a partial signature:
>
>   R+X,s,X where s = r + H(R+X,A,m)*a
>
>to allow them to satisfy "A CHECKSIGVERIFY" if they know the discrete
>log of X, and of course they can sign with B at any time. This is only
>half a round trip, and can be done at the same time as sending the "I
>want to do a PTLC for X" message to setup the (ultimately cheaper) MuSig
>spend. It's an extra signature on the sender's side and an extra verification
>on the receiver's side, but I think it works out fine.

It has been a while since I read that post, so my details may be fuzzy, but it looks possible as a way to reduce roundtrips, maybe?

Basically, if my memory and understanding are accurate, in the above, it is the *PTLC-offerrer* which provides an adaptor signature. That adaptor signature would be included in the `update_add_ptlc` message.

Does it become more workable that way?

Regards, ZmnSCPxj

Lloyd Fournier in reply to ZmnSCPxj permalink original

I was thinking along the same lines as Z. With MuSig2 and pre-sharing of signature nonces it should stay three rounds and share a similar structure.

On Tue, 7 Dec 2021 at 11:08, ZmnSCPxj via Lightning-dev < lightning-dev at lists.linuxfoundation.org> wrote:

Quoted text (5 lines)
>
> Basically, if my memory and understanding are accurate, in the above, it
> is the *PTLC-offerrer* which provides an adaptor signature.
> That adaptor signature would be included in the `update_add_ptlc` message.
>

Isn't it the case that all previous PTLC adaptor signatures need to be re-sent for each update_add_ptlc message because the signatures would no longer be valid once the commit tx changes. I think it's better to put it in `commitment_signed` if possible. This is what is done with pre-signed HTLC signatures at the moment anyway.

LL

ZmnSCPxj in reply to Lloyd Fournier permalink original

Good morning LL, and t-bast,

Quoted text (4 lines)
> > Basically, if my memory and understanding are accurate, in the above, it is the *PTLC-offerrer* which provides an adaptor signature.
> > That adaptor signature would be included in the `update_add_ptlc` message.
>
> Isn't it the case that all previous PTLC adaptor signatures need to be re-sent for each update_add_ptlc message because the signatures would no longer be valid once the commit tx changes. I think it's better to put it in `commitment_signed` if possible. This is what is done with pre-signed HTLC signatures at the moment anyway.

Agreed.

This is also avoided by fast-forwards, BTW, simply because fast-forwards delay the change of the commitment tx. It is another reason to consider fast-forwards, too....

Regards, ZmnSCPxj

Bastien TEINTURIER in reply to ZmnSCPxj permalink original

Hi Z, Lloyd,

Let's ignore the musig nonce exchanges for now. I believe these can be easily included in existing messages: they probably aren't the reason we need more round-trips (at least not the one I'm concerned about for now).

Quoted text (3 lines)
Basically, if my memory and understanding are accurate, in the above,
> it is the *PTLC-offerrer* which provides an adaptor signature.
> That adaptor signature would be included in the `update_add_ptlc` message.

Neat, you're completely right, I didn't realize that the adaptor signature could be completed by the other party, this is a great property I had missed. Thanks for pointing it out, it does simplify the protocol a lot!

I don't think you can include it in `update_add_ptlc` though, it has to be in `commitment_signed`, because if you do a batch of updates before signing, you would immediately invalidate the adaptor signatures you previously sent.

But it would be a simple change, where the signatures in `commitment_signed` would actually be adaptor signatures for PTLC-success transactions and normal signatures for PTLC-timeout transactions.

Quoted text (3 lines)
Isn't it the case that all previous PTLC adaptor signatures need to be
> re-sent for each update_add_ptlc message because the signatures would
> no longer be valid once the commit tx changes

Yes indeed, whenever the commitment changes, peers need to create new signatures and adaptor signatures for all pending PTLCs.

This is completely fine for PTLC-success and PTLC-timeout transactions, but we also need to exchange signatures for the new pre-signed transactions that spend a PTLC from the remote commitment. Let's call this new pre-signed transaction PTLC-remote-success (not a great name).

I believe these new transactions may require an additional round-trip. Let's take a very simple example, where we have one pending PTLC in each direction: PTLC_AB was offered by A to B and PTLC_BA was offered by B to A.

Now A makes some unrelated updates and wants to sign a new commitment. A cannot immediately send her `commitment_signed` to B. If she did, B would be able to broadcast this new commitment, and A would not be able to claim PTLC_BA from B's new commitment (even if she knew the payment secret) because she wouldn't have B's signature for the new PTLC-remote-success transaction.

So we first need B to send a new message `remote_ptlcs_signed` to A that contains B's adaptor signatures for the PTLC-remote-success transactions that would spend B's future commitment. After that A can safely send her `commitment_signed`. Similarly, A must send `remote_ptlcs_signed` to B before B can send its `commitment_signed`.

It's actually not that bad, we're only adding one message in each direction, and we're not adding more data (apart from nonces) to existing messages.

If you have ideas on how to avoid this new message, I'd be glad to hear them, hopefully I missed something again and we can make it better!

Thanks, Bastien

Le mar. 7 déc. 2021 à 09:04, ZmnSCPxj <ZmnSCPxj at protonmail.com> a écrit :

Quoted text (24 lines)
> Good morning LL, and t-bast,
>
> > > Basically, if my memory and understanding are accurate, in the above,
> it is the *PTLC-offerrer* which provides an adaptor signature.
> > > That adaptor signature would be included in the `update_add_ptlc`
> message.
> >
> > Isn't it the case that all previous PTLC adaptor signatures need to be
> re-sent for each update_add_ptlc message because the signatures would no
> longer be valid once the commit tx changes. I think it's better to put it
> in `commitment_signed` if possible. This is what is done with pre-signed
> HTLC signatures at the moment anyway.
>
> Agreed.
>
> This is also avoided by fast-forwards, BTW, simply because fast-forwards
> delay the change of the commitment tx.
> It is another reason to consider fast-forwards, too....
>
> Regards,
> ZmnSCPxj
>
>
>
ZmnSCPxj in reply to Bastien TEINTURIER permalink original

Good morning t-bast,

Quoted text (22 lines)
> I believe these new transactions may require an additional round-trip.
> Let's take a very simple example, where we have one pending PTLC in each
> direction: PTLC_AB was offered by A to B and PTLC_BA was offered by B to A.
>
> Now A makes some unrelated updates and wants to sign a new commitment.
> A cannot immediately send her `commitment_signed` to B.
> If she did, B would be able to broadcast this new commitment, and A would
> not be able to claim PTLC_BA from B's new commitment (even if she knew
> the payment secret) because she wouldn't have B's signature for the new
> PTLC-remote-success transaction.
>
> So we first need B to send a new message `remote_ptlcs_signed` to A that
> contains B's adaptor signatures for the PTLC-remote-success transactions
> that would spend B's future commitment. After that A can safely send her
> `commitment_signed`. Similarly, A must send `remote_ptlcs_signed` to B
> before B can send its `commitment_signed`.
>
> It's actually not that bad, we're only adding one message in each direction,
> and we're not adding more data (apart from nonces) to existing messages.
>
> If you have ideas on how to avoid this new message, I'd be glad to hear
> them, hopefully I missed something again and we can make it better!

`SIGHASH_NONE | SIGHASH_NOINPUT` (which will take another what, four years?) or a similar "covenant" opcode, such as `OP_CHECKTEMPLATEVERIFY` without any commitments or an `OP_CHECKSIGFROMSTACK` on an empty message. All you really need is a signature for an empty message, really...

Alternately, fast-forwards, which avoid this because it does not change commitment transactions on the payment-forwarding path. You only change commitment transactions once you have enough changes to justify collapsing them. Even in the aj formulation, when A adds a PTLC it only changes the transaction that hosts **only** A->B PTLCs as well as the A main output, all of which can be sent outright by A without changing any B->A PTLCs.

Basically... instead of a commitment tx like this:

                        +-------+
    funding outpoint -->|       |--> A main
                        |       |--> B main
                        |       |--> A->B PTLC
                        |       |--> B->A PTLC
                        +-------+

We could do this instead:

                        +-------+2of2  +-----+
    funding outpoint -->|       |----->|     |--> A main
                        |       |      |     |--> A->B PTLC
                        |       |      +-----+
                        |       |2or2  +-----+
                        |       |----->|     |--> B main
                        |       |      |     |--> B->A PTLC
                        +-------+      +-----+

Then whenever A wants to add a new A->B PTLC it only changes the tx inputs of the *other* A->B PTLCs without affecting the B->A PTLCs. Payment forwarding is fast, and you only change the "big" commitment tx rarely to clean up claimed and failed PTLCs, moving the extra messages out of the forwarding hot path.

But this is basically highly similar to what aj designed anyway, so...

Regards, ZmnSCPxj

Bastien TEINTURIER in reply to ZmnSCPxj permalink original

Hi Z,

Quoted text (6 lines)
`SIGHASH_NONE | SIGHASH_NOINPUT` (which will take another what, four
> years?) or a similar "covenant" opcode,

such as `OP_CHECKTEMPLATEVERIFY` without any commitments or an
> `OP_CHECKSIGFROMSTACK` on an empty message.
> All you really need is a signature for an empty message, really...
>

That fails my requirement of "deployable in 2022" :)

Same thing applies to fast-forwards: I do see their value, but I'd like to focus on a first version with minimal changes to the transaction structure and the update protocol, to ensure we can actually get agreement on it somewhat quickly and ship it in 2022. Then we can start working on a more ambitious rework of the protocol that adds a lot of cool features, such as what AJ proposed recently.

Cheers, Bastien

Le mer. 8 déc. 2021 à 00:52, ZmnSCPxj <ZmnSCPxj at protonmail.com> a écrit :

Quoted text (72 lines)
> Good morning t-bast,
>
>
> > I believe these new transactions may require an additional round-trip.
> > Let's take a very simple example, where we have one pending PTLC in each
> > direction: PTLC_AB was offered by A to B and PTLC_BA was offered by B to
> A.
> >
> > Now A makes some unrelated updates and wants to sign a new commitment.
> > A cannot immediately send her `commitment_signed` to B.
> > If she did, B would be able to broadcast this new commitment, and A would
> > not be able to claim PTLC_BA from B's new commitment (even if she knew
> > the payment secret) because she wouldn't have B's signature for the new
> > PTLC-remote-success transaction.
> >
> > So we first need B to send a new message `remote_ptlcs_signed` to A that
> > contains B's adaptor signatures for the PTLC-remote-success transactions
> > that would spend B's future commitment. After that A can safely send her
> > `commitment_signed`. Similarly, A must send `remote_ptlcs_signed` to B
> > before B can send its `commitment_signed`.
> >
> > It's actually not that bad, we're only adding one message in each
> direction,
> > and we're not adding more data (apart from nonces) to existing messages.
> >
> > If you have ideas on how to avoid this new message, I'd be glad to hear
> > them, hopefully I missed something again and we can make it better!
>
> `SIGHASH_NONE | SIGHASH_NOINPUT` (which will take another what, four
> years?) or a similar "covenant" opcode, such as `OP_CHECKTEMPLATEVERIFY`
> without any commitments or an `OP_CHECKSIGFROMSTACK` on an empty message.
> All you really need is a signature for an empty message, really...
>
> Alternately, fast-forwards, which avoid this because it does not change
> commitment transactions on the payment-forwarding path.
> You only change commitment transactions once you have enough changes to
> justify collapsing them.
> Even in the aj formulation, when A adds a PTLC it only changes the
> transaction that hosts **only** A->B PTLCs as well as the A main output,
> all of which can be sent outright by A without changing any B->A PTLCs.
>
> Basically... instead of a commitment tx like this:
>
>                         +-------+
>     funding outpoint -->|       |--> A main
>                         |       |--> B main
>                         |       |--> A->B PTLC
>                         |       |--> B->A PTLC
>                         +-------+
>
> We could do this instead:
>
>                         +-------+2of2  +-----+
>     funding outpoint -->|       |----->|     |--> A main
>                         |       |      |     |--> A->B PTLC
>                         |       |      +-----+
>                         |       |2or2  +-----+
>                         |       |----->|     |--> B main
>                         |       |      |     |--> B->A PTLC
>                         +-------+      +-----+
>
> Then whenever A wants to add a new A->B PTLC it only changes the tx inputs
> of the *other* A->B PTLCs without affecting the B->A PTLCs.
> Payment forwarding is fast, and you only change the "big" commitment tx
> rarely to clean up claimed and failed PTLCs, moving the extra messages out
> of the forwarding hot path.
>
> But this is basically highly similar to what aj designed anyway, so...
>
> Regards,
> ZmnSCPxj
>
Anthony Towns in reply to ZmnSCPxj permalink original

On Tue, Dec 07, 2021 at 11:52:04PM +0000, ZmnSCPxj via Lightning-dev wrote:

Quoted text (2 lines)
> Alternately, fast-forwards, which avoid this because it does not change commitment transactions on the payment-forwarding path.
> You only change commitment transactions once you have enough changes to justify collapsing them.

I think the problem t-bast describes comes up here as well when you collapse the fast-forwards (or, anytime you update the commitment transaction even if you don't collapse them).

That is, if you have two PTLCs, one from A->B conditional on X, one from B->A conditional on Y. Then if A wants to update the commitment tx, she needs to

  1) produce a signature to give to B to spend the funding tx
  2) produce an adaptor signature to authorise B to spend via X from his
     commitment tx
  3) produce a signature to allow B to recover Y after timeout from his
     commitment tx spending to an output she can claim if he cheats
  4) *receive* an adaptor signature from B to be able to spend the Y output
     if B posts his commitment tx using A's signature in (1)

The problem is, she can't give B the result of (1) until she's received (4) from B.

It doesn't matter if the B->A PTLC conditional on Y is in the commitment tx itself or within a fast-forward child-transaction -- any previous adaptor sig will be invalidated because there's a new commitment transaction, and if you allowed any way of spending without an adaptor sig, B wouldn't be able to recover the secret and would lose funds.

It also doesn't matter if the commitment transaction that A and B will publish is the same or different, only that it's different from the commitment tx that previous adaptor sigs committed to. (So ANYPREVOUT would fix this if it were available)

So I think this is still a relevant question, even if fast-forwards make it a rare problem, that perhaps is only applicable to very heavily used channels.

(I said the following in email to t-bast already)

I think doing a synchronous update of commitments to the channel state, something like:

   Alice -> Bob: propose_new_commitment
       channel id
       adaptor sigs for PTLCs to Bob
   Bob -> Alice: agree_new_commitment
       channel id
       adaptor sigs for PTLCs to Alice
       sigs for Alice to spend HTLCs and PTLCs to Bob from her own
         commitment tx
       signature for Alice to spend funding tx
   Alice -> Bob: finish_new_commitment_1
       channel id
       sigs for Bob to spend HTLCs and PTLCs to Alice from his own
         commitment tx
       signature for Bob to spend funding tx
       reveal old prior commitment secret
       new commitment nonce
   Bob -> Alice: finish_new_commitment_2
       reveal old prior commitment secret
       new commitment nonce

would work pretty well.

This adds half a round-trip compared to now:

   Alice -> Bob: commitment_signed
   Bob -> Alice: revoke_and_ack, commitment_signed
   Alice -> Bob: revoke_and_ack

The timings change like so:

  Bob can use the new commitment after 1.5 round-trips (previously 0.5)
  Alice can be sure Bob won't use the old commitment after 2 round-trips
  (previously 1)
  Alice can use the new commitment after 1 round-trip (unchanged)
  Bob can be sure Alice won't use the old commitment after 1.5 round-trips
  (unchanged -- note: this is what's relevant for forwarding)

Making the funding tx a musig setup would mean also supplying 64B of musig2 nonces along with the "adaptor sigs" in one direction, and providing the other side's 64B of musig2 nonces back along with the (now partial) signature for spending the funding tx (a total of 256B of nonce data, not 128B).

Because it keeps both peers' commitments synchronised to a single channel state, I think the same protocol should work fine with the revocable signatures on a single tx approach too, though I haven't tried working through the details.

Fast forwards would then be reducing the 2 round-trip protocol to update the state commitment to a 0.5 round-trip update, to reduce latency when forwarding by the same amount as before (1.5 round-trips to 0.5 round-trips).

Cheers, aj

Bastien TEINTURIER in reply to Anthony Towns permalink original

Hi AJ,

Quoted text (3 lines)
I think the problem t-bast describes comes up here as well when you
> collapse the fast-forwards (or, anytime you update the commitment
> transaction even if you don't collapse them).

Yes, exactly.

Quoted text (25 lines)
I think doing a synchronous update of commitments to the channel state,
> something like:

Alice -> Bob: propose_new_commitment
> channel id
> adaptor sigs for PTLCs to Bob

> Bob -> Alice: agree_new_commitment
> channel id
> adaptor sigs for PTLCs to Alice
> sigs for Alice to spend HTLCs and PTLCs to Bob from her own
> commitment tx
> signature for Alice to spend funding tx
>
> Alice -> Bob: finish_new_commitment_1
> channel id
> sigs for Bob to spend HTLCs and PTLCs to Alice from his own
> commitment tx
> signature for Bob to spend funding tx
> reveal old prior commitment secret
> new commitment nonce
>
> Bob -> Alice: finish_new_commitment_2
> reveal old prior commitment secret
> new commitment nonce
>
> would work pretty well.

I agree, this is better than my naive addition of a `remote_ptlcs_signed` message in both directions, and even though it changes the protocol messages it stays very close to the mechanisms we currently have.

I'll spend some time specifying this in more details, to verify that we're not missing anything. What I really like about this proposal is that we can probably bundle that protocol change with `option_simplified_update` [0] without the adaptor sigs, and simply add the adaptor sigs as tlvs when we do PTLCs. That lets us deploy this new update protocol separately from PTLCs and ensure it also simplifies the state machine and makes other features such as splicing [1] and dynamic channel upgrades [2] easier.

Thanks, Bastien

[0] https://github.com/lightning/bolts/pull/867
[1] https://github.com/lightning/bolts/pull/863
[2] https://github.com/lightning/bolts/pull/868

Le mer. 8 déc. 2021 à 10:29, Anthony Towns <aj at erisian.com.au> a écrit :

Quoted text (108 lines)
> On Tue, Dec 07, 2021 at 11:52:04PM +0000, ZmnSCPxj via Lightning-dev wrote:
> > Alternately, fast-forwards, which avoid this because it does not change
> commitment transactions on the payment-forwarding path.
> > You only change commitment transactions once you have enough changes to
> justify collapsing them.
>
> I think the problem t-bast describes comes up here as well when you
> collapse the fast-forwards (or, anytime you update the commitment
> transaction even if you don't collapse them).
>
> That is, if you have two PTLCs, one from A->B conditional on X, one
> from B->A conditional on Y. Then if A wants to update the commitment tx,
> she needs to
>
>   1) produce a signature to give to B to spend the funding tx
>   2) produce an adaptor signature to authorise B to spend via X from his
>      commitment tx
>   3) produce a signature to allow B to recover Y after timeout from his
>      commitment tx spending to an output she can claim if he cheats
>   4) *receive* an adaptor signature from B to be able to spend the Y output
>      if B posts his commitment tx using A's signature in (1)
>
> The problem is, she can't give B the result of (1) until she's received
> (4) from B.
>
> It doesn't matter if the B->A PTLC conditional on Y is in the commitment
> tx itself or within a fast-forward child-transaction -- any previous
> adaptor sig will be invalidated because there's a new commitment
> transaction, and if you allowed any way of spending without an adaptor
> sig, B wouldn't be able to recover the secret and would lose funds.
>
> It also doesn't matter if the commitment transaction that A and B will
> publish is the same or different, only that it's different from the
> commitment tx that previous adaptor sigs committed to. (So ANYPREVOUT
> would fix this if it were available)
>
> So I think this is still a relevant question, even if fast-forwards
> make it a rare problem, that perhaps is only applicable to very heavily
> used channels.
>
> (I said the following in email to t-bast already)
>
> I think doing a synchronous update of commitments to the channel state,
> something like:
>
>    Alice -> Bob: propose_new_commitment
>        channel id
>        adaptor sigs for PTLCs to Bob
>
>    Bob -> Alice: agree_new_commitment
>        channel id
>        adaptor sigs for PTLCs to Alice
>        sigs for Alice to spend HTLCs and PTLCs to Bob from her own
>          commitment tx
>        signature for Alice to spend funding tx
>
>    Alice -> Bob: finish_new_commitment_1
>        channel id
>        sigs for Bob to spend HTLCs and PTLCs to Alice from his own
>          commitment tx
>        signature for Bob to spend funding tx
>        reveal old prior commitment secret
>        new commitment nonce
>
>    Bob -> Alice: finish_new_commitment_2
>        reveal old prior commitment secret
>        new commitment nonce
>
> would work pretty well.
>
> This adds half a round-trip compared to now:
>
>    Alice -> Bob: commitment_signed
>    Bob -> Alice: revoke_and_ack, commitment_signed
>    Alice -> Bob: revoke_and_ack
>
> The timings change like so:
>
>   Bob can use the new commitment after 1.5 round-trips (previously 0.5)
>
>   Alice can be sure Bob won't use the old commitment after 2 round-trips
>   (previously 1)
>
>   Alice can use the new commitment after 1 round-trip (unchanged)
>
>   Bob can be sure Alice won't use the old commitment after 1.5 round-trips
>   (unchanged -- note: this is what's relevant for forwarding)
>
> Making the funding tx a musig setup would mean also supplying 64B
> of musig2 nonces along with the "adaptor sigs" in one direction,
> and providing the other side's 64B of musig2 nonces back along with the
> (now partial) signature for spending the funding tx (a total of 256B of
> nonce data, not 128B).
>
> Because it keeps both peers' commitments synchronised to a single channel
> state, I think the same protocol should work fine with the revocable
> signatures on a single tx approach too, though I haven't tried working
> through the details.
>
> Fast forwards would then be reducing the 2 round-trip protocol to
> update the state commitment to a 0.5 round-trip update, to reduce
> latency when forwarding by the same amount as before (1.5 round-trips
> to 0.5 round-trips).
>
> Cheers,
> aj
>
>
Bastien TEINTURIER in reply to Bastien TEINTURIER permalink original

Hi again AJ and list,

I have slightly re-worked your proposal, and came up with the following (I also added the musig2 nonces for completeness):

Alice -> Bob: commitment_proposed
    channel id
    adaptor sigs for PTLCs to Bob in Alice's next commitment
    musig nonces for Alice to spend funding tx
    musig nonces for Bob to spend funding tx
Bob -> Alice: commitment_proposed
    channel id
    adaptor sigs for PTLCs to Alice in Bob's next commitment
    musig nonces for Alice to spend funding tx
    musig nonces for Bob to spend funding tx
Bob -> Alice: commitment_signed
    channel id
    signature for Alice to spend funding tx
    sigs for Alice to spend HTLCs and PTLCs from her next commitment
Alice -> Bob: revoke_and_ack
    channel id
    reveal previous commitment secret
    next commitment point
Alice -> Bob: commitment_signed
    channel id
    signature for Bob to spend funding tx
    sigs for Bob to spend HTLCs and PTLCs from his next commitment
Bob -> Alice: revoke_and_ack
    channel id
    reveal previous commitment secret
    next commitment point

I believe it's exactly the same flow of data between peers as your proposal, but I simply split the data into several messages. Let me know if that's incorrect or if I missed a subtlety in your proposal.

This has some small advantages:

* commitment_signed and revoke_and_ack are mostly unchanged, we just add a new message before the commit / revoke dance. The only change happens in commitment_signed, where the signatures for PTLC-success transactions will actually become adaptor signatures. * the new adaptor signatures are in commitment_proposed instead of being in commitment_signed, which ensures that we can still have 2*483 pending (H|P)TLCs: since the message size is limited to 65kB, we would otherwise decrease our maximum to ~2*335 with your proposal (very rough calculation) * the messages are now symmetrical, which may be easier to reason about

One thing to note is that we reversed the order in which participants sign new commitments. We previously had Alice sign first, whereas now if Alice initiates, Bob will sign the updated commitment first. This is why we add only 0.5 RTT instead of 1 RTT compared to the current protocol. I don't think this is an issue, but if someone sees a way to maliciously exploit this, please share it!

I updated my article [0], people jumping on the thread now may find it helpful to better understand this discussion.

Thanks, Bastien

[0] https://github.com/t-bast/lightning-docs/pull/16

Le mer. 8 déc. 2021 à 11:00, Bastien TEINTURIER <bastien at acinq.fr> a écrit :

Quoted text (175 lines)
> Hi AJ,
>
> I think the problem t-bast describes comes up here as well when you
>> collapse the fast-forwards (or, anytime you update the commitment
>> transaction even if you don't collapse them).
>
>
> Yes, exactly.
>
> I think doing a synchronous update of commitments to the channel state,
>> something like:
>
>
>
> Alice -> Bob: propose_new_commitment
>> channel id
>> adaptor sigs for PTLCs to Bob
>
>
>> Bob -> Alice: agree_new_commitment
>> channel id
>> adaptor sigs for PTLCs to Alice
>> sigs for Alice to spend HTLCs and PTLCs to Bob from her own
>> commitment tx
>> signature for Alice to spend funding tx
>>
>> Alice -> Bob: finish_new_commitment_1
>> channel id
>> sigs for Bob to spend HTLCs and PTLCs to Alice from his own
>> commitment tx
>> signature for Bob to spend funding tx
>> reveal old prior commitment secret
>> new commitment nonce
>>
>> Bob -> Alice: finish_new_commitment_2
>> reveal old prior commitment secret
>> new commitment nonce
>>
>> would work pretty well.
>
>
> I agree, this is better than my naive addition of a `remote_ptlcs_signed`
> message in both directions, and even though it changes the protocol
> messages
> it stays very close to the mechanisms we currently have.
>
> I'll spend some time specifying this in more details, to verify that we're
> not missing anything. What I really like about this proposal is that we
> can probably bundle that protocol change with `option_simplified_update`
> [0]
> without the adaptor sigs, and simply add the adaptor sigs as tlvs when we
> do PTLCs. That lets us deploy this new update protocol separately from
> PTLCs
> and ensure it also simplifies the state machine and makes other features
> such as splicing [1] and dynamic channel upgrades [2] easier.
>
> Thanks,
> Bastien
>
> [0] https://github.com/lightning/bolts/pull/867
> [1] https://github.com/lightning/bolts/pull/863
> [2] https://github.com/lightning/bolts/pull/868
>
> Le mer. 8 déc. 2021 à 10:29, Anthony Towns <aj at erisian.com.au> a écrit :
>
>> On Tue, Dec 07, 2021 at 11:52:04PM +0000, ZmnSCPxj via Lightning-dev
>> wrote:
>> > Alternately, fast-forwards, which avoid this because it does not change
>> commitment transactions on the payment-forwarding path.
>> > You only change commitment transactions once you have enough changes to
>> justify collapsing them.
>>
>> I think the problem t-bast describes comes up here as well when you
>> collapse the fast-forwards (or, anytime you update the commitment
>> transaction even if you don't collapse them).
>>
>> That is, if you have two PTLCs, one from A->B conditional on X, one
>> from B->A conditional on Y. Then if A wants to update the commitment tx,
>> she needs to
>>
>>   1) produce a signature to give to B to spend the funding tx
>>   2) produce an adaptor signature to authorise B to spend via X from his
>>      commitment tx
>>   3) produce a signature to allow B to recover Y after timeout from his
>>      commitment tx spending to an output she can claim if he cheats
>>   4) *receive* an adaptor signature from B to be able to spend the Y
>> output
>>      if B posts his commitment tx using A's signature in (1)
>>
>> The problem is, she can't give B the result of (1) until she's received
>> (4) from B.
>>
>> It doesn't matter if the B->A PTLC conditional on Y is in the commitment
>> tx itself or within a fast-forward child-transaction -- any previous
>> adaptor sig will be invalidated because there's a new commitment
>> transaction, and if you allowed any way of spending without an adaptor
>> sig, B wouldn't be able to recover the secret and would lose funds.
>>
>> It also doesn't matter if the commitment transaction that A and B will
>> publish is the same or different, only that it's different from the
>> commitment tx that previous adaptor sigs committed to. (So ANYPREVOUT
>> would fix this if it were available)
>>
>> So I think this is still a relevant question, even if fast-forwards
>> make it a rare problem, that perhaps is only applicable to very heavily
>> used channels.
>>
>> (I said the following in email to t-bast already)
>>
>> I think doing a synchronous update of commitments to the channel state,
>> something like:
>>
>>    Alice -> Bob: propose_new_commitment
>>        channel id
>>        adaptor sigs for PTLCs to Bob
>>
>>    Bob -> Alice: agree_new_commitment
>>        channel id
>>        adaptor sigs for PTLCs to Alice
>>        sigs for Alice to spend HTLCs and PTLCs to Bob from her own
>>          commitment tx
>>        signature for Alice to spend funding tx
>>
>>    Alice -> Bob: finish_new_commitment_1
>>        channel id
>>        sigs for Bob to spend HTLCs and PTLCs to Alice from his own
>>          commitment tx
>>        signature for Bob to spend funding tx
>>        reveal old prior commitment secret
>>        new commitment nonce
>>
>>    Bob -> Alice: finish_new_commitment_2
>>        reveal old prior commitment secret
>>        new commitment nonce
>>
>> would work pretty well.
>>
>> This adds half a round-trip compared to now:
>>
>>    Alice -> Bob: commitment_signed
>>    Bob -> Alice: revoke_and_ack, commitment_signed
>>    Alice -> Bob: revoke_and_ack
>>
>> The timings change like so:
>>
>>   Bob can use the new commitment after 1.5 round-trips (previously 0.5)
>>
>>   Alice can be sure Bob won't use the old commitment after 2 round-trips
>>   (previously 1)
>>
>>   Alice can use the new commitment after 1 round-trip (unchanged)
>>
>>   Bob can be sure Alice won't use the old commitment after 1.5 round-trips
>>   (unchanged -- note: this is what's relevant for forwarding)
>>
>> Making the funding tx a musig setup would mean also supplying 64B
>> of musig2 nonces along with the "adaptor sigs" in one direction,
>> and providing the other side's 64B of musig2 nonces back along with the
>> (now partial) signature for spending the funding tx (a total of 256B of
>> nonce data, not 128B).
>>
>> Because it keeps both peers' commitments synchronised to a single channel
>> state, I think the same protocol should work fine with the revocable
>> signatures on a single tx approach too, though I haven't tried working
>> through the details.
>>
>> Fast forwards would then be reducing the 2 round-trip protocol to
>> update the state commitment to a 0.5 round-trip update, to reduce
>> latency when forwarding by the same amount as before (1.5 round-trips
>> to 0.5 round-trips).
>>
>> Cheers,
>> aj
>>
>>
Lloyd Fournier in reply to Bastien TEINTURIER permalink original

Hi thread,

I was indeed mistaken. It does require four rounds for both parties to fully transition to the next comimit tx and I don't think there is any easy way around this. As you've pointed out there it's still only three rounds before the message is forwarded so no performance decrease for forwarding.

I wanted to add a theoretical note that you might be aware of. The final message "Bob -> Alice: revoke_and_ack" is not strictly necessary. Alice does not care about Bob revoking a commit tx that gives her strictly more coins. Bob's new commit tx can use the same revocation key as the previous one i.e. only the offerer of the PTLC/HTLC does a revocation and increments their revocation key. Not sending messages you don't need to is usually both more performant and simpler but given that it introduces some asymmetry so I'm not sure if it's worth it. It's also worth noting that with fast forwards + symmetric commit tx you will need to do the full four rounds always I think.

Cheers,

LL

On Thu, 9 Dec 2021 at 02:03, Bastien TEINTURIER <bastien at acinq.fr> wrote:

Quoted text (252 lines)
> Hi again AJ and list,
>
> I have slightly re-worked your proposal, and came up with the following
> (I also added the musig2 nonces for completeness):
>
> Alice -> Bob: commitment_proposed
>     channel id
>     adaptor sigs for PTLCs to Bob in Alice's next commitment
>     musig nonces for Alice to spend funding tx
>     musig nonces for Bob to spend funding tx
>
> Bob -> Alice: commitment_proposed
>     channel id
>     adaptor sigs for PTLCs to Alice in Bob's next commitment
>     musig nonces for Alice to spend funding tx
>     musig nonces for Bob to spend funding tx
>
> Bob -> Alice: commitment_signed
>     channel id
>     signature for Alice to spend funding tx
>     sigs for Alice to spend HTLCs and PTLCs from her next commitment
>
> Alice -> Bob: revoke_and_ack
>     channel id
>     reveal previous commitment secret
>     next commitment point
>
> Alice -> Bob: commitment_signed
>     channel id
>     signature for Bob to spend funding tx
>     sigs for Bob to spend HTLCs and PTLCs from his next commitment
>
> Bob -> Alice: revoke_and_ack
>     channel id
>     reveal previous commitment secret
>     next commitment point
>
> I believe it's exactly the same flow of data between peers as your
> proposal, but I simply split the data into several messages. Let me
> know if that's incorrect or if I missed a subtlety in your proposal.
>
> This has some small advantages:
>
> * commitment_signed and revoke_and_ack are mostly unchanged, we just
> add a new message before the commit / revoke dance. The only change
> happens in commitment_signed, where the signatures for PTLC-success
> transactions will actually become adaptor signatures.
> * the new adaptor signatures are in commitment_proposed instead of being
> in commitment_signed, which ensures that we can still have 2*483
> pending (H|P)TLCs: since the message size is limited to 65kB, we would
> otherwise decrease our maximum to ~2*335 with your proposal (very rough
> calculation)
> * the messages are now symmetrical, which may be easier to reason about
>
> One thing to note is that we reversed the order in which participants
> sign new commitments. We previously had Alice sign first, whereas now
> if Alice initiates, Bob will sign the updated commitment first. This is
> why we add only 0.5 RTT instead of 1 RTT compared to the current protocol.
> I don't think this is an issue, but if someone sees a way to maliciously
> exploit this, please share it!
>
> I updated my article [0], people jumping on the thread now may find it
> helpful to better understand this discussion.
>
> Thanks,
> Bastien
>
> [0] https://github.com/t-bast/lightning-docs/pull/16
>
> Le mer. 8 déc. 2021 à 11:00, Bastien TEINTURIER <bastien at acinq.fr> a
> écrit :
>
>> Hi AJ,
>>
>> I think the problem t-bast describes comes up here as well when you
>>> collapse the fast-forwards (or, anytime you update the commitment
>>> transaction even if you don't collapse them).
>>
>>
>> Yes, exactly.
>>
>> I think doing a synchronous update of commitments to the channel state,
>>> something like:
>>
>>
>>
>> Alice -> Bob: propose_new_commitment
>>> channel id
>>> adaptor sigs for PTLCs to Bob
>>
>>
>>> Bob -> Alice: agree_new_commitment
>>> channel id
>>> adaptor sigs for PTLCs to Alice
>>> sigs for Alice to spend HTLCs and PTLCs to Bob from her own
>>> commitment tx
>>> signature for Alice to spend funding tx
>>>
>>> Alice -> Bob: finish_new_commitment_1
>>> channel id
>>> sigs for Bob to spend HTLCs and PTLCs to Alice from his own
>>> commitment tx
>>> signature for Bob to spend funding tx
>>> reveal old prior commitment secret
>>> new commitment nonce
>>>
>>> Bob -> Alice: finish_new_commitment_2
>>> reveal old prior commitment secret
>>> new commitment nonce
>>>
>>> would work pretty well.
>>
>>
>> I agree, this is better than my naive addition of a `remote_ptlcs_signed`
>> message in both directions, and even though it changes the protocol
>> messages
>> it stays very close to the mechanisms we currently have.
>>
>> I'll spend some time specifying this in more details, to verify that we're
>> not missing anything. What I really like about this proposal is that we
>> can probably bundle that protocol change with `option_simplified_update`
>> [0]
>> without the adaptor sigs, and simply add the adaptor sigs as tlvs when we
>> do PTLCs. That lets us deploy this new update protocol separately from
>> PTLCs
>> and ensure it also simplifies the state machine and makes other features
>> such as splicing [1] and dynamic channel upgrades [2] easier.
>>
>> Thanks,
>> Bastien
>>
>> [0] https://github.com/lightning/bolts/pull/867
>> [1] https://github.com/lightning/bolts/pull/863
>> [2] https://github.com/lightning/bolts/pull/868
>>
>> Le mer. 8 déc. 2021 à 10:29, Anthony Towns <aj at erisian.com.au> a écrit :
>>
>>> On Tue, Dec 07, 2021 at 11:52:04PM +0000, ZmnSCPxj via Lightning-dev
>>> wrote:
>>> > Alternately, fast-forwards, which avoid this because it does not
>>> change commitment transactions on the payment-forwarding path.
>>> > You only change commitment transactions once you have enough changes
>>> to justify collapsing them.
>>>
>>> I think the problem t-bast describes comes up here as well when you
>>> collapse the fast-forwards (or, anytime you update the commitment
>>> transaction even if you don't collapse them).
>>>
>>> That is, if you have two PTLCs, one from A->B conditional on X, one
>>> from B->A conditional on Y. Then if A wants to update the commitment tx,
>>> she needs to
>>>
>>>   1) produce a signature to give to B to spend the funding tx
>>>   2) produce an adaptor signature to authorise B to spend via X from his
>>>      commitment tx
>>>   3) produce a signature to allow B to recover Y after timeout from his
>>>      commitment tx spending to an output she can claim if he cheats
>>>   4) *receive* an adaptor signature from B to be able to spend the Y
>>> output
>>>      if B posts his commitment tx using A's signature in (1)
>>>
>>> The problem is, she can't give B the result of (1) until she's received
>>> (4) from B.
>>>
>>> It doesn't matter if the B->A PTLC conditional on Y is in the commitment
>>> tx itself or within a fast-forward child-transaction -- any previous
>>> adaptor sig will be invalidated because there's a new commitment
>>> transaction, and if you allowed any way of spending without an adaptor
>>> sig, B wouldn't be able to recover the secret and would lose funds.
>>>
>>> It also doesn't matter if the commitment transaction that A and B will
>>> publish is the same or different, only that it's different from the
>>> commitment tx that previous adaptor sigs committed to. (So ANYPREVOUT
>>> would fix this if it were available)
>>>
>>> So I think this is still a relevant question, even if fast-forwards
>>> make it a rare problem, that perhaps is only applicable to very heavily
>>> used channels.
>>>
>>> (I said the following in email to t-bast already)
>>>
>>> I think doing a synchronous update of commitments to the channel state,
>>> something like:
>>>
>>>    Alice -> Bob: propose_new_commitment
>>>        channel id
>>>        adaptor sigs for PTLCs to Bob
>>>
>>>    Bob -> Alice: agree_new_commitment
>>>        channel id
>>>        adaptor sigs for PTLCs to Alice
>>>        sigs for Alice to spend HTLCs and PTLCs to Bob from her own
>>>          commitment tx
>>>        signature for Alice to spend funding tx
>>>
>>>    Alice -> Bob: finish_new_commitment_1
>>>        channel id
>>>        sigs for Bob to spend HTLCs and PTLCs to Alice from his own
>>>          commitment tx
>>>        signature for Bob to spend funding tx
>>>        reveal old prior commitment secret
>>>        new commitment nonce
>>>
>>>    Bob -> Alice: finish_new_commitment_2
>>>        reveal old prior commitment secret
>>>        new commitment nonce
>>>
>>> would work pretty well.
>>>
>>> This adds half a round-trip compared to now:
>>>
>>>    Alice -> Bob: commitment_signed
>>>    Bob -> Alice: revoke_and_ack, commitment_signed
>>>    Alice -> Bob: revoke_and_ack
>>>
>>> The timings change like so:
>>>
>>>   Bob can use the new commitment after 1.5 round-trips (previously 0.5)
>>>
>>>   Alice can be sure Bob won't use the old commitment after 2 round-trips
>>>   (previously 1)
>>>
>>>   Alice can use the new commitment after 1 round-trip (unchanged)
>>>
>>>   Bob can be sure Alice won't use the old commitment after 1.5
>>> round-trips
>>>   (unchanged -- note: this is what's relevant for forwarding)
>>>
>>> Making the funding tx a musig setup would mean also supplying 64B
>>> of musig2 nonces along with the "adaptor sigs" in one direction,
>>> and providing the other side's 64B of musig2 nonces back along with the
>>> (now partial) signature for spending the funding tx (a total of 256B of
>>> nonce data, not 128B).
>>>
>>> Because it keeps both peers' commitments synchronised to a single channel
>>> state, I think the same protocol should work fine with the revocable
>>> signatures on a single tx approach too, though I haven't tried working
>>> through the details.
>>>
>>> Fast forwards would then be reducing the 2 round-trip protocol to
>>> update the state commitment to a 0.5 round-trip update, to reduce
>>> latency when forwarding by the same amount as before (1.5 round-trips
>>> to 0.5 round-trips).
>>>
>>> Cheers,
>>> aj
>>>
>>> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
>
Anthony Towns in reply to Lloyd Fournier permalink original

On Thu, Dec 09, 2021 at 12:34:00PM +1100, Lloyd Fournier wrote:

Quoted text (4 lines)
> I wanted to add a theoretical note that you might be aware of. The final
> message "Bob -> Alice: revoke_and_ack" is not strictly necessary. Alice
> does not care about Bob revoking a commit tx that gives her strictly more
> coins.

That's true if Alice is only sending new tx's paying Bob; and Rusty's examples in the `option_simplified_update` proposal do only include new HTLCs...

But I think it's intended to cover *all* update messages, and if Alice is also including any `update_fulfill_htlc` or `update_fail_htlc` messages in the commitment, she's potentially gaining funds, both for the amount of fees she saves by avoiding extra transactions, but for the fulfill case, potentially also because she doesn't need to worry about the fulfilled htlc reaching its timeout.

Actually, as an alternative to the `option_simplified_update` approach, has anyone considered an approach more like this:

 * each node can unilaterally send various messages that always update
   the state, eg:
     + new htlc/ptlc paying the other node (update_add_htlc)
     + secret reveal of htlc/ptlc paying self (update_fulfil_htlc)
     + rejection of htlc/ptlc paying self (update_fail_htlc)
     + timeout of htlc/ptlc paying the other node (not currently allowed?)
     + update the channel fee rate (update_fee)
 * continue to allow these to occur at any time, asynchronously, but
   to make it easier to keep track of them, add a uint64_t counter
   to each message, that each peer increments by 1 for each message.
 * each channel state (n) then corresponds to the accumulation of
   updates from each each peer, up to message (a) for Alice, and message
   (b) for Bob.
 * so when updating to a new commitment (n+1), the proposal message
   should just include both update values (a') and (b')
 * nodes can then track the state by having a list of
   htlcs/ptlcs/balances, etc for state (n), and a list of unapplied
   update messages for themselves and the other party (a+1,...,a') and
   (b+1,...,b'), and apply them in order when constructing the new state
   (n+1) for a new commitment signing round

I think that retains both the interesting async bits (anyone can queue state updates immediately) but also makes it fairly simple to maintain the state?

Quoted text (2 lines)
> Bob's new commit tx can use the same revocation key as the previous
> one

That's a neat idea, but I think the fail/fulfill messages break it. _But_ I think that means it would still be an interesting technique to use for fast forwards which get updated for every add message...

Quoted text (2 lines)
> Not sending messages you don't need to is usually
> both more performant and simpler

The extra message from Bob allows Alice to discard the adaptor sigs associated with the old state, which I think is probably worthwhile anyway?

Cheers, aj

Anthony Towns in reply to Bastien TEINTURIER permalink original

On Wed, Dec 08, 2021 at 04:02:02PM +0100, Bastien TEINTURIER wrote:

Quoted text (3 lines)
> I updated my article [0], people jumping on the thread now may find it
> helpful to better understand this discussion.
> [0] https://github.com/t-bast/lightning-docs/pull/16

Since merged, so https://github.com/t-bast/lightning-docs/blob/master/taproot-updates.md

So imagine that this proposal is finished and widely adopted/deployed and someone adds an additional feature bit that allows a channel to forward PTLCs only, no HTLCs.

Then suppose that you forget every old PTLC, because you don't like having your channel state grow without bound. What happens if your counterparty broadcasts an old state?

 * the musig2 channel funding is irrelevant -- the funding tx has been
   spend at this point
 * the unspent commitment outputs pay to:
     to_local: ipk = musig(revkey, mykey) -- known ; scripts also known
     to_remote: claimable in 1 block, would be better if ipk was also musig
     *_anchor: dust, who cares -- might be better if local_anchor used
        key = revkey
     *_htlc: irrelevant by definition
     local_ptlc: ipk = musig(revkey, mykey) -- known; scripts also known
 * commitment outputs may be immediately spent via layered txs. if so,
   their outputs are: ipk = musig(revkey, mykey); with fixed scripts,
   that include a relative timelock

So provided you know the revocation key (which you do, because it's an old transaction and that only requires log(states) data to reconstruct) and your own private key, you can reconstruct all the scripts and use key path spends for every output immediately (excepting the local_anchor, and to_remote is delayed by a block).

So while this doesn't achieve eltoo's goal of "no toxic waste", I believe it does achieve the goal of "state information is bounded no matter how long you leave the channel open / how many transactions travel over the channel".

(Provided you're willing to wait for the other party to attempt to claim a htlc via their layered transaction, you can use this strategy for htlcs as well as ptlcs -- however this leaves you the risk that they never attempt to claim the funds, which may leave you out of pocket, and may give them the opportunity to do an attack along the lines of "you don't get access to the $10,000 locked in old HTLCs unless you pay me $1,000". So I don't think that's really a smart thing to do)

Cheers, aj

Bastien TEINTURIER in reply to Anthony Towns permalink original

Hey AJ and list,

That's a very good point, it's really worth highlighting!

The reason we have "toxic waste" with HTLCs is because we commit to the payment_hash directly inside the transaction scripts, so we need to remember all the payment_hash we've seen to be able to recreate the scripts (and spend the outputs, even if they are revoked).

But with PTLCs, we commit to a payment_point outside of the scripts (in the adaptor signature that is exchanged), so we're able to recreate the scripts independently of the payment details! This also means that the payment_point never appears on-chain (which is good for privacy) whereas the payment_hash does appear on-chain for HTLCs.

Quoted text (2 lines)
*_anchor: dust, who cares -- might be better if local_anchor used key =
> revkey

I don't think we can use revkey, this would prevent us from bumping the current remote commitment if it appears on-chain (because we don't know the private revkey yet if this is the latest commitment). Usually the remote peer should bump it, but if they don't, we may want to bump it ourselves instead of publishing our own commitment (where our main output has a long CSV).

But as you already mentioned, who cares, it's dust and we don't even need it to CPFP the revoked commitment, we can use any other output since the revocation path isn't encumbered with a CSV 1.

Cheers, Bastien

Le dim. 19 déc. 2021 à 23:23, Anthony Towns <aj at erisian.com.au> a écrit :

Quoted text (54 lines)
> On Wed, Dec 08, 2021 at 04:02:02PM +0100, Bastien TEINTURIER wrote:
> > I updated my article [0], people jumping on the thread now may find it
> > helpful to better understand this discussion.
> > [0] https://github.com/t-bast/lightning-docs/pull/16
>
> Since merged, so
> https://github.com/t-bast/lightning-docs/blob/master/taproot-updates.md
>
> So imagine that this proposal is finished and widely adopted/deployed
> and someone adds an additional feature bit that allows a channel to
> forward PTLCs only, no HTLCs.
>
> Then suppose that you forget every old PTLC, because you don't like
> having your channel state grow without bound. What happens if your
> counterparty broadcasts an old state?
>
>  * the musig2 channel funding is irrelevant -- the funding tx has been
>    spend at this point
>
>  * the unspent commitment outputs pay to:
>      to_local: ipk = musig(revkey, mykey) -- known ; scripts also known
>      to_remote: claimable in 1 block, would be better if ipk was also musig
>      *_anchor: dust, who cares -- might be better if local_anchor used
>         key = revkey
>      *_htlc: irrelevant by definition
>      local_ptlc: ipk = musig(revkey, mykey) -- known; scripts also known
>
>  * commitment outputs may be immediately spent via layered txs. if so,
>    their outputs are: ipk = musig(revkey, mykey); with fixed scripts,
>    that include a relative timelock
>
> So provided you know the revocation key (which you do, because it's an
> old transaction and that only requires log(states) data to reconstruct)
> and your own private key, you can reconstruct all the scripts and use
> key path spends for every output immediately (excepting the local_anchor,
> and to_remote is delayed by a block).
>
> So while this doesn't achieve eltoo's goal of "no toxic waste", I believe
> it does achieve the goal of "state information is bounded no matter
> how long you leave the channel open / how many transactions travel over
> the channel".
>
> (Provided you're willing to wait for the other party to attempt to claim
> a htlc via their layered transaction, you can use this strategy for
> htlcs as well as ptlcs -- however this leaves you the risk that they
> never attempt to claim the funds, which may leave you out of pocket,
> and may give them the opportunity to do an attack along the lines of
> "you don't get access to the $10,000 locked in old HTLCs unless you pay
> me $1,000".  So I don't think that's really a smart thing to do)
>
> Cheers,
> aj
>
>
Anthony Towns in reply to Bastien TEINTURIER permalink original

On Tue, Dec 21, 2021 at 04:25:41PM +0100, Bastien TEINTURIER wrote:

Quoted text (4 lines)
> The reason we have "toxic waste" with HTLCs is because we commit to the
> payment_hash directly inside the transaction scripts, so we need to
> remember all the payment_hash we've seen to be able to recreate the
> scripts (and spend the outputs, even if they are revoked).

I think "toxic waste" refers to having old data around that, if used, could cause you to lose all the funds in your channel -- that's why it's toxic. This is more just regular landfill :)

Quoted text (3 lines)
> *_anchor: dust, who cares -- might be better if local_anchor used key =
> > revkey
> I don't think we can use revkey,
musig(revkey, remote_key)
  --> allows them to spend after you've revealed the secret for revkey
      you can never spend because you'll never know the secret for
      remote_key

but if you just say:

(revkey)

then you can spend (because you know revkey) immediately (because it's an anchor output, so intended to be immediately spent) or they can spend if it's an obsolete commitment and you've revealed the revkey secret.

Quoted text (6 lines)
> this would prevent us from bumping the
> current remote commitment if it appears on-chain (because we don't know
> the private revkey yet if this is the latest commitment). Usually the
> remote peer should bump it, but if they don't, we may want to bump it
> ourselves instead of publishing our own commitment (where our main
> output has a long CSV).

If we're going to bump someone else's commitment, we'll use the remote_anchor they provided, not the local_anchor, so I think this is fine (as long as I haven't gotten local/remote confused somewhere along the way).

Cheers, aj

Bastien TEINTURIER in reply to Anthony Towns permalink original

Hey AJ,

Right, I was probably confused between local/remote, especially when we're talking about our anchor in the remote commitment (should it be called local anchor, which is from our point of view, or remote?).

Let's call them Alice and Bob, and Bob is publishing a commitment. Correct me if I'm wrong there, what you're suggesting is that:

* Bob's anchor on Bob's commitment can be spent with revkey
* Alice's anchor on Bob's commitment can be spent with Alice's pubkey

This does ensure that each participant is able to claim their anchor in the latest commitment, and Alice is able to claim both anchors in any of Bob's outdated commitments.

But I think it defeats the `OP_16 OP_CHECKSEQUENCEVERIFY` script branch. We have that branch to allow anyone to spend anchor outputs *after* the commitment is confirmed, to avoid keeping them around in the utxo set forever. However, the trick is that the internal pubkey must be set to something that is publicly revealed when the channel closes. Now that we put the revkey in internal pubkeys everywhere instead of script branches, that revkey is *not* revealed when channels close with the latest commit. So it would prevent people from using that script branch to clean up the utxo set...

I have currently used <local_delayedpubkey> and <remote_pubkey> because they're revealed whenever main outputs are claimed, but there is probably a smarter solution (maybe one that would let us use revkey here as you suggest), this will be worth thinking about a bit more.

Thanks, Bastien

Le mar. 21 déc. 2021 à 17:04, Anthony Towns <aj at erisian.com.au> a écrit :

Quoted text (43 lines)
> On Tue, Dec 21, 2021 at 04:25:41PM +0100, Bastien TEINTURIER wrote:
> > The reason we have "toxic waste" with HTLCs is because we commit to the
> > payment_hash directly inside the transaction scripts, so we need to
> > remember all the payment_hash we've seen to be able to recreate the
> > scripts (and spend the outputs, even if they are revoked).
>
> I think "toxic waste" refers to having old data around that, if used,
> could cause you to lose all the funds in your channel -- that's why it's
> toxic. This is more just regular landfill :)
>
> > *_anchor: dust, who cares -- might be better if local_anchor used key =
> > > revkey
> > I don't think we can use revkey,
>
> musig(revkey, remote_key)
>   --> allows them to spend after you've revealed the secret for revkey
>       you can never spend because you'll never know the secret for
>       remote_key
>
> but if you just say:
>
> (revkey)
>
> then you can spend (because you know revkey) immediately (because it's
> an anchor output, so intended to be immediately spent) or they can spend
> if it's an obsolete commitment and you've revealed the revkey secret.
>
> > this would prevent us from bumping the
> > current remote commitment if it appears on-chain (because we don't know
> > the private revkey yet if this is the latest commitment). Usually the
> > remote peer should bump it, but if they don't, we may want to bump it
> > ourselves instead of publishing our own commitment (where our main
> > output has a long CSV).
>
> If we're going to bump someone else's commitment, we'll use the
> remote_anchor they provided, not the local_anchor, so I think this is
> fine (as long as I haven't gotten local/remote confused somewhere along
> the way).
>
> Cheers,
> aj
>
>