Skip to content
LearnBitcoin

ResearchBitcoin Dev Archive lightning-dev list

Lightning in a Taproot future

14 messages, Dec 15, 2019, to Jan 27, 2020. Started by ZmnSCPxj.

ZmnSCPxj (8), David A. Harding (3), Matt Corallo, Anthony Towns, Lloyd Fournier

Permalink First message in the Wayback Machine

ZmnSCPxj permalink original

Good morning list,

I would like to initiate some discussion on how Lightning could be updated to take advantage of the upcoming taproot update to the base layer.

For now, I am assuming the continued use of the existing Poon-Dryja update mechanism. Decker-Russell-Osuntokun requires `SIGHASH_NOINPUT`/`SIGHASH_ANYPREVOUT`, and its details seem less settled for now than taproot details.

* [ ] We could update the current Poon-Dryja mechanism to use Schnorr signatures.
* [ ] Or we could just keep the current Poon-Dryja mechanism with SegWit v0 only, and only update to Schnorr / SegWit v1 when we can implement Decker-Russell-Osuntokun.
  * This brings up the question as to whether we will allow Poon-Dryja to host pointlocked-timelocked contracts (i.e. the Scriptless Script replacement of HTLCs that uses payment points+scalars).
    * [ ] We could constrain Poon-Dryja channels to only HTLCs.
      * This might be simpler for implementations: implementations could have a completely new module that implements Decker-Russell-Osuntokun with HTLCs and PTLCs, and not touch existing modules for Poon-Dryja with HTLCs only.
      * We could "retire" Poon-Dryja constructions at some point and only add new features to Decker-Russell-Osuntokun channels.
    * [ ] We could allow hosting PTLCs as well on Poon-Dryja channels, as nothing in the base layer prevents a transaction from providing both SegWit v0 and SegWit v1 outputs anyway.

Poon-Dryja with Schnorr -----------------------

If we decide to update the current Poon-Dryja mechanism to use Schnorr, there are some wrinkles:

* [ ] We could just drop-in replace the signing algorithm with Schnorr.
  * We would define a NUMS point to be used as Taproot internal key, and use a single tapscript that is simply the current script template.
  * This is arguably not really taking advantage of the Schnorr and Taproot features, however.
* [ ] Or we could use some sort of MuSig between the two channel participants.

The latter option is probably what we want to use, as it potentially allows a channel close to be indistinguishable from an ordinary SegWit v1 spend of a UTXO. Even for channels that have been published via gossip, it moves the onus of storing historical data about historically-published channels from base layer fullnodes to nodes that want to surveill the network.

### Digression: 2-of-2 is Obviously Lightning

Existing 2-of-2 outputs have a very high probability of being Lightning Network channels. Thus, someone who wishes to surveill the Lightning Network can simply query any archive fullnode for historical 2-of-2 outputs and have a good chance that those are Lightning Network channels.

Consider the adage: Never go to sea with two chronometers; take one or three. https://en.wikipedia.org/wiki/Dual_modular_redundancy This implies that ordinary HODL usage of transaction outputs will either use 1-of-1, or 2-of-3.

Offchain techniques, on the other hand, are only safe (trustless) if they are n-of-n, and are only usefully multi-participant if n > 1. https://zmnscpxj.github.io/offchain/safety.html Thus any n-of-n is likely to be an offchain protocol, with the most likely being the most widespread offchain protocol, Lightning Network.

Thus, the hyperbole "2-of-2 is Obviously Lightning".

However, we can "hide" 2-of-2 in a 2-of-3, which can be done by generating a third point from a NUMS point plus a random tweak generated by both participants. Better yet, MuSig allows hiding any n-of-n among 1-of-1; we expect 1-of-1 use to dominate in the foreseeable future, thus MuSig usage maximizes our anonymity set.

### End Digression

A potential issue with MuSig is the increased number of communication rounds needed to generate signatures.

In the current Poon-Dryja setup we have, in order to completely sign the commitment transaction held by one participant, we only require sending a completed signature from the remote participant via `commitment_signed`. Then the local participant issues a `revoke_and_ack` to reassure the remote side that the previous commitment it held is now revoked. Thus, the signing itself requires only 0.5 round trips.

MuSig requires three rounds to complete the signing protocol. Since Poon-Dryja only require the complete set of signatures for any particular commitment transaction to be owned by only one participant (i.e. Poon-Dryja commitment transactions are asymmetrical), MuSig only requires 2.5 round trips to sign a Poon-Dryja commitment.

Reducing the round trips is desirable when considering latency, which affects the experienced speed of forwarding, as well as the backwards propagation of failures (but not of successful payments). Currently, latency on the network is known to be very low, but I observe that most Lightning Network participants today have excellent Internet connectivity, which might not be true in the foreseeable future.

We can reduce the round trips to 1.5 per commitment, except for the initial commitment transaction, by sending the `R` precommitments (the first phase of MuSig) of the *next* signing session while sending the `s` for the *current* signing session.

Finally, we can consider to reduce the use of MuSig via various techniques. One technique is the use of fast forwards: https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2019/improving-payment-latency-by-fast-forwards#m-403939fc

The other involves using Taproot. The taproot internal pubkey is the MuSig of both participants, but we also add an explicit 2-of-2 as a tapscript (or hide the 2-of-2 in a 2-of-3), i.e. `<A> OP_CHECKSIGVERIFY <B> OP_CHECKSIG` in a tapscript. This allows commitment transactions to use the tapscript path and have separate signatures for both participants. Then, mutual close uses the MuSig keypath spend. This reduces the changes relative to the current Poon-Dryja implementation: we can continue to use `commitment_signed` messages (or equivalent new ones for Taproot-based Poon-Dryja channels), and only the mutual close ritual needs to be modified to use MuSig.

Thus the options are below, but ***please do not select an option yet***, because further sections greatly affect the tradeoffs of the options below.

* [ ] Latency is not an issue (even in the foreseeable future), just use the 2.5 round trips for MuSig and MuSig-sign every commitment.
* [ ] Pre-send the `R` commitments with the previous `s`.
  * This increases the needed storage requirements of both nodes, and possibly complexity of node software, but reduces the round trips to 1.5.
  * This usage may need to have larger bounds than what may be naively expected, if we decide to use Multi-`R` composable MuSig (see later section).
  * Even *without* this option, at the minimum we still need to store `R` commitments and `R`, at least in memory, until we complete the MuSig ritual.
* [ ] Use fast-forwards.
  * This removes the latency of commitment transaction signing from the forwarding and failure-reporting paths.
    * *Improved* forwarding and failure-reporting latency compared to today (revocation and signature not needed for forwarding/failure-reporting).
  * Latency is still high for commitment transaction signing, but this is less of an issue as it is no longer in the forwarding/failure-reporting path.
* [ ] Explicit 2-of-2 for commitment, MuSig for mutual close.
  * No degradation in latency compared to today (0.5 round trips for signature, additional 1 round trip for signalling and revocation).
  * No improvement (or degradation) of privacy for unilateral closes compared to today, but improved privacy for mutual closes.
    * An argument *for* this option is that unilateral closes (commitment transactions) have special scripts on their outputs anyway, thus still leak their privacy, but see later sections for how Taproot may help reduce the uniqueness of those outputs, thus *not* taking this option may still improve privacy for unilateral closes.

Composable MuSig ----------------

As I describe here: https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2019-November/017493.html

In that write-up, I mention the use-case of nodelets. Another use-case is for redundant hardware signers: https://lists.ozlabs.org/pipermail/c-lightning/2019-December/000172.html

We have the option of allowing for a composable MuSig, probably my multi-`R` proposal, where each participant may send one or more `R` commitments and subsequent `R`s.

* [ ] Not use composable MuSig of any kind, at least for now.
  * Possibly we could defer the use of a composable MuSig when a better composable MuSig (with security proofs) has been derived.
* [ ] Use Multi-`R` composable MuSig.
  * We need to probably impose some limit on the number of `R` commitments that can be sent: _____ `R`s maximum.

The latter option above affects the previous choice regarding whether to pre-send `R` commitments with the previous `s` sending, as this increases the maximal storage requirement for the pre-sent `R` commitment(s).

Pointlocked Timelocked Contracts --------------------------------

I would have preferred to keep this in a separate discussion thread, however the exact details of PTLCs may affect our decision on how to sign commitment transactions.

PTLCs are necessary to switch the Lightning Network to payment point+scalar, and indeed one can argue that the entire point of enabling Schnorr and Taproot at the base layer is to allow us to use payment point+scalar at the Lightning layer.

First, I will discuss how to create a certain kind of PTLCs, which I call "purely scriptless" PTLCs. In particular, I would like to point out that we *actually* use in current Poon-Dryja Lightning Network channels is *revocable* HTLCs, thus we need to have *revocable* PTLCs to replace them.

* First, we must have a sender A, who is buying a secret scalar, and knows the point equivalent to that scalar.
* Second, we have a receiver B, who knows this secret scalar (or can somehow learn this secret scalar).
* A and B agree on the specifications of the PTLC: the point, the future absolute timelock, the value.
* A creates (but *does not* sign or broadcast) a transaction that pays to a MuSig of A and B and shares the txid and output number with the relevant MuSig output.
* A and B create a backout transaction.
  * This backout has an `nLockTime` equal to the agreed absolute timelock.
  * It spends the above MuSig output (this input must enable `nLockTime`, e.g. by setting `nSequence` to `0xFFFFFFFE`).
  * It creates an output that is solely controlled by A.
* A and B perform a MuSig ritual to sign the backout transaction.
* A now signs and broadcast the first transaction, the one that has an output that represents the PTLC.
* A and B wait for the above transaction to confirm deeply.
  This completes the setup phase for the PTLC.
* After this point, if the agreed-upon locktime is reached, A broadcasts the backout transaction and aborts the ritual.
* A and B create a claim transaction.
  * This has an `nLockTime` of 0, or a present or past blockheight, or disabled `nLockTime`.
  * This spends the above MuSig output.
  * This creates an output that is solely controlled by B.
* A and B generate an adaptor signature for the claim transaction, which reveals the agreed scalar.
  * This is almost entirely a MuSig ritual, except at `s` exchange, B provides `t + r + h(R | MuSig(A,B) | m) * MuSigTweak(A, B, B) * b` first, then demands `r + h(R | MuSig(A,B) | m) * MuSigTweak(A, B, A) * a` from A, then reveals `r + h(R | MuSig(A,B) | m) * MuSigTweak(A, B, B) * b` (or the completed signature, by publishing onchain), revealing the secret scalar `t` to A.
* A is able to learn the secret scalar from the above adaptor signature followed by the full signature, completing the ritual.

Note that the above ritual is "purely scriptless". It is possible to take advantage of taproot to create a tapscript equivalent to `<agreed locktime> OP_CHECKLOCKTIMEVERIFY OP_DROP <A> OP_CHECKSIG`. This removes the need to perform a MuSig ritual to sign a backout transaction: A can generate the backout transaction all by itself. This use is not purely scriptless, as the timelocked branch is controlled by a tapscript that is hidden in the pointlocked branch, meaning that taking the timelocked branch reveals the contract.

The tradeoff is that if we use "purely scriptless" PTLCs:

* If we have purely scriptless PTLCs, then even the timelock branch is potentially indistinguishable from ordinary spends.
  * We should note that Bitcoin Core itself already uses the current blockheight plus 1 for `nLockTime` when spending, instead of a 0 or disabled `nLockTime`.
  * If the above habit were more widespread (i.e. if all wallets implemented the use of a current `nLockTime` for ordinary onchain spends) then the timelock branch has an anonymity set equal to all Schnorr keypath spends, as the `nLockTime` is always used anyway.
  * Other kinds of offchain protocols may also utilize this technique, slightly increasing the anonymity set as well.
    Thus, the use of the current blockheight plus 1 for `nLockTime` should be recommended for improved privacy in Bitcoin anyway.
* However, purely scriptless PTLCs require a complete MuSig ritual (2.5 to 3 round trips!) to sign the timelocked branch (the initial backout transaction); this increases the latency of adding new PTLCs.
  * Of note is that in the case of Lightning, we may need to add a new PTLC while another PTLC is *still* in-flight; on the new commitment transaction, we need to redo the MuSig rituals to create new backouts and new adaptor signtures for each PTLC.
    * This can be amortized such that we redo all the rituals for all existing PTLCs in parallel.
      * The use of multi-`R` composable MuSig greatly increases the storage requirements as well!
  * Further, the privacy gained in the timelock path is degraded or lost when we consider revocable PTLCs and revocable outputs.
  * It is not clear to me as fo now if the MuSig ritual for the backout transaction must complete in full before the MuSig ritual for the claim transaction (the pointlocked branch, which includes sharing an adaptor signature during `s` exchange).
    * If we can do these two rituals in parallel, this reduces the latency disadvantage of the purely scriptless PTLC to just 1 round trip compared to the tapscripted timelock branch PTLC.
    * Possibly the adaptor signature ritual could stop until B provides the adaptor signature, then full `s` exchange is deferred to after the PTLC 2-of-2 is instantiated onchain/reified in a commitment transaction.

Thus our options are the below, but again, you should defer deciding on the best option until you understand about revocable PTLCs.

* [ ] We can use a purely scriptless PTLC construction.
  * Better privacy, but increased latency.
* [ ] We can use a tapscripted timelock branch and a keypath pointlocked branch for the PTLC.
  * Lower latency, but possibly reduced privacy advantage in the timelock branch (privacy advantage still exists in the pointlocked branch, which we hope is more common anyway).

Revocable Outputs and PTLCs ---------------------------

Poon-Dryja mechanism is based on revocation of contracts instantiated from previous states. Thus, all outputs of Poon-Dryja must be made revocable.

At a high-enough level, this only requires the addition of a `(revocation_secret && remote_secret) || (CSV && L)` to the top-level logic (`L`) of a contract.
Of course, the details have the devil.

Now, in Poon-Dryja, each side of the channel has its own commitment transaction. Thus, contracts on the commitment transaction refer to a "local side" and a "remote side". The "local side" is whoever is holding the completely-signed commitment transaction, while the "remote side" is the other side.

Revocable outputs always have a CSV-requirement before the output can be spent by whoever "should" own the output, according to the contract details. The revocation secret is known by the local side, and then when a *new* commitment transaction has been signed, the revocation secret is given by the local side to the remote side, allowing all outputs to be spent directly by the remote side if an old, revoked commitment transaction is published onchain.

There are many ways to implement revocable outputs. The core idea of revocable outputs, however, is that there must exist some relative-locktime branch on each output that goes to the local side. This relative-locktime branch can be implemented as "purely scriptless" by using a 2-of-2 of both the local and remote sides, with a relative-locktime `nSequence`, using the same technique as described in the previous section.

However, unlike the absolute-locktime `nLockTime` for the timelock branches of PTLCs, ***there is no current wallet software that uses activated-relative-locktime `nSequence` for ordinary spends***. Thus, any use of the relative-locktime branch does *not* have a privacy advantage under purely scriptless.

Thus the tradeoffs here are different, and definitely in favor of the tapscripted-relative-locktime technique.

* There is no current wallet software that uses relative locktimes.
  * Bitcoin Core uses absolute locktimes with the current blockheight plus 1, and we can hide the use of absolute locktimes by imitating this Bitcoin Core behavior.
  * Any use of relative locktimes is a strong signal of some kind of complicated offchain updateable mechanism.
    We can note as well that Decker-Russell-Osuntokun also uses relative locktimes.
* The relative-locktime branch in revocable outputs is the **desirable** case, because taking the relative locktime means that the commitment transaction published *was not* a revoked transaction (i.e. it was the latest transaction version).
  * Thus, it would be nice if this had good privacy.
  * However, this *cannot* have good privacy since there is no current common use of activated relative locktimes for ordinary spends.

The latter point above also biases us towards rejecting purely-scriptless in the *previous* section, in particular:

* The absolute-locktime branch in the PTLC is the **undesirable** case, where the payee B somehow stops responding to A.
  * In particular, propagating failure backwards is done by simply deleting PTLCs, thus the absolute-locktime branch does not come into play during payment failure.
  * Thus, the privacy increase of hiding absolute-locktime branches is minor, and the privacy breach of revocable outputs (i.e. it leaks the use of relative-locktime, and nearly all uses of relative locktime will be offchain updateable cryptocurrency mechanisms, such as Poon-Dryja or Decker-Russell-Osuntokun) is arguably much larger than the privacy increase of purely-scriptless absolute-locktime.

Of particular not is that if a PTLC is instantiated on the commitment transaction of the payer A, then the absolute-locktime backout transaction must *not* pay to A only, but instead pays to a *revocable output* that will eventually pay to A after the relative locktime. Thus, the privacy boost of the purely-scriptless backout transaction would be lost by the later revelation of the use of a relative locktime after the revocable output is reclaimed by A. Again, that use of relative locktime (whether enforced by script, or by scriptless use of a 2-of-2 that is spent with an activated relative-locktime `nSequence`) is a strong indicator of the use of Poon-Dryja or Decker-Russell-Osuntokun or even Decker-Wattenhofer mechanisms, and the logic is that since Lightning Network is the most widespread offchain mechanism, it probably indicates the use of LN.

Thus the decision in the previous section is affected by this reality that we in fact need *revocable* PTLCs, not plain PTLCs, thus the advantage of purely-scriptless backout transactions in the previous section is reduced by the need to make outputs revocable.

Thus:

* Revocable outputs require a relative-timelock branch.
* That branch is the **desirable** branch, i.e. the latest commitment transaction is the one that got published and thus is *not* revoked.
  * We thus expect this relative-timelock branch to be the *common* branch.
* No wallet uses relative-timelock for ordinary spends, unlike abolute-locktime where Bitcoin Core always uses absolute-locktime `nLockTime` for ordinary spends.
  * Thus, using purely scriptless for the relative-timelock branch of revocable outputs does not in fact hide that we are doing something special.

Conclusion ----------

Others may find further issues or alternative options for the above points. Further discussion may be warranted before we actually select particular options to implement and evaluate in alpha software.

Regards, ZmnSCPxj

Matt Corallo in reply to ZmnSCPxj permalink original

Given the timeline for soft forks to activate on Bitcoin, I don't know why we'd be super conservative about using new features of the Bitcoin consensus rules. I think obviously we'd want to rush as fast as we can into adding real cross-hop privacy to lightning payments, given both the number of awkward edge cases it introduces into the protocol, and the massive privacy leak.

Changing the underlying commitment transaction structure *could* come later, as it is, indeed, lower priority (and then the rule would be "taproot outputs are always lightning" for some time anyway), but, if you're changing things kinda why not.

Of course once you get privacy across routing hops, the importance of privacy-preserving routing algorithm work and fixing some other privacy holes is probably more important, so I could be dissuaded.

Matt

On 12/15/19 3:43 PM, ZmnSCPxj via Lightning-dev wrote:

Quoted text (230 lines)
> Good morning list,
>
> I would like to initiate some discussion on how Lightning could be updated to take advantage of the upcoming taproot update to the base layer.
>
> For now, I am assuming the continued use of the existing Poon-Dryja update mechanism.
> Decker-Russell-Osuntokun requires `SIGHASH_NOINPUT`/`SIGHASH_ANYPREVOUT`, and its details seem less settled for now than taproot details.
>
> * [ ] We could update the current Poon-Dryja mechanism to use Schnorr signatures.
> * [ ] Or we could just keep the current Poon-Dryja mechanism with SegWit v0 only, and only update to Schnorr / SegWit v1 when we can implement Decker-Russell-Osuntokun.
>   * This brings up the question as to whether we will allow Poon-Dryja to host pointlocked-timelocked contracts (i.e. the Scriptless Script replacement of HTLCs that uses payment points+scalars).
>     * [ ] We could constrain Poon-Dryja channels to only HTLCs.
>       * This might be simpler for implementations: implementations could have a completely new module that implements Decker-Russell-Osuntokun with HTLCs and PTLCs, and not touch existing modules for Poon-Dryja with HTLCs only.
>       * We could "retire" Poon-Dryja constructions at some point and only add new features to Decker-Russell-Osuntokun channels.
>     * [ ] We could allow hosting PTLCs as well on Poon-Dryja channels, as nothing in the base layer prevents a transaction from providing both SegWit v0 and SegWit v1 outputs anyway.
>
> Poon-Dryja with Schnorr
> -----------------------
>
> If we decide to update the current Poon-Dryja mechanism to use Schnorr, there are some wrinkles:
>
> * [ ] We could just drop-in replace the signing algorithm with Schnorr.
>   * We would define a NUMS point to be used as Taproot internal key, and use a single tapscript that is simply the current script template.
>   * This is arguably not really taking advantage of the Schnorr and Taproot features, however.
> * [ ] Or we could use some sort of MuSig between the two channel participants.
>
> The latter option is probably what we want to use, as it potentially allows a channel close to be indistinguishable from an ordinary SegWit v1 spend of a UTXO.
> Even for channels that have been published via gossip, it moves the onus of storing historical data about historically-published channels from base layer fullnodes to nodes that want to surveill the network.
>
> ### Digression: 2-of-2 is Obviously Lightning
>
> Existing 2-of-2 outputs have a very high probability of being Lightning Network channels.
> Thus, someone who wishes to surveill the Lightning Network can simply query any archive fullnode for historical 2-of-2 outputs and have a good chance that those are Lightning Network channels.
>
> Consider the adage: Never go to sea with two chronometers; take one or three.
> https://en.wikipedia.org/wiki/Dual_modular_redundancy
> This implies that ordinary HODL usage of transaction outputs will either use 1-of-1, or 2-of-3.
>
> Offchain techniques, on the other hand, are only safe (trustless) if they are n-of-n, and are only usefully multi-participant if n > 1.
> https://zmnscpxj.github.io/offchain/safety.html
> Thus any n-of-n is likely to be an offchain protocol, with the most likely being the most widespread offchain protocol, Lightning Network.
>
> Thus, the hyperbole "2-of-2 is Obviously Lightning".
>
> However, we can "hide" 2-of-2 in a 2-of-3, which can be done by generating a third point from a NUMS point plus a random tweak generated by both participants.
> Better yet, MuSig allows hiding any n-of-n among 1-of-1; we expect 1-of-1 use to dominate in the foreseeable future, thus MuSig usage maximizes our anonymity set.
>
> ### End Digression
>
> A potential issue with MuSig is the increased number of communication rounds needed to generate signatures.
>
> In the current Poon-Dryja setup we have, in order to completely sign the commitment transaction held by one participant, we only require sending a completed signature from the remote participant via `commitment_signed`.
> Then the local participant issues a `revoke_and_ack` to reassure the remote side that the previous commitment it held is now revoked.
> Thus, the signing itself requires only 0.5 round trips.
>
> MuSig requires three rounds to complete the signing protocol.
> Since Poon-Dryja only require the complete set of signatures for any particular commitment transaction to be owned by only one participant (i.e. Poon-Dryja commitment transactions are asymmetrical), MuSig only requires 2.5 round trips to sign a Poon-Dryja commitment.
>
> Reducing the round trips is desirable when considering latency, which affects the experienced speed of forwarding, as well as the backwards propagation of failures (but not of successful payments).
> Currently, latency on the network is known to be very low, but I observe that most Lightning Network participants today have excellent Internet connectivity, which might not be true in the foreseeable future.
>
> We can reduce the round trips to 1.5 per commitment, except for the initial commitment transaction, by sending the `R` precommitments (the first phase of MuSig) of the *next* signing session while sending the `s` for the *current* signing session.
>
> Finally, we can consider to reduce the use of MuSig via various techniques.
> One technique is the use of fast forwards: https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2019/improving-payment-latency-by-fast-forwards#m-403939fc
>
> The other involves using Taproot.
> The taproot internal pubkey is the MuSig of both participants, but we also add an explicit 2-of-2 as a tapscript (or hide the 2-of-2 in a 2-of-3), i.e. `<A> OP_CHECKSIGVERIFY <B> OP_CHECKSIG` in a tapscript.
> This allows commitment transactions to use the tapscript path and have separate signatures for both participants.
> Then, mutual close uses the MuSig keypath spend.
> This reduces the changes relative to the current Poon-Dryja implementation: we can continue to use `commitment_signed` messages (or equivalent new ones for Taproot-based Poon-Dryja channels), and only the mutual close ritual needs to be modified to use MuSig.
>
> Thus the options are below, but ***please do not select an option yet***, because further sections greatly affect the tradeoffs of the options below.
>
> * [ ] Latency is not an issue (even in the foreseeable future), just use the 2.5 round trips for MuSig and MuSig-sign every commitment.
> * [ ] Pre-send the `R` commitments with the previous `s`.
>   * This increases the needed storage requirements of both nodes, and possibly complexity of node software, but reduces the round trips to 1.5.
>   * This usage may need to have larger bounds than what may be naively expected, if we decide to use Multi-`R` composable MuSig (see later section).
>   * Even *without* this option, at the minimum we still need to store `R` commitments and `R`, at least in memory, until we complete the MuSig ritual.
> * [ ] Use fast-forwards.
>   * This removes the latency of commitment transaction signing from the forwarding and failure-reporting paths.
>     * *Improved* forwarding and failure-reporting latency compared to today (revocation and signature not needed for forwarding/failure-reporting).
>   * Latency is still high for commitment transaction signing, but this is less of an issue as it is no longer in the forwarding/failure-reporting path.
> * [ ] Explicit 2-of-2 for commitment, MuSig for mutual close.
>   * No degradation in latency compared to today (0.5 round trips for signature, additional 1 round trip for signalling and revocation).
>   * No improvement (or degradation) of privacy for unilateral closes compared to today, but improved privacy for mutual closes.
>     * An argument *for* this option is that unilateral closes (commitment transactions) have special scripts on their outputs anyway, thus still leak their privacy, but see later sections for how Taproot may help reduce the uniqueness of those outputs, thus *not* taking this option may still improve privacy for unilateral closes.
>
> Composable MuSig
> ----------------
>
> As I describe here: https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2019-November/017493.html
>
> In that write-up, I mention the use-case of nodelets.
> Another use-case is for redundant hardware signers: https://lists.ozlabs.org/pipermail/c-lightning/2019-December/000172.html
>
> We have the option of allowing for a composable MuSig, probably my multi-`R` proposal, where each participant may send one or more `R` commitments and subsequent `R`s.
>
> * [ ] Not use composable MuSig of any kind, at least for now.
>   * Possibly we could defer the use of a composable MuSig when a better composable MuSig (with security proofs) has been derived.
> * [ ] Use Multi-`R` composable MuSig.
>   * We need to probably impose some limit on the number of `R` commitments that can be sent: _____ `R`s maximum.
>
> The latter option above affects the previous choice regarding whether to pre-send `R` commitments with the previous `s` sending, as this increases the maximal storage requirement for the pre-sent `R` commitment(s).
>
> Pointlocked Timelocked Contracts
> --------------------------------
>
> I would have preferred to keep this in a separate discussion thread, however the exact details of PTLCs may affect our decision on how to sign commitment transactions.
>
> PTLCs are necessary to switch the Lightning Network to payment point+scalar, and indeed one can argue that the entire point of enabling Schnorr and Taproot at the base layer is to allow us to use payment point+scalar at the Lightning layer.
>
> First, I will discuss how to create a certain kind of PTLCs, which I call "purely scriptless" PTLCs.
> In particular, I would like to point out that we *actually* use in current Poon-Dryja Lightning Network channels is *revocable* HTLCs, thus we need to have *revocable* PTLCs to replace them.
>
> * First, we must have a sender A, who is buying a secret scalar, and knows the point equivalent to that scalar.
> * Second, we have a receiver B, who knows this secret scalar (or can somehow learn this secret scalar).
> * A and B agree on the specifications of the PTLC: the point, the future absolute timelock, the value.
> * A creates (but *does not* sign or broadcast) a transaction that pays to a MuSig of A and B and shares the txid and output number with the relevant MuSig output.
> * A and B create a backout transaction.
>   * This backout has an `nLockTime` equal to the agreed absolute timelock.
>   * It spends the above MuSig output (this input must enable `nLockTime`, e.g. by setting `nSequence` to `0xFFFFFFFE`).
>   * It creates an output that is solely controlled by A.
> * A and B perform a MuSig ritual to sign the backout transaction.
> * A now signs and broadcast the first transaction, the one that has an output that represents the PTLC.
> * A and B wait for the above transaction to confirm deeply.
>   This completes the setup phase for the PTLC.
> * After this point, if the agreed-upon locktime is reached, A broadcasts the backout transaction and aborts the ritual.
> * A and B create a claim transaction.
>   * This has an `nLockTime` of 0, or a present or past blockheight, or disabled `nLockTime`.
>   * This spends the above MuSig output.
>   * This creates an output that is solely controlled by B.
> * A and B generate an adaptor signature for the claim transaction, which reveals the agreed scalar.
>   * This is almost entirely a MuSig ritual, except at `s` exchange, B provides `t + r + h(R | MuSig(A,B) | m) * MuSigTweak(A, B, B) * b` first, then demands `r + h(R | MuSig(A,B) | m) * MuSigTweak(A, B, A) * a` from A, then reveals `r + h(R | MuSig(A,B) | m) * MuSigTweak(A, B, B) * b` (or the completed signature, by publishing onchain), revealing the secret scalar `t` to A.
> * A is able to learn the secret scalar from the above adaptor signature followed by the full signature, completing the ritual.
>
> Note that the above ritual is "purely scriptless".
> It is possible to take advantage of taproot to create a tapscript equivalent to `<agreed locktime> OP_CHECKLOCKTIMEVERIFY OP_DROP <A> OP_CHECKSIG`.
> This removes the need to perform a MuSig ritual to sign a backout transaction: A can generate the backout transaction all by itself.
> This use is not purely scriptless, as the timelocked branch is controlled by a tapscript that is hidden in the pointlocked branch, meaning that taking the timelocked branch reveals the contract.
>
> The tradeoff is that if we use "purely scriptless" PTLCs:
>
> * If we have purely scriptless PTLCs, then even the timelock branch is potentially indistinguishable from ordinary spends.
>   * We should note that Bitcoin Core itself already uses the current blockheight plus 1 for `nLockTime` when spending, instead of a 0 or disabled `nLockTime`.
>   * If the above habit were more widespread (i.e. if all wallets implemented the use of a current `nLockTime` for ordinary onchain spends) then the timelock branch has an anonymity set equal to all Schnorr keypath spends, as the `nLockTime` is always used anyway.
>   * Other kinds of offchain protocols may also utilize this technique, slightly increasing the anonymity set as well.
>     Thus, the use of the current blockheight plus 1 for `nLockTime` should be recommended for improved privacy in Bitcoin anyway.
> * However, purely scriptless PTLCs require a complete MuSig ritual (2.5 to 3 round trips!) to sign the timelocked branch (the initial backout transaction); this increases the latency of adding new PTLCs.
>   * Of note is that in the case of Lightning, we may need to add a new PTLC while another PTLC is *still* in-flight; on the new commitment transaction, we need to redo the MuSig rituals to create new backouts and new adaptor signtures for each PTLC.
>     * This can be amortized such that we redo all the rituals for all existing PTLCs in parallel.
>       * The use of multi-`R` composable MuSig greatly increases the storage requirements as well!
>   * Further, the privacy gained in the timelock path is degraded or lost when we consider revocable PTLCs and revocable outputs.
>   * It is not clear to me as fo now if the MuSig ritual for the backout transaction must complete in full before the MuSig ritual for the claim transaction (the pointlocked branch, which includes sharing an adaptor signature during `s` exchange).
>     * If we can do these two rituals in parallel, this reduces the latency disadvantage of the purely scriptless PTLC to just 1 round trip compared to the tapscripted timelock branch PTLC.
>     * Possibly the adaptor signature ritual could stop until B provides the adaptor signature, then full `s` exchange is deferred to after the PTLC 2-of-2 is instantiated onchain/reified in a commitment transaction.
>
> Thus our options are the below, but again, you should defer deciding on the best option until you understand about revocable PTLCs.
>
> * [ ] We can use a purely scriptless PTLC construction.
>   * Better privacy, but increased latency.
> * [ ] We can use a tapscripted timelock branch and a keypath pointlocked branch for the PTLC.
>   * Lower latency, but possibly reduced privacy advantage in the timelock branch (privacy advantage still exists in the pointlocked branch, which we hope is more common anyway).
>
> Revocable Outputs and PTLCs
> ---------------------------
>
> Poon-Dryja mechanism is based on revocation of contracts instantiated from previous states.
> Thus, all outputs of Poon-Dryja must be made revocable.
>
> At a high-enough level, this only requires the addition of a `(revocation_secret && remote_secret) || (CSV && L)` to the top-level logic (`L`) of a contract.
> Of course, the details have the devil.
>
> Now, in Poon-Dryja, each side of the channel has its own commitment transaction.
> Thus, contracts on the commitment transaction refer to a "local side" and a "remote side".
> The "local side" is whoever is holding the completely-signed commitment transaction, while the "remote side" is the other side.
>
> Revocable outputs always have a CSV-requirement before the output can be spent by whoever "should" own the output, according to the contract details.
> The revocation secret is known by the local side, and then when a *new* commitment transaction has been signed, the revocation secret is given by the local side to the remote side, allowing all outputs to be spent directly by the remote side if an old, revoked commitment transaction is published onchain.
>
> There are many ways to implement revocable outputs.
> The core idea of revocable outputs, however, is that there must exist some relative-locktime branch on each output that goes to the local side.
> This relative-locktime branch can be implemented as "purely scriptless" by using a 2-of-2 of both the local and remote sides, with a relative-locktime `nSequence`, using the same technique as described in the previous section.
>
> However, unlike the absolute-locktime `nLockTime` for the timelock branches of PTLCs, ***there is no current wallet software that uses activated-relative-locktime `nSequence` for ordinary spends***.
> Thus, any use of the relative-locktime branch does *not* have a privacy advantage under purely scriptless.
>
> Thus the tradeoffs here are different, and definitely in favor of the tapscripted-relative-locktime technique.
>
> * There is no current wallet software that uses relative locktimes.
>   * Bitcoin Core uses absolute locktimes with the current blockheight plus 1, and we can hide the use of absolute locktimes by imitating this Bitcoin Core behavior.
>   * Any use of relative locktimes is a strong signal of some kind of complicated offchain updateable mechanism.
>     We can note as well that Decker-Russell-Osuntokun also uses relative locktimes.
> * The relative-locktime branch in revocable outputs is the **desirable** case, because taking the relative locktime means that the commitment transaction published *was not* a revoked transaction (i.e. it was the latest transaction version).
>   * Thus, it would be nice if this had good privacy.
>   * However, this *cannot* have good privacy since there is no current common use of activated relative locktimes for ordinary spends.
>
> The latter point above also biases us towards rejecting purely-scriptless in the *previous* section, in particular:
>
> * The absolute-locktime branch in the PTLC is the **undesirable** case, where the payee B somehow stops responding to A.
>   * In particular, propagating failure backwards is done by simply deleting PTLCs, thus the absolute-locktime branch does not come into play during payment failure.
>   * Thus, the privacy increase of hiding absolute-locktime branches is minor, and the privacy breach of revocable outputs (i.e. it leaks the use of relative-locktime, and nearly all uses of relative locktime will be offchain updateable cryptocurrency mechanisms, such as Poon-Dryja or Decker-Russell-Osuntokun) is arguably much larger than the privacy increase of purely-scriptless absolute-locktime.
>
> Of particular not is that if a PTLC is instantiated on the commitment transaction of the payer A, then the absolute-locktime backout transaction must *not* pay to A only, but instead pays to a *revocable output* that will eventually pay to A after the relative locktime.
> Thus, the privacy boost of the purely-scriptless backout transaction would be lost by the later revelation of the use of a relative locktime after the revocable output is reclaimed by A.
> Again, that use of relative locktime (whether enforced by script, or by scriptless use of a 2-of-2 that is spent with an activated relative-locktime `nSequence`) is a strong indicator of the use of Poon-Dryja or Decker-Russell-Osuntokun or even Decker-Wattenhofer mechanisms, and the logic is that since Lightning Network is the most widespread offchain mechanism, it probably indicates the use of LN.
>
> Thus the decision in the previous section is affected by this reality that we in fact need *revocable* PTLCs, not plain PTLCs, thus the advantage of purely-scriptless backout transactions in the previous section is reduced by the need to make outputs revocable.
>
> Thus:
>
> * Revocable outputs require a relative-timelock branch.
> * That branch is the **desirable** branch, i.e. the latest commitment transaction is the one that got published and thus is *not* revoked.
>   * We thus expect this relative-timelock branch to be the *common* branch.
> * No wallet uses relative-timelock for ordinary spends, unlike abolute-locktime where Bitcoin Core always uses absolute-locktime `nLockTime` for ordinary spends.
>   * Thus, using purely scriptless for the relative-timelock branch of revocable outputs does not in fact hide that we are doing something special.
>
> Conclusion
> ----------
>
> Others may find further issues or alternative options for the above points.
> Further discussion may be warranted before we actually select particular options to implement and evaluate in alpha software.
>
> Regards,
> ZmnSCPxj
>
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
>
Anthony Towns in reply to ZmnSCPxj permalink original

On Sun, Dec 15, 2019 at 03:43:07PM +0000, ZmnSCPxj via Lightning-dev wrote:

Quoted text (2 lines)
> For now, I am assuming the continued use of the existing Poon-Dryja update mechanism.
> Decker-Russell-Osuntokun requires `SIGHASH_NOINPUT`/`SIGHASH_ANYPREVOUT`, and its details seem less settled for now than taproot details.

Supporting PTLCs instead of HTLCs is a global upgrade in that you need all nodes along your payment path to support it; moving from Poon-Dryja to Decker-Russell-Osuntokun is only relevant to individual peers. So I think it makes sense to do PTLCs first if the required features aren't both enabled at the same time.

Quoted text (2 lines)
> Poon-Dryja with Schnorr
> -----------------------

I think MuSig between the two pairs is always superior to a NUMS point for the taproot internal key; you definitely want to calculate a point rather than use a constant, or you're giving away that it's lightning, and if you're calculating you might as well calculate something that can be used for a cooperative key path spend if you ever want to.

Quoted text (1 line)
> 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.

Quoted text (24 lines)
> Pointlocked Timelocked Contracts
> --------------------------------
> First, I will discuss how to create a certain kind of PTLCs, which I call "purely scriptless" PTLCs.
> In particular, I would like to point out that we *actually* use in current Poon-Dryja Lightning Network channels is *revocable* HTLCs, thus we need to have *revocable* PTLCs to replace them.
> * First, we must have a sender A, who is buying a secret scalar, and knows the point equivalent to that scalar.
> * Second, we have a receiver B, who knows this secret scalar (or can somehow learn this secret scalar).
> * A and B agree on the specifications of the PTLC: the point, the future absolute timelock, the value.
> * A creates (but *does not* sign or broadcast) a transaction that pays to a MuSig of A and B and shares the txid and output number with the relevant MuSig output.
> * A and B create a backout transaction.
>   * This backout has an `nLockTime` equal to the agreed absolute timelock.
>   * It spends the above MuSig output (this input must enable `nLockTime`, e.g. by setting `nSequence` to `0xFFFFFFFE`).
>   * It creates an output that is solely controlled by A.
> * A and B perform a MuSig ritual to sign the backout transaction.
> * A now signs and broadcast the first transaction, the one that has an output that represents the PTLC.
> * A and B wait for the above transaction to confirm deeply.
>   This completes the setup phase for the PTLC.
> * After this point, if the agreed-upon locktime is reached, A broadcasts the backout transaction and aborts the ritual.
> * A and B create a claim transaction.
>   * This has an `nLockTime` of 0, or a present or past blockheight, or disabled `nLockTime`.
>   * This spends the above MuSig output.
>   * This creates an output that is solely controlled by B.
> * A and B generate an adaptor signature for the claim transaction, which reveals the agreed scalar.
>   * This is almost entirely a MuSig ritual, except at `s` exchange, B provides `t + r + h(R | MuSig(A,B) | m) * MuSigTweak(A, B, B) * b` first, then demands `r + h(R | MuSig(A,B) | m) * MuSigTweak(A, B, A) * a` from A, then reveals `r + h(R | MuSig(A,B) | m) * MuSigTweak(A, B, B) * b` (or the completed signature, by publishing onchain), revealing the secret scalar `t` to A.
> * A is able to learn the secret scalar from the above adaptor signature followed by the full signature, completing the ritual.

(I think it makes more sense to provide "r + H(R+T, P, m)*b" instead of "r+t + H(R,P,m)*b" -- you might not know "t" at the point you need to start the signature exchange)

I think the setup can be similar to BOLT-3:

  Funding TX output:  MuSig(A,B)
  Commitment Tx Held by A:
    - locktime: obscured commitment number
    - input: funding tx
    - outputs:
        balance A
	balance B
	PTLC paying to A
	PTLC paying to B
        [etc]

balance B can pay directly to B

balance A pays to MuSig(Rn,B) -- where Rn is the revocation key for the nth commitment, and A holds a presigned tx by B with relative locktime set, paying the funds to A.

PTLCs also pay to MuSig(Rn,B) --

for the one paying to A, A holds a tx partially presigned by B that needs the point's discrete log added to x with relative timelock; for the one paying to B, A holds a presigned tx by B that has absolute locktime set and pays to MuSig(Rn,B) for which A has another presigned tx by B that has relative locktime set.

HTLC's also pay to MuSig(Rn,B) but they're tweaked by a script -- if they're paying to B, A just holds the same timelocked presigned tx's as for PTLCs; if they're paying to A, A will use a "HASH160 X EQUALVERIFY A CHECKSIGVERIFY delay CSV" script path instead.

B has a similar commitment Tx; and A holds pre-signed tx's for the PTLC's there, except without the relative timelock txs.

This adds up to B needing to provide A with signatures for:

  the funding tx
  A's balance
  each PTLC/HTLC paying/refunding to A from A's commitment and the sub tx for each of those
  each PTLC/HTLC paying/refunding to B from B's commitment

and each of those signatures need to be updated every commitment update.

Note that you need to receive all the partial signatures to spend the commitment tx before you provide your partial signature over the funding tx to authorise the commitment tx. So yet more rounds of communication.

I think this approach would let you upgrade existing channels to support PTLCs without closing/reopening, though.

I think you could do something eltoo-ish to simplify watchtowers:

    Funding TX output: MuSig(A,B)
    Commitment Tx Held by A:
      - locktime: obscured commitment number
      - inputs: funding tx
      - outputs: MuSig(Rn,B)
    Settlement Tx Held by A:
      - nsequence: to_self_delay
      - input: commitment tx held by A
      - outputs:
         balance A
	 balance B
	 PTLC paying to A
	 PTLC paying to B
    Secondary Settlement Tx Held by B:
      - no abs/relative locktime
      - input: commitment tx held by A
      - outputs:
         balance A
	 balance B
	 PTLC paying to A
	 PTLC paying to B

in which case once the commitment is revoked, B only needs to do a single signature of MuSig(Rn,B) to claim all the funds if A publishes the old commitment, without having to worry about any HTLC/PTLC info? The settlement tx can be a bit simplified I think too. Maybe the edge case when the absolute locktime is close to the relative locktime makes this painful, though I think it would make eltoo painful then too? Not sure if I'm missing something here.

(Note that this gives symmetric delays: if A unilaterally closes the channel by publishing the commitment tx, and B wants their funds, B can either immediately claim all the funds via the revocation secret if A was cheating, or has to publish the settlement tx first, at which point A can get all A's funds immediately as well)

Quoted text (3 lines)
> Revocable Outputs and PTLCs
> ---------------------------
> * No wallet uses relative-timelock for ordinary spends, unlike abolute-locktime where Bitcoin Core always uses absolute-locktime `nLockTime` for ordinary spends.

I think the fact lightning relative timelocks will be "round" numbers, and the timelocked tx will be published as soon as possible will make it relatively easy to distinguish them from other spends anyway. Doing it scriptlessly is cheaper on chain though.

Anyway, my picks are:

 - [x] Poon-Dryja PTLCs prior to eltoo
 - [x] scriptless revocation via MuSig(Rn,B) internal keys
 - [x] support HTLCs via taproot
 - [x] (optionally) allow use of script paths to minimise round trip
       delay

Cheers, aj

ZmnSCPxj in reply to Anthony Towns permalink original

Good morning,

Quoted text (10 lines)
> On Sun, Dec 15, 2019 at 03:43:07PM +0000, ZmnSCPxj via Lightning-dev wrote:
>
> > For now, I am assuming the continued use of the existing Poon-Dryja update mechanism.
> > Decker-Russell-Osuntokun requires `SIGHASH_NOINPUT`/`SIGHASH_ANYPREVOUT`, and its details seem less settled for now than taproot details.
>
> Supporting PTLCs instead of HTLCs is a global upgrade in that you need
> all nodes along your payment path to support it; moving from Poon-Dryja
> to Decker-Russell-Osuntokun is only relevant to individual peers. So I
> think it makes sense to do PTLCs first if the required features aren't
> both enabled at the same time.

Indeed. The question is then do we upgrade Poon-Dryja to *at least* use a MuSig on mutual close (for the privacy boost of mutual closes), or do we just keep Poon-Dryja as is now, and add PTLCs from them.

Quoted text (10 lines)
>
> > Poon-Dryja with Schnorr
> >
> > ------------------------
>
> I think MuSig between the two pairs is always superior to a NUMS point
> for the taproot internal key; you definitely want to calculate a point
> rather than use a constant, or you're giving away that it's lightning,
> and if you're calculating you might as well calculate something that can
> be used for a cooperative key path spend if you ever want to.

I am uncertain why a NUMS point would be used here, except if you wanted to simulate an explicit 2-of-3 from your explicit 2-of-2, which while interesting is really a foolish idea and I will now lurk forever (for some definition of "forever") because of ever suggesting it.

Quoted text (6 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:

Not quite the correct section? This section is discussing the Poon-Dryja updateable mechanism, not the PTLCs, and it is the the "PTLC" which requires discrete log of a point.

But in any case....

Quoted text (34 lines)
>
> 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.

Ah, so I suppose you are saying that it is possible to create an adaptor signature for what is effectively a 1-of-1 Schnorr pubkey, and that can implement the pointlocked branch?

Just to be clear, in the above:

* A is the payer (and wants to pay if and only if it can learn the payment).
* B is the payee (and knows the secret).

So A gives a pointlock condition to the payee by providing an adaptor signature for its pubkey A, which cannot be used to validate, but B can simply add the secret `x` that is the discrete log of `X`. And since A knows the above adaptor signature which it generated, once the completed signature for A is given by B, A can simply subtract it with the stored adaptor signature to learn the secret.

However, we still need a branch for the timelock, and if the output is revocable, some more additional conditions and/or scripts need to be made. We could use the same script for a revocable timelocked transaction going back to A, but A would have to get the signature from B for this revocable timelocked transaction *before* it hands over the adaptor signature (else B can just keep the adaptor signature forever and not claim the funds until its own convenience, possibly beyond the time that the scalar is useful). This may mean adding one more round trip.

Quoted text (33 lines)
>
> > Pointlocked Timelocked Contracts
> >
> > ---------------------------------
> >
> > First, I will discuss how to create a certain kind of PTLCs, which I call "purely scriptless" PTLCs.
> > In particular, I would like to point out that we actually use in current Poon-Dryja Lightning Network channels is revocable HTLCs, thus we need to have revocable PTLCs to replace them.
> >
> > -   First, we must have a sender A, who is buying a secret scalar, and knows the point equivalent to that scalar.
> > -   Second, we have a receiver B, who knows this secret scalar (or can somehow learn this secret scalar).
> > -   A and B agree on the specifications of the PTLC: the point, the future absolute timelock, the value.
> > -   A creates (but does not sign or broadcast) a transaction that pays to a MuSig of A and B and shares the txid and output number with the relevant MuSig output.
> > -   A and B create a backout transaction.
> >     -   This backout has an `nLockTime` equal to the agreed absolute timelock.
> >     -   It spends the above MuSig output (this input must enable `nLockTime`, e.g. by setting `nSequence` to `0xFFFFFFFE`).
> >     -   It creates an output that is solely controlled by A.
> > -   A and B perform a MuSig ritual to sign the backout transaction.
> > -   A now signs and broadcast the first transaction, the one that has an output that represents the PTLC.
> > -   A and B wait for the above transaction to confirm deeply.
> >     This completes the setup phase for the PTLC.
> >
> > -   After this point, if the agreed-upon locktime is reached, A broadcasts the backout transaction and aborts the ritual.
> > -   A and B create a claim transaction.
> >     -   This has an `nLockTime` of 0, or a present or past blockheight, or disabled `nLockTime`.
> >     -   This spends the above MuSig output.
> >     -   This creates an output that is solely controlled by B.
> > -   A and B generate an adaptor signature for the claim transaction, which reveals the agreed scalar.
> >     -   This is almost entirely a MuSig ritual, except at `s` exchange, B provides `t + r + h(R | MuSig(A,B) | m) * MuSigTweak(A, B, B) * b` first, then demands `r + h(R | MuSig(A,B) | m) * MuSigTweak(A, B, A) * a` from A, then reveals `r + h(R | MuSig(A,B) | m) * MuSigTweak(A, B, B) * b` (or the completed signature, by publishing onchain), revealing the secret scalar `t` to A.
> > -   A is able to learn the secret scalar from the above adaptor signature followed by the full signature, completing the ritual.
>
> (I think it makes more sense to provide "r + H(R+T, P, m)*b" instead of
> "r+t + H(R,P,m)*b" -- you might not know "t" at the point you need to
> start the signature exchange)
Ah, so basically the signature that appears onchain would be `(R + T, r + t + h(R + T | P | m) * p)`?
Quoted text (14 lines)
>
> I think the setup can be similar to BOLT-3:
>
> Funding TX output: MuSig(A,B)
>
> Commitment Tx Held by A:
> - locktime: obscured commitment number
> - input: funding tx
> - outputs:
> balance A
> balance B
> PTLC paying to A
> PTLC paying to B
> [etc]

Just to be clear, "PTLC paying to A" means the pointlock branch pays to A, the timelock branch pays to B, right?

Quoted text (35 lines)
>
> balance B can pay directly to B
>
> balance A pays to MuSig(Rn,B) -- where Rn is the revocation key for the
> nth commitment, and A holds a presigned tx by B with relative locktime
> set, paying the funds to A.
>
> PTLCs also pay to MuSig(Rn,B) --
>
> for the one paying to A, A holds a tx
> partially presigned by B that needs the point's discrete log added to x
> with relative timelock; for the one paying to B, A holds a presigned tx
> by B that has absolute locktime set and pays to MuSig(Rn,B) for which
> A has another presigned tx by B that has relative locktime set.
>
> HTLC's also pay to MuSig(Rn,B) but they're tweaked by a script -- if
> they're paying to B, A just holds the same timelocked presigned tx's as
> for PTLCs; if they're paying to A, A will use a "HASH160 X EQUALVERIFY
> A CHECKSIGVERIFY delay CSV" script path instead.
>
> B has a similar commitment Tx; and A holds pre-signed tx's for the
> PTLC's there, except without the relative timelock txs.
>
> This adds up to B needing to provide A with signatures for:
>
> the funding tx
> A's balance
> each PTLC/HTLC paying/refunding to A from A's commitment and the sub tx for each of those
> each PTLC/HTLC paying/refunding to B from B's commitment
>
> and each of those signatures need to be updated every commitment update.
>
> Note that you need to receive all the partial signatures to spend the
> commitment tx before you provide your partial signature over the funding
> tx to authorise the commitment tx. So yet more rounds of communication.

Yes, this looks like it needs some more fleshing out.

Quoted text (3 lines)
>
> I think this approach would let you upgrade existing channels to support
> PTLCs without closing/reopening, though.

I believe so as well, as of course the base layer allows transactions to have a mix of SegWit v0 (HTLCs) and SegWit v1 (PTLCs) outputs.

Quoted text (35 lines)
>
> I think you could do something eltoo-ish to simplify watchtowers:
>
> Funding TX output: MuSig(A,B)
>
> Commitment Tx Held by A:
> - locktime: obscured commitment number
> - inputs: funding tx
> - outputs: MuSig(Rn,B)
>
> Settlement Tx Held by A:
> - nsequence: to_self_delay
> - input: commitment tx held by A
> - outputs:
> balance A
> balance B
> PTLC paying to A
> PTLC paying to B
>
> Secondary Settlement Tx Held by B:
> - no abs/relative locktime
> - input: commitment tx held by A
> - outputs:
> balance A
> balance B
> PTLC paying to A
> PTLC paying to B
>
> in which case once the commitment is revoked, B only needs to do a single
> signature of MuSig(Rn,B) to claim all the funds if A publishes the
> old commitment, without having to worry about any HTLC/PTLC info? The
> settlement tx can be a bit simplified I think too. Maybe the edge case
> when the absolute locktime is close to the relative locktime makes this
> painful, though I think it would make eltoo painful then too? Not sure
> if I'm missing something here.

Indeed, having the relative locktime affect the absolute locktime is a pain, and I hope to have moved away from pathfinding before Decker-Russell-Osuntokun arrives and makes it a headache to find paths. The issue is that the relative locktime for Decker-Russell-Osuntokun must be combined over each step of the route via the "max" function instead of the "`+`" function, and all existing pathfinding algos assume costs are combined via "`+`". I suppose this is doable by annotating each node with the current max-csv, and if the node under evaluation has a higher csv requirement than the max-csv of the node it is arriving from, treat that edge as having a higher cost, but bleah.

Quoted text (29 lines)
>
> (Note that this gives symmetric delays: if A unilaterally closes the
> channel by publishing the commitment tx, and B wants their funds, B can
> either immediately claim all the funds via the revocation secret if A
> was cheating, or has to publish the settlement tx first, at which point
> A can get all A's funds immediately as well)
>
> > Revocable Outputs and PTLCs
> >
> > ----------------------------
> >
> > -   No wallet uses relative-timelock for ordinary spends, unlike abolute-locktime where Bitcoin Core always uses absolute-locktime `nLockTime` for ordinary spends.
>
> I think the fact lightning relative timelocks will be "round" numbers,
> and the timelocked tx will be published as soon as possible will make
> it relatively easy to distinguish them from other spends anyway. Doing
> it scriptlessly is cheaper on chain though.
>
> Anyway, my picks are:
>
> -   [x] Poon-Dryja PTLCs prior to eltoo
> -   [x] scriptless revocation via MuSig(Rn,B) internal keys
> -   [x] support HTLCs via taproot
> -   [x] (optionally) allow use of script paths to minimise round trip
>     delay
>
>     Cheers,
>     aj
>

Thank you for your considered opinion as well as the new adaptor constructions.

Regards, ZmnSCPxj

Lloyd Fournier in reply to ZmnSCPxj permalink original

Hi ZmnSCPxj and Aj,

Thanks for starting this discussion ZmnSCPxj. Although transactions with relative lock times are easily distinguishable today, couldn't this situation be improved? Even just a few wallets changing their behaviour to set relative time locks on normal payments would weaken the heuristic. From a design perspective it feels like leaving the improvement vector open would be better.

Aj's model of scriptless lightning is more or less what I had in my mind (but with much better detail). On the question of "script based payment points" or "fully scriptless": Why not just do both?

Since the tapscript version is faster to the "irrevocably committed" state, you first do that so you can forward the payment as fast as possible. Now that both parties have a commitment tx with a tapscript PTLC, they can (in no hurry) sign the scriptless spending transactions from the PTLC output. I think once they have signatures on their scriptless PTLC transactions they can forget all the tapscript data (to minimize the data they have to store per commitment tx).

Quoted text (12 lines)
> 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.

This is exactly how I thought the "script based payment point" would work where you just replace the hashing with an CHECKSIG and an adaptor sig. Like Z, I don't see how you can get away with just that though. I think you need to do a full tapscript PTLC and revocation (1.5 round trips) before you can forward a payment.

Cheers,

LL

David A. Harding in reply to Lloyd Fournier permalink original

On Wed, Dec 18, 2019 at 02:51:56PM +1100, Lloyd Fournier wrote:

Quoted text (6 lines)
> Hi ZmnSCPxj and Aj,
>
> Thanks for starting this discussion ZmnSCPxj. Although transactions with
> relative lock times are easily distinguishable today, couldn't this
> situation be improved? Even just a few wallets changing their behaviour to
> set relative time locks on normal payments would weaken the heuristic.

As mentioned in ZmnSCPxj's post, some wallets (most notably Bitcoin Core) provide partial anti-fee-sniping protection by setting their nLockTime to the next-block height[1]. In line with your idea to do the same with nSequence, I think it would be possible to suggest to the Bitcoin Core project that they also set nSequence to the block age of the UTXO being spent (if possible[2]). I think this could slightly enhance existing anti-fee-sniping by limiting a sniper's ability to rearrange ancestor transactions. For example, imagine we have two transactions both created by Bitcoin Core on the best block chain:

                      tx0               tx1
                       |                 |
          [ ]---------[ ]-------[ ]-----[ ]----
    Block 600,000    ..01      ..02    ..03

Let's assume tx0 and tx1 were both confirmed quickly, so their nLockTime equals their block height. That means a fee sniper's reorg can't move either transaction further back in the chain, burying them under addition PoW. Let's also assume that tx1 is a child of tx0 and sets its nSequence to 2 blocks. Now tx0 also can't be moved further forward in the chain without also moving tx1 further forward, meaning any reduction in the amount of PoW covering one transaction would also reduce the amount of PoW covering any of its descendant transactions (if they opt-in to this scheme).

Bitcoin Core obviously has the information necessary to add an appropriate nSequence to its transactions because it has a copy of the UTXO set, but *every* wallet should be keeping track of its transaction's confirmation scores, so every wallet should know the nSequence delta to use to allow its transactions to be confirmed in the next block but no earlier block.

My question here would be whether this change would be useful in providing privacy for the scheme ZmnSCPxj described. IIUC, the pre-signed transactions Zmn described wouldn't need to use both relative locktime (nSequence) and absolute locktime (nLockTime) at the same time, so it would be possible to set nLockTime to an appropriate value when using nSequence for security. This might not blend in perfectly with anti-fee-sniping (especially to relay nodes) but perhaps Bitcoin Core's fuzzing[1] could be increased to help compensate.

-Dave

[1] I think Bitcoin Core implements low-probability fuzzing of the nLockTime to help cover for wallets that send transactions while still syncing to the tip. E.g. an instance fully synced to the current chain tip might set 1-in-100 of its transactions nLockTime to some past block height so that spy nodes can't tell whether that transaction was transmitted by a fuzzing node or one of the nodes that just happened to be IBD syncing from them at that moment.

[2] nSequence can only encode up to a max of 65,535 for the block distance; see BIP68. Also, obviously, if the parent transaction is unconfirmed at the time one of its outputs is spent, the child can't have a relative lock-height unless you want to delay its confirmation.

ZmnSCPxj in reply to ZmnSCPxj permalink original
Quoted text (1 line)
> indeed one can argue that the entire point of enabling Schnorr and Taproot at the base layer is to allow us to use payment point+scalar at the Lightning layer.

Just to be clear, this statement is intended to be facetious, along the same vein as "Lightning Network is so awesome, we just had to invent Bitcoin for it".

Regards, ZmnSCPxj

ZmnSCPxj in reply to David A. Harding permalink original

Good morning David,

Quoted text (48 lines)
> On Wed, Dec 18, 2019 at 02:51:56PM +1100, Lloyd Fournier wrote:
>
> > Hi ZmnSCPxj and Aj,
> > Thanks for starting this discussion ZmnSCPxj. Although transactions with
> > relative lock times are easily distinguishable today, couldn't this
> > situation be improved? Even just a few wallets changing their behaviour to
> > set relative time locks on normal payments would weaken the heuristic.
>
> As mentioned in ZmnSCPxj's post, some wallets (most notably Bitcoin
> Core) provide partial anti-fee-sniping protection by setting their
> nLockTime to the next-block height[1]. In line with your idea to do the
> same with nSequence, I think it would be possible to suggest to the
> Bitcoin Core project that they also set nSequence to the block age of
> the UTXO being spent (if possible[2]). I think this could slightly
> enhance existing anti-fee-sniping by limiting a sniper's ability to
> rearrange ancestor transactions. For example, imagine we have two
> transactions both created by Bitcoin Core on the best block chain:
>
> tx0 tx1
> | |
> [ ]---------[ ]-------[ ]-----[ ]----
> Block 600,000 ..01 ..02 ..03
>
> Let's assume tx0 and tx1 were both confirmed quickly, so their nLockTime
> equals their block height. That means a fee sniper's reorg can't move
> either transaction further back in the chain, burying them under
> addition PoW. Let's also assume that tx1 is a child of tx0 and sets its
> nSequence to 2 blocks. Now tx0 also can't be moved further forward in
> the chain without also moving tx1 further forward, meaning any reduction
> in the amount of PoW covering one transaction would also reduce the
> amount of PoW covering any of its descendant transactions (if they
> opt-in to this scheme).
>
> Bitcoin Core obviously has the information necessary to add an
> appropriate nSequence to its transactions because it has a copy of the
> UTXO set, but every wallet should be keeping track of its transaction's
> confirmation scores, so every wallet should know the nSequence delta to
> use to allow its transactions to be confirmed in the next block but no
> earlier block.
>
> My question here would be whether this change would be useful in providing
> privacy for the scheme ZmnSCPxj described. IIUC, the pre-signed
> transactions Zmn described wouldn't need to use both relative locktime
> (nSequence) and absolute locktime (nLockTime) at the same time, so it
> would be possible to set nLockTime to an appropriate value when using
> nSequence for security. This might not blend in perfectly with
> anti-fee-sniping (especially to relay nodes) but perhaps Bitcoin Core's
> fuzzing[1] could be increased to help compensate.

Unfortunately it does not quite work to have a transaction with *both* non-zero `nLockTime` and relative-locktime `nSequence`.

For `nLockTime`-only (no relative locktime, i.e. all `nSequence` is 0xFFFFFFE), these are used in HTLC / PTLC contracts. The beneficiary of the timelock branch of the HTLC/PTLC will publish it at around the `nLockTime`, which matches with the behavior that Bitcoin Core will produce.

For `nSequence` relative-locktime transactions that protect the security of the channel mechanism, these are used in unilateral closes. The issue is that a unilateral close might occur far, far in the future. Thus, any non-0 `nLockTime` you signed up for at the time the commitment transaction was signed, will likely be obsolete.

Instead, what Bitcoin Core would have to do would be something like:

* Toss a coin:
  * If it is heads, use a non-relative-locktime `nSequence` and an `nLockTime` of the next block (i.e. current behavior).
  * If it is tails, use a relative-locktime `nSequence` equal to the confirmations of the output being spent, and an `nLockTime` of 0.

Then we would hide the Lightning relative-locktime transactions with an `nLockTime` of 0.

Note that `nLockTime` transactions can be used in general as a backoff for cooperative protocols such as CoinSwap. I allude to this use here: https://github.com/AdamISZ/CoinSwapCS/issues/53 Thus we expect that there will be more users of `nLockTime`d transactions than relative-timelock `nSequence` transactions. It might be wise to bias the above coin towards using the relative-locktime `nSequence` more often than the `nLockTime`.

As far as I can tell, relative-locktime is most often used for unlimited-lifetime offchain updateable mechanisms, of which Lightning Poon-Dryja, Decker-Wattenhofer, and "eltoo" Decker-Russell-Osuntokun are the examples most readily available from my cortex-analogue. All intra-chain swaps (submarine swaps, CoinSwap, Lightning multi-hop routing) should use absolute-locktime, and can be optimized to some extent by use of `nLockTime` ordinary spends.

Regards, ZmnSCPxj

ZmnSCPxj in reply to ZmnSCPxj permalink original

Good morning,

Another point regarding the use of "purely scriptless" (i.e. using pre-signed `nLockTime` and `nSequence`d transactions) is that there are significantly more signatures to be generated cooperatively. We need to use MuSig for these in order to hide in the much larger 1-of-1 anonymity set. There are two branches per PTLC (pointlock and timelock), and one of those branches would lead to a revocable output (which has a relative-locktime), thus 3 signatures (just for one HTLC). It is probably safe to perform the MuSig for all three signatures in one MuSig exchange, and probably for all PTLCs on each commitment transaction as well, plus the revocable `to_self` output. However the commitment transaction itself would have to be signed *after* all the PTLCs and revocable `to_self` have been signed, so we cannot run the MuSig for this in parallel with the PTLCs and `to_self`.

Now, we know we can hide the timelock branches, as well as the revocable outputs, with other `nLockTime`d and `nSequence`d transactions.

* The timelock branch will be enforced by one of the participants, and will come onchain (if not congested) at the same blockheight indicated by the `nLockTime`.
* The revocable output will be claimed at the end of the revocation grace period, and will come onchain (if not congested) at the relative blocktime indicaated by the `nSequence`.

Both of the above will be indistinguishable from the anti-fee-sniping behavior (once we modify Bitcoin Core to randomly select between absolute and relative anti-fee-sniping), thus hides among the other transactions made by Bitcoin Core.

However, the commitment transaction itself, and the pointlock branch, cannot hide among the anti-fee-sniping behavior.

* The commitment transaction is kept indefinitely, and if there is no activity on the channel, a million blocks may pass since its `nLockTime` and `nSequence` have been fixed.
  * Thus, any `nLockTime` or `nSequence` we put in the commitment transaction would be well in the past by the time the commitment transaction appears onchain, and thus they can be identified that way.
  * We could just recreate the commitment transaction every time a new block comes in, so that the latest commitment transaction always has an up-to-date `nLockTime` or `nSequence`, but now every block would cause a system shock across the entire Lightning Network as all nodes update their channel states with their peers.
    * But what happens if the peer is offline at a new block?
      We are forced to keep around a commitment transaction with a past `nLockTime`/`nSequence`.
      If the peer remains offline we might then decide to push the commitment transaction, but since the peer is offline, it will have the past `nLockTime`/`nSequence`.
* The pointlock branch is dependent on the commitment transaction above, and encounters the same issues.

So in general it might be better for commitment transactions, as well as scriptless script pointlocks, to not have a fee-sniping-protection-emulation. But this means we also do not want to have all wallets use fee-sniping-protection.

Another point, and the reason why I pointed out that you need at least two MuSig rounds (the first running all the PTLC and revocable outputs in parallel, the second signing just the commitment hosting them), is that this increases latency of each update. This is fine if you are on open network, but on e.g. Tor each turnaround is greatly increased, and the multiple MuSig rounds get more delay.

Regards, ZmnSCPxj

David A. Harding in reply to ZmnSCPxj permalink original

On Tue, Jan 07, 2020 at 12:26:05AM +0000, ZmnSCPxj wrote:

Quoted text (5 lines)
> For `nSequence` relative-locktime transactions that protect the
> security of the channel mechanism, these are used in unilateral
> closes.  The issue is that a unilateral close might occur far, far in
> the future.  Thus, any non-0 `nLockTime` you signed up for at the time
> the commitment transaction was signed, will likely be obsolete.

As long as there's no conflict created by using both relative and absolute locktimes in the same transaction, I don't think there's any problem. Multiple versions of a commitment transaction may be signed, each with different nLockTimes but all other parts of the transaction the same (including any relative timelocks). This obviously requires a tiny bit of extra CPU plus modest amounts of extra bandwidth and storage, but it seems within reason for people who want better privacy.

Quoted text (7 lines)
> Instead, what Bitcoin Core would have to do would be something like:
>
> * Toss a coin:
>   * If it is heads, use a non-relative-locktime `nSequence` and an `nLockTime` of the next block (i.e. current behavior).
>   * If it is tails, use a relative-locktime `nSequence` equal to the confirmations of the output being spent, and an `nLockTime` of 0.
>
> Then we would hide the Lightning relative-locktime transactions with an `nLockTime` of 0.

Commitment transactions for current two-party LN have at least two outputs; the chance of both outputs being spent with an nLockTime of 0 is 25% (assuming every non-LN onchain transaction uses the above scheme). That's a fairly significant bias that can be combined with other indicators to identify LN transactions for analytics or censorship.

-Dave

ZmnSCPxj in reply to David A. Harding permalink original

Good morning David,

Quoted text (15 lines)
> On Tue, Jan 07, 2020 at 12:26:05AM +0000, ZmnSCPxj wrote:
>
> > For `nSequence` relative-locktime transactions that protect the
> > security of the channel mechanism, these are used in unilateral
> > closes. The issue is that a unilateral close might occur far, far in
> > the future. Thus, any non-0 `nLockTime` you signed up for at the time
> > the commitment transaction was signed, will likely be obsolete.
>
> As long as there's no conflict created by using both relative and
> absolute locktimes in the same transaction, I don't think there's any
> problem. Multiple versions of a commitment transaction may be signed,
> each with different nLockTimes but all other parts of the transaction
> the same (including any relative timelocks). This obviously requires a
> tiny bit of extra CPU plus modest amounts of extra bandwidth and
> storage, but it seems within reason for people who want better privacy.

Yes, but how many `nLockTime` candidates are enough? If there is not enough granularity, then you will be forced to use an `nLockTime` that is in the past, and if the blockchain layer is not congested then, it is a smoking gun of such pre-signed transactions. Either that or you wait for the next available `nLockTime`.

Further, there must always exist some limit on the largest-`nLockTime` commitment transaction you keep. If the largest-`nLockTime` commitment transaction is now approaching, and the counterparty goes offline, then you have a Morton fork:

* Drop the commitment transaction at the correct blockheight now.
  * You regret this later if the counterparty comes online, since now your channel is in a closed state.
* Keep the channel open.
  * You regret this later if the counterparty remains offline, since now your commitment transaction is badly out-of-date and you lose privacy if you drop it.

We see this already with `update_fee` disagreements, if the funder gives an apparently-lowball fee estimate, do you drop now (and lose possible revenue), or do you wait (and risk that later, that lowball fee estimate is even lower for the current situation). Due to user complaint we have gone the "wait and maybe suffer later" route but that is the choice that leaks privacy in the above fork.

Quoted text (14 lines)
>
> > Instead, what Bitcoin Core would have to do would be something like:
> >
> > -   Toss a coin:
> >     -   If it is heads, use a non-relative-locktime `nSequence` and an `nLockTime` of the next block (i.e. current behavior).
> >     -   If it is tails, use a relative-locktime `nSequence` equal to the confirmations of the output being spent, and an `nLockTime` of 0.
> >
> > Then we would hide the Lightning relative-locktime transactions with an `nLockTime` of 0.
>
> Commitment transactions for current two-party LN have at least two
> outputs; the chance of both outputs being spent with an nLockTime of 0
> is 25% (assuming every non-LN onchain transaction uses the above
> scheme). That's a fairly significant bias that can be combined with
> other indicators to identify LN transactions for analytics or censorship.

Hmm?

Assuming both counterparties have a balance on the channel, then at least one of the outputs must be spendable (disregarding the revocation branch) with a relative lock time, so if we select between "0 `nLockTime` but enabled `nSequence`" vs "current blockheight plus one `nLockTime`" at 50%, and there are only the two "main" outputs and no PTLCs, then you get exactly 50% of the outputs being spent with one policy and 50% being spent with the other policy.

Basically, on every Poon-Dryja commitment transaction, assuming there are no PTLCs/HTLCs and both sides have money in the channel, then:

* one output will be directly spendable by the remote side.
* one output will be spendable by the local side, but only after a relative locktime from the commitment transaction.

So if the remote side uses an `nLockTime`-enabled transaction, and the local side uses a `nSequence`-enabled transaction to scriptlessly implement relative locktime, then we match the 50% coin toss.

Unless you are referring to something else?

Regards, ZmnSCPxj

David A. Harding in reply to ZmnSCPxj permalink original

On Sun, Jan 12, 2020 at 03:01:06PM +0000, ZmnSCPxj wrote:

Quoted text (9 lines)
> Basically, on every Poon-Dryja commitment transaction [...]
>
> * one output will be directly spendable by the remote side.
> * one output will be spendable by the local side [...] after a
>   relative locktime [...]
>
> So if the remote side uses an `nLockTime`-enabled transaction, and the
> local side uses a `nSequence`-enabled transaction to scriptlessly
> implement relative locktime, then we match the 50% coin toss.

That's better, but I don't think it's quite as good as you claim.

Given a parent transaction with two outputs which are spent as two separate child transactions, the four equal-probability outcomes for a non-LN wallet that randomly sets either nSequence or nLockTime are:

    | child 0   | child 1   |
    |-----------|-----------|
    | nLockTime | nLockTime |
    | nLockTime | nSequence |
    | nSequence | nLockTime |
    | nSequence | nSequence |

You're proposing that either (nLockTime, nSequence) or (nSequence, nLockTime) be used. That's 50% of the options, which is not the same as the results of a 50% coin toss. A block chain analyst can rule out any transactions pairs using (nLockTime, nLockTime) or (nSequence, nSequence) as unilateral closes. This eliminates 50% of transactions from the anonymity set protecting LN unilateral closes.

We could obviously improve that by having the remote side randomly select between nLockTime and nSequence for its transaction, but I don't believe that you ever get access to the full anonymity set like you do when dual timelocking.

-Dave

ZmnSCPxj in reply to David A. Harding permalink original

Good morning David, and list,

It seems to me possible (though potentially undesirable) to have a "maximally private" channel that uses *only* absolute locktimes.

For maximum privacy, you would need to sign new pairs of commitment transactions at every block anyway. And if you sign a new pair "too late", you run the risk that a block will arrive and then make your transaction obviously not match the Bitcoin Core anti-fee-sniping behavior, thus distinguishable, thus non-private, so to preserve the privacy of your channels you would have to drop onchain as soon as a block arrives but your counterparty is not responding quickly enough to sign a new commitment transaction (and all the dreary other transactions needed to make the commitment transaction actually contain the contracts you want, in Scriptless Script form) *and* revoke the previous commitment transaction.

So suppose you start at block height N. You and your counterparty sign commitment transactions that have an `nLockTime` of N+2.

The consideration here is that if those commitment transactions are unrevoked as of block height N+2, then one or the other commitment transaction ***will*** be dropped onchain, because if not then the transaction will be "out of place" in the block and obviously is not a Bitcoin Core anti-fee-sniping transaction.

Now, for a commitment transaction to be revocable, the outputs that are owned by the holder of the commitment transaction must be revocable. Typically, that is implemented by adding a relative-timelock, and a branch that allows immediate revocation. Both branches can be actually be implemented in Scriptless Script: relative-locktime by pre-signing an `nSequence`d transaction, immediate revocation by revealing your share of the pubkey.

But note that we have a strong promise that this commitment transaction will appear at block height N+2 (unless revoked by then), because privacy. So we know as well that the "relative-locktime" branch will appear at block height N+2+R, where R is the relative-locktime. Since we already know what *absolute* blockheight we want it to appear in, we could just use an absolute-locktime `nLockTime` requirement, with the pre-signed N+2+R for that transaction that spends the commitment transaction.

So the relative-locktime times needed here can instead be transposed to absolute locktimes, i.e. `nLockTime`d transactions that are indistinguishable from Bitcoin Core anti-fee-sniping transactions.

So no need to modify the Bitcoin Core to use `nSequence` as well for anti-fee-sniping.

Why is the commitment transaction set up with an `nLockTime` of N+2? Because if a block arrives, the block height is now N+1. So now the participants have to create a pair of commitment transactions at N+3 and revoke their held N+2 transactions. If not, then they have to drop the N+2 commitment transaction *now* so that miners can include them in the *next* block at height N+2.

(We could switch to N+3 instead, that at least gives a one-block-duration limit for the other side to respond in and update their transactions)

Of course, the drawbacks are:

* If this is widespread, there will be bursts of activity on the Lightning network at every block.
* The use of MuSig Schnorr signing means a good amount of turnarounds, which is bad for high-latency connections like Tor hidden services, further compounded by the need to perform such signing rituals at each block.
* As soon as your counterparty drops offline, the channel between you will now be at high risk of simply being dropped onchain right now, i.e. closing.

But note the extreme privacy! Now there is no need for relative locktimes, just absolute ones, and we already have a plausible anonymity set for absolute-locktime transactions (Bitcoin Core anti-fee-sniping). With Schnorr and Scriptless Script, and the above technique of "just sign new commitments at every block", even a unilateral close is indistinguishable from normal spends by Bitcoin Core, and if you still use an unpublished channel (perish the thought!) they are no longer obvious to onchain analysis as Lightning Network channels.

Regards, ZmnSCPxj

ZmnSCPxj in reply to ZmnSCPxj permalink original

Good morning list,

Quoted text (19 lines)
> Good morning David, and list,
>
> It seems to me possible (though potentially undesirable) to have a "maximally private" channel that uses only absolute locktimes.
>
> For maximum privacy, you would need to sign new pairs of commitment transactions at every block anyway.
> And if you sign a new pair "too late", you run the risk that a block will arrive and then make your transaction obviously not match the Bitcoin Core anti-fee-sniping behavior, thus distinguishable, thus non-private, so to preserve the privacy of your channels you would have to drop onchain as soon as a block arrives but your counterparty is not responding quickly enough to sign a new commitment transaction (and all the dreary other transactions needed to make the commitment transaction actually contain the contracts you want, in Scriptless Script form) and revoke the previous commitment transaction.
>
> So suppose you start at block height N.
> You and your counterparty sign commitment transactions that have an `nLockTime` of N+2.
>
> The consideration here is that if those commitment transactions are unrevoked as of block height N+2, then one or the other commitment transaction will be dropped onchain, because if not then the transaction will be "out of place" in the block and obviously is not a Bitcoin Core anti-fee-sniping transaction.
>
> Now, for a commitment transaction to be revocable, the outputs that are owned by the holder of the commitment transaction must be revocable.
> Typically, that is implemented by adding a relative-timelock, and a branch that allows immediate revocation.
> Both branches can be actually be implemented in Scriptless Script: relative-locktime by pre-signing an `nSequence`d transaction, immediate revocation by revealing your share of the pubkey.
>
> But note that we have a strong promise that this commitment transaction will appear at block height N+2 (unless revoked by then), because privacy.
> So we know as well that the "relative-locktime" branch will appear at block height N+2+R, where R is the relative-locktime.
> Since we already know what absolute blockheight we want it to appear in, we could just use an absolute-locktime `nLockTime` requirement, with the pre-signed N+2+R for that transaction that spends the commitment transaction.

No, sorry, this is insecure, because the "revoked by then" branch still exists, this is daft, lower-level cognition agents proposing this have been reduced in influence in the overall community of sub-agents. So no, we still need relative-locktime here.

I would also like to point out that the revelation of relative-locktime requirements would only happen in a unilateral honest closs (they can be hidden in a unilateral dishonest close that is caught and revoked, by using the revocation key as a shard of the Taproot key). Mutual closes can be simple spends in a Taproot future of a Schnorr output, and thus have good privacy. I have not trawled the data yet but I believe unilateral closes are a tiny fraction of mutual closes, so this privacy leak might be acceptable.

Against this, however, we might consider that as Lightning becomes more stable, deliberate closure of channels becomes less likely, meaning more closes will be "accidental", e.g. bugs, nodes going offline, etc. Thus unilateral closes may increase in proportion compared to mutual closes in the future, in which case we might want to re-consider privacy for unilateral closes.

Regards, ZmnSCPxj