Skip to content
LearnBitcoin

ResearchBitcoin Dev Archive lightning-dev list

Improving Payment Latency by Fast Forwards

13 messages, Apr 24, 2019, to Jun 20, 2021. Started by ZmnSCPxj.

ZmnSCPxj (9), Lloyd Fournier (4)

Permalink First message in the Wayback Machine

ZmnSCPxj permalink original

Introduction ============

Currently, the protocol for forwarding requires 1.5 round trips before the next node can safely forward the payment. This creates much greater latency for payments, and even with the current network at a nascent stage, payments can take entire seconds to complete. As the network grows and some nodes start becoming unable to store the entire routemap, remote route lookups are needed. Remote route lookups are likely to increase the route length, thus payment latency will increase even more.

So, we should consider ways of improving payment latency, before the increasing LN size causes further increases in payment latency. Like all optimizations, it is likely that we will need to run as fast as we can, just to stay in one place, like the Red Queen.

Slow Forwarding ---------------

The current protocol for a single forward looks like:

      Alice                     Bob                     Carol
        |                        |                        |
        | ---update_add_htlc---> |                        |
        | --commitment_signed--> |                        |
        |                        |                        |
        | <-commitment_signed--- |                        |
        | <--revoke_and_ack----- |                        |
        |                        |                        |
        | ---revoke_and_ack----> |                        |
        |                        | ---update_add_htlc---> |

Bob cannot safely forward `update_add_htlc` immediately since there is no commitment transaction that contains the HTLC yet. Further, even when a new pair of commitment transactions is signed by Alice, two commitment transactions can still safely be put onchain, one of which does not contain the HTLC. Only when Alice and Bob have revoked their previous commitment transaction can Bob safely forward to Carol.

The above concept is called "irrevocably committed" by the BOLT spec.

To reach this "irrevocably committed" state, requires the above 1.5 round trips. If Alice and Bob are physically distant from each other, communication latency can be very large.

Further, both Alice and Bob want to reduce bandwidth usage. This sometimes means that Alice and Bob will wait a short while before signing commitments and revoking previous ones, in order to keep the number of new signatures being passed around small. C-lightning, for example, defers signing a new commitment by 10ms after sending an update in case another forward on the same channel is requested. This causes additional latency on top of the communication latency.

Poon-Dryja Outputs ------------------

Let me now digress, to investigate the outputs of a Poon-Dryja commitment transaction.

There are at least two commitment transactions that are valid at any one time, one for each node in the channel. Each one is symmetrical, but different. Thus, there is the concepts below:

1.  "local" commitment transaction, is the valid commitment transaction I am holding.
2.  "remote" commitment transaction, is the valid commitment transaction my counterparty is holding.

Each commitment transaction has at least two outputs (although one may be elided if too small or 0). Thus, each commitment transaction has these two outputs:

1.  "to-local" output.
    On the local commitment transaction, this is my "main" output.
    On the remote commitment transaction, this is my counterparty "main" output.
2.  "to-remote" output.
    On the local commitment transaction, this is my counterparty "main" output.
    On the remote commitment transaction, this is my "main" output.

In the original Poon-Dryja formulation, the "to-remote" output pays directly to a P2WPKH. However, the "to-local" output is encumbered by a CSV, and is revocable. In the BOLT 1.0 spec, the SCRIPT is:

    OP_IF
        # Penalty transaction
        <revocationpubkey>
    OP_ELSE
        `to_self_delay`
        OP_CSV
        OP_DROP
        <local_delayedpubkey>
    OP_ENDIF
    OP_CHECKSIG

Of note, is that the `revocationpubkey` is actually a combination of the local node revocation key, and a remote node key. It is like a 2-of-2 that cannot be signed cooperatively by both parties, but which the local node can give entirely to the remote node so that the remote node can sign by itself (revocation). It could have been implemented as a 2-of-2 multisignature, but the above formulation takes less block space.

In the recent Lightning Developer Summit in 2018, it was decided that the "to-remote" output will also be encumbered by a CSV. I will propose in this writeup, that a modification of the above script be used in both "to-local" and "to-remote".

Fast Forwards =============

Ideally, we would like to be able to say that an HTLC is "irrevocably committed" using only a single message from Alice to Bob. That way, communication latencies when forwarding payments can be reduced, which should improve payment speed over the network in general.

I observe that one may consider any offchain system a specialization of an offchain transaction cut-through system. Thus, one may model changes to the offchain system state as the creation of some transactions, followed by a cut-through of those transactions into the new state.

Thus, I propose that to-local outputs be encumbered with the script:

    OP_IF
        # Penalty transaction/Fast forward
        <local_revokepubkey> OP_CHECKSIGVERIFY <remote_penaltyclaimpubkey>
    OP_ELSE
        `to_self_delay`
        OP_CSV
        OP_DROP
        <local_delayedpubkey>
    OP_ENDIF
    OP_CHECKSIG

Then, symmetrically, to-remote outputs are encumbered with the script:

    OP_IF
        # Penalty transaction/Fast forward
        <local_revokepubkey> OP_CHECKSIGVERIFY <remote_penaltyclaimpubkey>
    OP_ELSE
        `to_self_delay`
        OP_CSV
        OP_DROP
        <remote_delayedpubkey>
    OP_ENDIF
    OP_CHECKSIG

When doing a `revoke_and_ack`, the sender gives the `local_revokeprivkey` to the remote side, who now knows both keys to the penalty branch and can now penalize the sender if the revoked commitment transaction is published.

Then, we define a new message, `fastforward_add_htlc`. This creates a pair of transactions, the fast-forward HTLC transactions, on top of the latest commitment transactions of both nodes. For simplicity, they can be restricted to be sent only while one commitment transaction is valid on both sides and while no update is in-flight in the channel. (alternatively, a channel using fast-forwards might be restricted to *only* using fast-forwards, with updates of commitment transactions being in strong synchrony rather than the weak synchrony currently used)

The local/remote fast-forward HTLC transaction spends the to-local/to-remote output of the commitment transaction. It spends the value of the HTLC being forward to the normal HTLC construction used in Lightning. The remaining change is placed into "the same" script that was spent (with pubkeys changed). This change output can now be considered the "next" main output (it is used to chain the next `fastforward_add_htlc` from that side).

The `fastforward_add_htlc` includes the originating node signatures for both the local and remote fast-forward HTLC transactions. It also contains the signatures needed to support the revocable HTLC construction.

For example, the local fast-forward HTLC transaction spends the to-local output of the local commitment. The sending node signs using the `local_revokepubkey` and includes this signature in the `fastforward_add_htlc` message. The remote fast-forward HTLC transaction spends the to-remote output of the remote commitment. The sending node signs using the `remote_penaltyclaimpubkey` and includes this signature in the `fastforward_add_htlc` message.

The receiver of the message can now consider this HTLC to be irrevocably committed. This is because it can now spend the main output of the counterparty using the fast-forward HTLC transactions by providing the other missing signature. Further, the sender cannot revoke it since it cannot double-spend that transaction until after the CSV restriction. The CSV restriction is precisely how long the receiver can be offline before a successful theft can be performed, so it should not be an issue for the receiver.

Thus, upon receipt of the `fastforward_add_htlc`, it is now possible for Bob to immediately begin forwarding the payment onward:

      Alice                     Bob                     Carol
        |                        |                        |
        | -fastforward_add_htlc> |                        |
        |                        | -fastforward_add_htlc> |

(if Carol does not support fast forwards, Bob can send the old `update_add_htlc` instead.) Then, the next commitment transaction will "cut-through" any built up fast-forward HTLC transactions, collapsing the HTLC outputs to the commitment transactions.

Unilateral Closes -----------------

Unfortunately, unilateral closes mean that, if the counterparty is not paying attention, they will not be able to claim any HTLC added via `fastforward_add_htlc`. Now, the CSV setting one selects should reflect how long one feels their node can remain offline. And as long as we are able to come back online before the CSV is reached, we can apply any fast-forward HTLC transactions and claim the HTLCs that have dropped onchain.

Of course, the real world has many ways to surprise our expectations. Thus, using fast-forwards implies higher risk for nodes that accept fast forwards and which then themselves forward immediately.

Fast Failures =============

Fast forwards are not enough: due to incomplete information, failures of individual payment routing attempts are common. The directive is to simply try and try again until the payment pushes through or no routes remain or too much time has been spent trying to route.

Further, success is already fast: as soon as you receive `update_fulfill_htlc` you can immediately safely send `update_fulfill_htlc` to upstream without the commitment signing and revocation of previous commitment.

However, failures via `update_fail_htlc` cannot be propagated immediately for a similar reason that payments via `update_add_htlc` cannot be propagated immediately: there exists a valid commitment that still has the HTLC by which the money can still be claimed onchain.

I observe that the "fast forward" technique simply reuses the revocation path to root a new transaction. I also observe that the HTLC construction used by Lightning is revocable.

Thus, since it is possible to revoke the HTLC construction used by Lightning, we can reuse the revocation path of an HTLC as the "fast failure" path, using the same technique we used in fast forward. Care must be taken to provide signatures for failing the HTLC itself, as well as the HTLC-success and HTLC-timeout transactions.

The difference here is that failed HTLCs do not contribute back to the "main" output immediately. The transaction used to fail the HTLC is a simple one-input one-output transaction. Only when failure of the HTLCs has been put in a new commitment transaction can their value be reused for adding new HTLCs.

For example, suppose we start with 3mBTC on my side of the channel. I offer two different HTLCs to you, of 1mBTC each, by two `fastforward_add_htlcs`. However, both of them fail. This leaves me with only 1mBTC on my main output, with two different 1mBTC outputs that have not been "merged" back into it yet. So I can no longer forward a 2mBTC HTLC, until we have resynchronized (signed new commitments and revoked) and combined the failed HTLC outputs back to my main output.

Still, this removes the commitment transaction synchronization away from the critical path in the overall Lightning try-and-try-until-you-die routing algorithm, improving payment latency overall. Thus, this may be an acceptable tradeoff when considering payment latency.

Fees ====

Oh no.

Please do not ask about fees.

In case of a unilateral close after a fast-forward or fast-fail, additional transactions need to be put onchain, beyond just the commitment transactions. These transactions need to pay for onchain fees.

Thus, channels offering low-latency fast forwards need to charge higher offchain fees to offset the risk that they need to pay onchain fees. Further, channels offering low-latency fast forwards also need to offset the unilateral close risk with higher fees.

Perhaps the two nodes on the channel can attest that they have low-latency fast forwards. However, merely because they claim it does not make it so.

Nodes could make known-failing payments (generate a random payment hash, route through the "fast forward"-claiming channel, measure latency) to determine the truth of the fast forward. In fact, if nodes do this "in the background" continuously, they can map out which channels have good latency (regardless of the use of fast forward or not: two nodes located physically close to each other with low-latency internet connections may very well have good enough latency even without fast forwards).

Fast Forwards on Decker-Russell-Osuntokun =========================================

Decker-Russell-Osuntokun does not, in fact, need fast forwards, if we design the link-level protocol properly.

Each "add HTLC" "fulfill HTLC" "fail HTLC" "change fee" update message includes the signature needed for the next update transaction and the next state transaction, that immediately has the new state. Then the peer should reply with the remaining signatures needed immediately.

Upon receiving an "add HTLC", one can now construct the full next update transaction/next state transaction, and the existence of this update transaction is enough to invalidate any previous update transaction. So it is safe to forward the "add HTLC" to the next hop immediately as soon as the node can update its local database. This is different from Poon-Dryja, where the existence of the next commitment transactions does not imply that the previous commitment transaction is revoked.

Of course, there is now the issue of "how do we handle when both nodes want to update at the same time and sent conflicting 'next update' messages?" Perhaps it can be left as an exercise to the reader how to do this while not requiring any round trips in the critical path of forwarding, in the typical case. For instance, if one has sent an update but receives an update in return, coordinate with the counterparty, do not forward yet, and then figure out a common "next" update/state transaction that has both updates, then continue with forwarding the update you received.

ZmnSCPxj in reply to ZmnSCPxj permalink original

Good morning list,

I have decided to dabble in necromancy, thus, I revive this long-dead thread from two years ago. Ph34R mE and my leet thread necromancy skillz.

A short while ago, LL and Steve Lee were discussing about ways to reduce the privkey onlineness requirement for Lightning. And LL mentioned that this proposal could allow privkeys to be kept offline for a receiver.

* The receiver has to be online, still.
* Its privkeys can be kept offline.
  * The receiver can still receive even if its privkeys are offline (for example the privkeys are in a hardware signing module that is typically kept offline and is only put online at rare intervals).
* The sender has to be online and the sender privkeys have to be online.
* Forwarders and their privkeys have to be online.

Unfortunately, I think the proposal, as currently made, cannot support the above feature, as stated.

When an HTLC transaction is provided by the sender under a Fast Forward scheme, it provides a transaction that spends from "its" output in both versions of the latest Poon-Dryja commitment transaction.

However, this output, as provided in the Fast Forward scheme, requires *two* signatures.

Here are the scripts mentioned in the previous post:

    OP_IF
        # Penalty transaction/Fast forward
        <local_revokepubkey> OP_CHECKSIGVERIFY <remote_penaltyclaimpubkey>
    OP_ELSE
        `to_self_delay`
        OP_CSV
        OP_DROP
        <local_delayedpubkey>
    OP_ENDIF
    OP_CHECKSIG

And:

    OP_IF
        # Penalty transaction/Fast forward
        <local_revokepubkey> OP_CHECKSIGVERIFY <remote_penaltyclaimpubkey>
    OP_ELSE
        `to_self_delay`
        OP_CSV
        OP_DROP
        <remote_delayedpubkey>
    OP_ENDIF
    OP_CHECKSIG

Now, the first branch is what is used in the Fast Forward scheme. And we can see that in the first branch, two signatures are needed: one for local, and one for remote.

Thus, any HTLC-bearing transactions are signed by both the sender and receiver. Fast Forwards works its low-latency magic by simply having the sender send the signature spending from the current channel state, outright, to the receiver, and until the channel is updated, the HTLC is "safe":

* The current channel state (represented by some commitment tx) cannot be replaced with an alternative, without the replacer risking funds loss (Poon-Dryja punishment mechanism).
* The spending tx that instantiates the HTLC is safe because the receiver will not willingly sign an alternate version.

***HOWEVER***, the HTLC is safe on the assumption that *the receiver can provide its signature* if the channel is dropped onchain. And channels can be dropped onchain *at any time*. If the receiver is unable to provide its signature before the `to_self_delay` finishes, then the sender can revoke ***all*** HTLCs it sent!

Thus, at least as initially stated, Fast Forwards cannot be used for this "receiver online, privkeys offline, can receive" feature.

***HOWEVER HOWEVER***, we should note that the caveats are something we can actually work with:

* The privkeys can only be offline for up to `to_self_delay` blocks.
  * We ***need*** privkeys to be periodically online more often than `to_self_delay` anyway, ***in case of theft attempts***.
    So this is not an ***additional*** requirement at least.
* Watchtowers cannot guard against attempts to steal Fast Forwarded HTLCs --- they need to receive the signatures for the HTLC transactions as well, otherwise they can do nothing about it.
  * However, whenever the receiver sends to a watchtower it *does* need to send signatures anyway, so it still needs to get privkeys online for signing.
  * Since we need the privkeys to be made online a little more often than every `to_self_delay` blocks anyway, this is *not* an additional requirement!

***THUS***, we *can* provide a tweaked version of the above desired feature:

* The receiver has to be online, still.
* Its privkeys can be kept offline, ***BUT***, it has to be regularly brought online a little more often than `to_self_delay`.
  * The receiver can still receive even if its privkeys are offline (for example the privkeys are in a hardware signing module that is typically kept offline and is only put online at rare intervals).
* The sender has to be online and the sender privkeys have to be online.
* Forwarders and their privkeys have to be online.

The additional requirement --- that the receiver privkeys have to be regularly brought online --- is not actually an onerous one *since we need it for channel safety*.

So this feature is indeed supported by Fast Forwards (with fairly minimal caveats!) and kudos to LL for thinking of it!

Against this, we should remind the drawbacks of Fast Forwards:

* Onchain space is much higher (in the unilateral close case only --- channel opens and mutual closes remain small) due to chaining of transactions instead of strict replacement.
* Fast Forwarded HTLCs need to have their signatures stored on replicated storage, and is O(n) (current Poon-Dryja requires O(1) storage for revocation keys but O(n) storage for HTLC hash/timelock details).
  If you lose your data storage, you lose received HTLCs, including those whose preimages you have already released.

For this, we should also take note that:

* Payment latency is greatly improved.
* The above "receiver online, receiver privkeys offline, can receive" feature is now possible, with the caveat:
  * The privkeys need to be periodically brought online for short amounts of time in order to "collapse" chains of HTLC transactions, recover from theft attempts, and update watchtowers etc.

---

Now, Fast Forwards is a scheme that is designed for a modified form of Poon-Dryja.

Unfortunately, at least for now, it seems the scheme cannot be used in Decker-Russell-Osuntokun ("eltoo").

In particular, Fast Forwards work because it is safe (and even required!) for a Poon-Dryja scheme to impose timeouts on the "main" outputs of a channel. And those timeouts have a branch that is a 2-of-2 between the channel participants. That branch is where Fast Forwards hook into.

In Decker-Russell-Osuntokun, the "main" outputs are not encumbered by any timeouts; they are simple singly-signed outputs. The timeout is instead placed "before" the state transactions that contain the "main" outputs. The HTLC transactions are not safe without a 2-of-2, as otherwise the sender could just spend the main output to a different address, removing the HTLC.

Because of this, the "main" output of a Decker-Russell-Osuntokun cannot be used in a Fast Forwarded manner, as the Fast Forwarded transaction needs to be signed by both participants.

We *could* add *another* timeout at the main output simply to support Fast Forwards, using a similar "2of2 or OP_CSV+singlesig". However, this increases the effective delay in the case the channel is dropped unilaterally onchain.

In addition, we should remind that when forwarding, Decker-Russell-Osuntokun requires that the CLTV at a particular hop be larger than the `to_self_delay` at that hop i.e. it imposes a "minimum CLTV" cost that is combined with `max` instead of `+`, which pathfinding algorithms (that I know of) are totally not designed for.

Furthermore, properly designed, a Decker-Russell-Osuntokun construction could also have payment latency approaching the latency of the Fast Forward scheme, so that advantage of Fast Forwards is lost as well, so we are paying for more inconvenience for a smaller feature set (only the "receiver online, privkey offline" feature remains; maybe worth it?).

Of note, is that there also exists a Poon-Dryja variant that has a similar structure to Decker-Russell-Osuntokun (and has the same drawback of requiring a "minimum CLTV" at each hop) --- Fast Forwards would also not work well with that particular Poon-Dryja variant, too.

Regards, ZmnSCPxj

ZmnSCPxj in reply to ZmnSCPxj permalink original

Good morning list,

Note that there is a possible jamming attack here.

More specifically, when "failing" an incoming HTLC, the receiver of the HTLC sends its signature for a transaction spending the HTLC and spending it back to the sender revocable contract. The funds cannot be reused until the channel state is updated to cut-through all the transactions (the HTLC transaction and the failure transaction). (Well it *could* but that greatly amps the complexity of the whole thing --- no, just no.)

Thus I could jam a particular receiver by sending, via forwarding nodes, to that receiver, payments with a random hash, which with high probability have preimages that are unknown by the receiver. The receiver can only fail those HTLCs, but "to fail an HTLC" under Fast Forwards makes the funds unusable, until the previous channel state can be revoked and replaced with a new one. But updating the channel state requires privkeys to be online in order to create the signatures for the new channel state.

This creates a practical limit on how long you can keep privkeys offline; if you keep it offline too long, an attacker can jam all your incoming capacity for long periods of time. This is not currently a problem without "receiver online, privkey offline", since without "privkey offline" case, the receiver can update the channel state immediately.

However, if the receiver is willing to lose privacy, the protocol can be mildly modified so that the receiver tells the forwarding node to *first* ask the receiver about every HTLC hash before actually instantiating and sending the HTLC. Only if the receiver agrees will the forwarder actually send the HTLC.

The forwarder is incentivized to go along with this, as otherwise, the receiver cannot actually fail any HTLCs --- it needs to provide a signature, and signatures require privkeys, and the receiver has those offline. Thus, the forwarder would prefer to ask the receiver *before* it instantiates the HTLC, as otherwise the HTLC cannot be cancelled until the receiver gets its privkeys online, which can take a long time --- and if the HTLC times out in the meantime, that can only be enforced by dropping onchain, and Fast Forwards are *very* expensive in the unilateral close case.

Obviously this tells the forwarding node that the channel is used for receiving and that any payments over it terminate at the next hop, thus a privacy degradation. On the other hand, unpublished channels remain popular despite my best efforts, and this is the exact problem unpublished channels have, so ---- not a degradation in privacy in practice, since users of unpublished channels already have degraded privacy (axiom of terminus),

This also increases latency once again, as there is now 1.5 roundtrips (forwarder asks receiver if this forwarded HTLC is kosher, receiver responds, forwarder sends signature to HTLC transaction). However, the increased latency only occurs at the endpoint; forwarders (which need to have privkeys online 100% of the time anyway, and can thus cut-through any number of failed HTLCs at any time) can skip the "is this HTLC kosher" message and just send the HTLC signatures immediately. Thus, this may be an acceptable tradeoff.

Thus, one might consider this scheme to be usable for *either* Fast Forwards, *or* "receiver online, privkeys offline", but not usefully both (after all, a forwarder is both a receiver and a sender, and a sender needs its keys in order to send, so it cannot use the "privkeys offline" feature anyway).

It may be difficult to understand this, so maybe I will make a convenient presentation of some sort.

Regards, ZmnSCPxj

Lloyd Fournier in reply to ZmnSCPxj permalink original

Hey Z,

Thanks for your analysis. I agree with your conclusion. I think the most practical approach is the "ask first" 3 round protocol.

Another option is to have `remote_penaltyclaimpubkey` owned by the node instead of the hardware device. This allows funds to accrue in the fast forward state which can be swept into the commit tx at the merchants discretion. If a fast forward state needs to be asserted on-chain it can then be done automatically without the hardware device. Of course, the funds in the FF state are more vulnerable than the main channel balance during that time because their keys are not in a secure device but this seems ok. The obvious analogy is to having cash in the till (less secure) that you send to your bank (more secure™) at the end of the day or week.

Quoted text (3 lines)
> We ***need*** privkeys to be periodically online more often than
`to_self_delay` anyway, ***in case of theft attempts***.
>  So this is not an ***additional*** requirement at least.

This is a really important point. I guess you have to actually do this periodically, only when there is an actual attempt at theft. Quite annoying to UX to require this.

Cheers,

LL

ZmnSCPxj in reply to Lloyd Fournier permalink original

Good morning LL,

Quoted text (9 lines)
> Hey Z,
>
> Thanks for your analysis. I agree with your conclusion. I think the most practical approach is the "ask first" 3 round protocol.
>
> Another option is to have `remote_penaltyclaimpubkey` owned by the node instead of the hardware device.
> This allows funds to accrue in the fast forward state which can be swept into the commit tx at the merchants discretion.
> If a fast forward state needs to be asserted on-chain it can then be done automatically without the hardware device.
> Of course, the funds in the FF state are more vulnerable than the main channel balance during that time because their keys are not in a secure device but this seems ok.
> The obvious analogy is to having cash in the till (less secure) that you send to your bank (more secure™) at the end of the day or week.

This seems a useful technique.

Quoted text (5 lines)
>
> > We ***need*** privkeys to be periodically online more often than `to_self_delay` anyway, ***in case of theft attempts***.
> >  So this is not an ***additional*** requirement at least.
>
> This is a really important point. I guess you have to actually do this periodically, only when there is an actual attempt at theft. Quite annoying to UX to require this.

If you mean "***not*** only when there is an actual attempt at theft", yes.

My thought that this would be useful for a "big"-ish merchant that primarily accepts payments, to mitigate its key exposure. It would program a small low-power device such that it almost always has its network interface disabled, but periodically (at random times) it will enable its network interface and connect out to the node, presenting a proof that it holds the privkey. It would have a firewall so that it cannot receive incoming connection requests and can only make outgoing connection requests (and as noted above, most of the time the network interface would be disabled outright).

Then the node could wait for this hardware to contact it, and proceed to "roll up" any fast-forwarded HTLCs. This could also be an opportunity for the node to send out funds, for example to pay the salaries of employees or dividends to shareholders of the merchant.

Regards, ZmnSCPxj

ZmnSCPxj in reply to ZmnSCPxj permalink original

Good morning list,

Quoted text (1 line)
> It may be difficult to understand this, so maybe I will make a convenient presentation of some sort.

As promised: https://zmnscpxj.github.io/offchain/2021-06-fast-forwards.odp

The presentation is intended to be seen by semi-technical and technical people, particular those that have not read (or managed to fully read and understand) the original writeup in 2019. Simply "run" the presentation (F5 in LibreOffice), as the presentation uses callouts extensively for explication.

Regards, ZmnSCPxj

Lloyd Fournier in reply to ZmnSCPxj permalink original

Hi Z,

I just went through the presentation which made your thinking very clear. Thanks. I will not be able to match this effort so please bear with me as I try and explain my own thinking. I don't see why fast forwards (FF) need "symmetrically encumbered outputs"? To me the protocol should be asymmetric.

This is what I think happens when offering a FF HTLC: 1. The offerer creates and signs a new commitment tx as normal with the HTLC except it has the same revocation key as the last one. 2. The offerer patches their balance output by sending a tx spending from it to a new tx which has the HTLC output and their balance output (unencumbered).

The HTLC is now irrevocably committed from the perspective of the receiver. Now the receiver presents the pre-image and the offerer then:

1. The offerer creates and signs a new commitment tx as normal consolidating the funds into the receiver's balance output except once again it has the same revocation key as the last one. 2. The offerer patches their commitment tx balance output again by sending a tx spending from it to a new tx which splits into the receiver's balance (the value of the claimed HTLC) and the offerer's remaining balance.

You can repeat the above process without having the receiver's revocation keys online or their commitment tx keys for many HTLCs while the offerer still has balance towards the receiver. The on-chain cost is about the same as before for an uncooperative close.

Once the receiver brings their keys on line they can consolidate the FF state into a new commitment txs on both sides and with a proper revocation operate the channel normally. What has been the receiver up until now can finally send funds.

Am I missing something?

Cheers,

LL

On Mon, 31 May 2021 at 19:47, ZmnSCPxj via Lightning-dev < lightning-dev at lists.linuxfoundation.org> wrote:

Quoted text (22 lines)
> Good morning list,
>
> > It may be difficult to understand this, so maybe I will make a
> convenient presentation of some sort.
>
> As promised: https://zmnscpxj.github.io/offchain/2021-06-fast-forwards.odp
>
> The presentation is intended to be seen by semi-technical and technical
> people, particular those that have not read (or managed to fully read and
> understand) the original writeup in 2019.
> Simply "run" the presentation (F5 in LibreOffice), as the presentation
> uses callouts extensively for explication.
>
> Regards,
> ZmnSCPxj
>
>
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
>
ZmnSCPxj in reply to Lloyd Fournier permalink original

Good morning LL,

Quoted text (22 lines)
> Hi Z,
>
> I just went through the presentation which made your thinking very clear. Thanks.
> I will not be able to match this effort so please bear with me as I try and explain my own thinking.
> I don't see why fast forwards (FF) need "symmetrically encumbered outputs"? To me the protocol should be asymmetric.
>
> This is what I think happens when offering a FF HTLC:
> 1. The offerer creates and signs a new commitment tx as normal with the HTLC except it has the same revocation key as the last one.
> 2. The offerer patches their balance output by sending a tx spending from it to a new tx which has the HTLC output and their balance output (unencumbered).
>
> The HTLC is now irrevocably committed from the perspective of the receiver.
> Now the receiver presents the pre-image and the offerer then:
>
> 1. The offerer creates and signs a new commitment tx as normal consolidating the funds into the receiver's balance output except once again it has the same revocation key as the last one.
> 2. The offerer patches their commitment tx balance output again by sending a tx spending from it to a new tx which splits into the receiver's balance (the value of the claimed HTLC) and the offerer's remaining balance.
>
> You can repeat the above process without having the receiver's revocation keys online or their commitment tx keys for many HTLCs while the offerer still has balance towards the receiver.
> The on-chain cost is about the same as before for an uncooperative close.
>
> Once the receiver brings their keys on line they can consolidate the FF state into a new commitment txs on both sides and with a proper revocation operate the channel normally. What has been the receiver up until now can finally send funds.
>
> Am I missing something?

Basically, you are taking advantage of the fact that we **actually** let the commitments on both sides be desynchronized with each other. I tend to elide this fact when explaining, and also avoid it when planning protocols.

However I believe the idea is correct.

Anyway, as I understood it:

So suppose we start with this pair of commitment txes:

    +--------------------------+
    |  Commitment tx 1 of A    |
    +------------+-------------+
    |            | (A[0] && B) |
    |            |||(A && CSV) |
    |    SigB    +-------------+
    |            |      B      |
    |            |             |
    +------------+-------------+
    +--------------------------+
    |  Commitment tx 1 of B    |
    +------------+-------------+
    |    SigA    |      A      |
    |            |             |
    |            +-------------+
    |            | (A && B[0]) |
    |            |||(B && CSV) |
    +------------+-------------+

Now Alice wants to offer an HTLC to Bob. What Alice does is:

* **Retain** the Alice commitment tx and create an HTLC tx spending from it.
* **Advance** the Bob commitment tx (and letting it desync from the Alice commitment tx), adding the same HTLC.

So after Alice sends its new signatures, our offchain txes are:

    +--------------------------+    +--------------------------+
    |  Commitment tx 1 of A    |    |          HTLC Tx         |
    +------------+-------------+    +------------+-------------+
    |            | (A[0] && B) |--->|  SigA[0]   | (A[0] && B) |
    |            |||(A && CSV) |    |            |||(A && CSV) |
    |    SigB    +-------------+    |            +-------------+
    |            |      B      |    |            |    A->B     |
    |            |             |    |            |    HTLC     |
    +------------+-------------+    +------------+-------------+
    +--------------------------+
    | Commitment tx *2* of B   |
    +------------+-------------+
    |    SigA    |      A      |
    |            |             |
    |            +-------------+
    |            | (A && B[1]) |
    |            |||(B && CSV) |
    |            +-------------+
    |            |    A->B     |
    |            |    HTLC     |
    +------------+-------------+

Notes:

* Again, for Alice to offer the HTLC to Bob, only Alice has to make new signatures (`SigA[0]` and `SigA` for commitment tx *2* of Bob).
* If Alice goes offline and Bob decides to drop onchain, Bob only needs to sign the new commitment tx.
  We can argue that dropping channels *should* be rare enough that requiring privkeys for this operation is not a burden.
* If Alice decides to drop the channel onchain, Bob only needs to bring in the privkey for the HTLC tx, which we can (at a lower, detailed level) be different from the "main" B privkey.

So yes, I think it seems workable without symmetric encumbrance.

Regards. ZmnSCPxj

ZmnSCPxj in reply to ZmnSCPxj permalink original

Good morning again LL,

So I started thinking as well, about Decker-Russell-Osuntokun and the Fast Forwards technique, as well as your "desync" idea.

And it seems to me that we can also adapt a variant of this idea with Decker-Russell-Osuntokun, with the advantage of **not** requiring the additional encumbrance at the outputs.

The technique is that we allow Bob the receiver to have possession of *later* states while Alice the sender only possesses an old state.

Alice sends the signatures for a new state (update + settlement) whenever it offers an HTLC to Bob, and whenever Bob fulfills the HTLC. However, Alice *does not* wait for Bob to return signatures for a new state. So Alice remains stuck with the old state.

* Suppose Alice wants to close the channel unilaterally.
  * Alice broadcasts the old update tx.
  * Bob has an incentive to bring its latest state onchain (bringing its privkey online and signing the latest update).
    * All the payments are in the Alice->Bob direction.
  * Even though Alice broadcasted an old state, it does not lose money since Decker-Russell-Osuntokun is non-punitive.
* Bob can bring its privkey online to close the channel unilaterally with the latest state.

So it looks to me that Decker-Russell-Osuntokun similarly does **not** require the additional encumbrance at the "main" outputs. We simply allow the sender to remain at an older state.

So let us give a concrete example.

* Alice and Bob start at state 1: Alice = 50, Bob = 50.
* Alice offers a HTLC of value 10.
  * Alice: state 1: Alice = 50, Bob = 50
  * Bob: state 2: Alice = 40, Bob = 50, A->B HTLC = 10
* Bob fulfills, so Alice sends a new state.which transfers the A->B HTLC value to Bob.
  * Alice: state 1: Alice = 50, Bob = 50
  * Bob: state 3: Alice = 40, Bob = 60
* Bob brings its privkey online because it wants to send out via Alice (a forwarder).
  It offers an HTLC B->A of value 20.
  * Alice: state 4: Alice = 40, Bob = 40, B->A HTLC = 20
  * Bob: state 3: Alice = 40, Bob = 60

Because publishing old state is "safe" under Decker-Russell-Osuntokun, it is fine for one participant to have *only* an older state! And we can arrange the incentives so that the one with the latest state is the one who is most incentivized to publish the latest state.

(We should probably change the subject of this thread BTW)

Another advantage here is that unlike the Poon-Dryja Fast Forwards, we do *not* build up a long chain of HTLC txes. At the worst case, we have an old update tx that is superseded by a later update tx instead, thus the overhead is expected to be at most 1 extra update tx no matter how many HTLCs are offered while Bob has its privkey offline.

Regards, ZmnSCPxj

Lloyd Fournier in reply to ZmnSCPxj permalink original

Hi Z,

I agree with your analysis. This is how I pictured eltoo fast forwards working as well.

Another interesting thing about this idea is that it could allow a new type of custodial LN provider where the custodian is only in charge of receiving payments to the channel but cannot spend them. With the non-custodial LN phone apps there is this annoying UX where you have to keep the app open to receive a payment (because the pre-image is on my phone). I wouldn't mind letting the provider handle receiving payments on my behalf. Of course this means they would be able to steal the money in the FF state but this is a big reduction in risk from a full custodial solution. In other words, you should be able to get the seamless experience of a fully custodial wallet while only giving them custody of small amounts of coins for a short time.

On Wed, 2 Jun 2021 at 13:30, ZmnSCPxj <ZmnSCPxj at protonmail.com> wrote:

Quoted text (8 lines)
>
> Another advantage here is that unlike the Poon-Dryja Fast Forwards, we do
> *not* build up a long chain of HTLC txes.
> At the worst case, we have an old update tx that is superseded by a later
> update tx instead, thus the overhead is expected to be at most 1 extra
> update tx no matter how many HTLCs are offered while Bob has its privkey
> offline.
>

I don't think you need to build up a long chain of HTLC txs for the Poon-Dryja fast forward in the "desync" approach. Each one just replaces the other.

Cheers,

LL

ZmnSCPxj in reply to Lloyd Fournier permalink original

Good morning LL,

Quoted text (9 lines)
> Hi Z,
>
> I agree with your analysis. This is how I pictured eltoo fast forwards working as well.
>
> Another interesting thing about this idea is that it could allow a new type of custodial LN provider where the custodian is only in charge of receiving payments to the channel but cannot spend them.
> With the non-custodial LN phone apps there is this annoying UX where you have to keep the app open to receive a payment (because the pre-image is on my phone).
> I wouldn't mind letting the provider handle receiving payments on my behalf.
> Of course this means they would be able to steal the money in the FF state but this is a big reduction in risk from a full custodial solution.
> In other words, you should be able to get the seamless experience of a fully custodial wallet while only giving them custody of small amounts of coins for a short time.

Yes, that is indeed a good advantage and thank you for this.

Quoted text (6 lines)
> On Wed, 2 Jun 2021 at 13:30, ZmnSCPxj <ZmnSCPxj at protonmail.com> wrote:
>
> > Another advantage here is that unlike the Poon-Dryja Fast Forwards, we do *not* build up a long chain of HTLC txes.
> > At the worst case, we have an old update tx that is superseded by a later update tx instead, thus the overhead is expected to be at most 1 extra update tx no matter how many HTLCs are offered while Bob has its privkey offline.
>
> I don't think you need to build up a long chain of HTLC txs for the Poon-Dryja fast forward in the "desync" approach. Each one just replaces the other.

Thinking about it more, this seems correct.

Referring back to the diagrams:

    +--------------------------+    +--------------------------+
    |  Commitment tx 1 of A    |    |          HTLC Tx         |
    +------------+-------------+    +------------+-------------+
    |            | (A[0] && B) |--->|  SigA[0]   | (A[0] && B) |
    |            |||(A && CSV) |    |            |||(A && CSV) |
    |    SigB    +-------------+    |            +-------------+
    |            |      B      |    |            |    A->B     |
    |            |             |    |            |    HTLC     |
    +------------+-------------+    +------------+-------------+
    +--------------------------+
    | Commitment tx *2* of B   |
    +------------+-------------+
    |    SigA    |      A      |
    |            |             |
    |            +-------------+
    |            | (A && B[0]) |
    |            |||(B && CSV) |
    |            +-------------+
    |            |    A->B     |
    |            |    HTLC     |
    +------------+-------------+

On the *next* HTLC, Alice just gives s commitment tx *3* `SigA`, and a replacement HTLC Tx `SigA[0]` to the cashier of Bob.

    +--------------------------+    +--------------------------+
    |  Commitment tx 1 of A    |    |       HTLC Tx *2*        |
    +------------+-------------+    +------------+-------------+
    |            | (A[0] && B) |--->|  SigA[0]   | (A[0] && B) |
    |            |||(A && CSV) |    |            |||(A && CSV) |
    |    SigB    +-------------+    |            +-------------+
    |            |      B      |    |            |    A->B     |
    |            |             |    |            |    HTLC     |
    +------------+-------------+    |            +-------------+
                                    |            |    A->B     |
                                    |            |    HTLC     |
                                    +------------+-------------+
    +--------------------------+
    | Commitment tx *3* of B   |
    +------------+-------------+
    |    SigA    |      A      |
    |            |             |
    |            +-------------+
    |            | (A && B[0]) |
    |            |||(B && CSV) |
    |            +-------------+
    |            |    A->B     |
    |            |    HTLC     |
    |            +-------------+
    |            |    A->B     |
    |            |    HTLC     |
    +------------+-------------+

This is safe, because:

* If Alice publishes Commitment tx 1 of Alice, Bob has every incentive to publish the HTLC Tx *2*, not the older HTLC Tx.
  * Alice cannot force publishing the *previous* HTLC Tx, because Alice has no `B` key and cannot force-publish it.
* If Bob wants to close unilaterally, it has every incentive to publish the latest Commitment tx ### of B, because that has the most HTLCs going to Bob.

Against the above we should note that the "HTLCs" we are talking about in Poon-Dryja are not simple contracts but are instead revocable HTLCs, which means additional dependent transactions. So I think the above *is* doable, but *does* require additional complexity and care, in that every A->B HTLC has to have some signatures exchanged as well (which, as they are HTLCs "in flight", we can have the keys on the cashier).

---------------------

I also have another subtlety to bring up with the above.

In particular, for a set of *simplex* Alice-to-Bob payments, Bob should ***not*** provide the revocation keys of older "commitment transactions owned by Bob".

That is, the cashier should ***not*** have access to the revocation keys.

Notice the above example:

    +--------------------------+
    | Commitment tx *2* of B   |
    +------------+-------------+
    |    SigA    |      A      |
    |            |             |
    |            +-------------+
    |            | (A && B[0]) |
    |            |||(B && CSV) |
    |            +-------------+
    |            |    A->B     |
    |            |    HTLC     |
    +------------+-------------+

Despite being the *2nd* commitment tx, it should have the ***same*** Bob-side revocation key `B[0]` instead of the next one in the series, `B[1]`.

My previous email was wrong in incrementing `B[1]` here.

To understand this subtlety, let us divide Bob into these characters:

* The "true" Bob, which represents the actual economic entity that is using this scheme for their improved economic efficiency (i.e. "because it is convenient for the user").
* Carol the cashier, who is in direct communication with Alice and is 100% online.
  * This represents a piece of (hopefully open-source) software which acts as the 100%-online node.
* Kelly the keyholder, who holds the important private keys of Bob, and *only* connects to Carol (via a direct connection) if and only if Bob wills it.
  * This represents a piece of hardware that keeps the keys offline.

Now, let us consider the below property:

* Bob has access to all the activity of Carol, including all communications between Carol and Alice.
  * More to the point, Bob has a copy of every `SigA` received by Carol.

The above property is accurate to the real world, I think, because Carol is not a true economic sentient entity. It is "just" a piece of software you install on a piece of hardware with 100% uptime, and presumably Bob either has personally audited the software, or has hired someone to do so on its behalf.

Of course, software is never perfect, and it is possible that a bug in the software will allow Alice to extract additional information from Carol the cashier-software. We model this as Carol then cooperating with Alice to do as much economic damage to Bob as possible.

For example, Carol is the one who keeps the various `SigA`s from Alice. Thus, in theory, if Carol is corrupted by Alice, Carol is capable of deleting all the `SigA`s coming from Alice, including that needed by every "commitment transaction owned by Bob". Thus, a "signature-deletion" attack mounted by Alice and Carol on Bob can prevent Bob from unilaterally closing the channel, leading to hostage-taking of ***all*** the Bob-side funds in the channel, not just in-flight HTLCs.

However, remember that Carol is "really" just a piece of (potentially buggy) software. Bob can mitigate signature deletion:

* Perhaps the backing datastore is really a copy-on-write structure, such that deletions are not actual overwrites of old data, and older version containing the signatures can be retained.
* Bob can take snapshots of the backing datastore periodically, which reduces the damage of deletions, as Bob has a copy of some of the older data before Carol deleted signatures.
* Perhaps the signature datastore is an append-only log, which is only periodically reaped of truly obsolete signatures by Bob.
  As signatures are only 64 bytes, this is not an onerous amount of data for low-bandwidth Bobs.
* The Carol software could be structured so that the signature datastore is a separate process, thus enjoys some amount of protection (process isolation) from exploits on the "main" Carol software that is online and connected to Alice.

Thus, in our model, we have the property that Bob can always recover all signatures sent by Alice, even if Carol is corrupted by Alice --- we model the signature-deletion attack as impossible, by assumption. (This is a strengthening of security assumptions, thus a weakening of the security of the scheme --- if Bob does not take the above mitigations, Bob ***is*** vulnerable to a signature-deletion attack and might have ***all*** funds in hostage).

Now, hostaging of the funds in a channel occurs because one participant loses the ability to unilaterally close. If Bob is unable to unilaterally close, Alice can refuse to cooperate on channel closures unless Bob dontes some money to Alice. Signature-deletion is only *one* way to lose this ability.

Another way is for a corrupted Carol to reveal all the revocation keys, including the latest revocation key, to Alice. This prevents Bob from safely unilaterally closing the channel, as the latest transaction it has is revocable by Alice (because Carol has been corrupted and has leaked the latest revocation key).

Thus:

* Carol ***MUST NOT*** be given the entire set of revocation keys `B[0]`..`B[n]`.
  Carol should only be given *previous* revocation keys by Bob, as a hardened derivation from the keys held by KElly.

Of course, since Carol has no access to the *current* revocation key, it cannot provide it once the *next* commitment is created.

This implies that, until Bob puts Kelly online and gets access to the entire sequence of revocation keys, Carol also **cannot** provide revocation keys for previous states. Thus, as long as Kelly is offline, Alice and Carol have to reuse the same revocation key.

This is still safe, since later "commitment transaction owned by Bob" have more and more funds in HTLCs going to Bob. Thus, Bob has every incentive to use only the latest "commitment transaction owned by Bob".

So:

* As long as all transfers are Alice->Bob direction, there is no need to update the revocation key (and Carol ***cannot*** provide this key anyway without Kelly).
* Once we have a Bob->Alice transfer (i.e. Bob sends out money), only then does the revocation key need to be exposed to Carol for sending to Alice.
  * As the sequence of revocation keys are derived from the master privkey held by Kelly, Kelly is needed.
  * We need Kelly to be online anyway for sends (to send the corresponding signatures as well), so this is *not* an *additional* requirement.

Regards, ZmnSCPxj

Lloyd Fournier in reply to ZmnSCPxj permalink original

Hi Z,

Thanks again for getting to the bottom of this. I think we are on the same page except for one clarification:

On Tue, 8 Jun 2021 at 12:37, ZmnSCPxj <ZmnSCPxj at protonmail.com> wrote:

Quoted text (8 lines)
> Thus, in our model, we have the property that Bob can always recover all
> signatures sent by Alice, even if Carol is corrupted by Alice --- we model
> the signature-deletion attack as impossible, by assumption.
> (This is a strengthening of security assumptions, thus a weakening of the
> security of the scheme --- if Bob does not take the above mitigations, Bob
> ***is*** vulnerable to a signature-deletion attack and might have ***all***
> funds in hostage).
>

Only where ***all*** refers to the funds in the fast forward -- funds consolidated into the channel balance are not at risk (modulo enforcing correct state on chain). I think it should be easy to get a stream of signatures so they can't be deleted. The user "Bob" is creating and sending the invoices so they can always demand and save the signatures from "Carol the Cashier" that correspond to each payment so the "deletion attack" will be thwarted.

LL

ZmnSCPxj in reply to Lloyd Fournier permalink original

Good morning LL,

Quoted text (12 lines)
> Hi Z,
>
> Thanks again for getting to the bottom of this. I think we are on the same page except for one clarification:
>
> On Tue, 8 Jun 2021 at 12:37, ZmnSCPxj <ZmnSCPxj at protonmail.com> wrote:
>
>
> > Thus, in our model, we have the property that Bob can always recover all signatures sent by Alice, even if Carol is corrupted by Alice --- we model the signature-deletion attack as impossible, by assumption.
> > (This is a strengthening of security assumptions, thus a weakening of the security of the scheme --- if Bob does not take the above mitigations, Bob ***is*** vulnerable to a signature-deletion attack and might have ***all*** funds in hostage).
>
> Only where ***all*** refers to the funds in the fast forward -- funds consolidated into the channel balance are not at risk (modulo enforcing correct state on chain).
> I think it should be easy to get a stream of signatures so they can't be deleted. The user "Bob" is creating and sending the invoices so they can always demand and save the signatures from "Carol the Cashier" that correspond to each payment so the "deletion attack" will be thwarted.

To be clear, what I meant here with "***all***" was that risk of funds hostage exists if Bob has absolutely no mitigation against this (i.e. makes no copies of signatures for itself). What you suggest is a mitigation that *does* prevent this "***all***" case (i.e. Bob makes its own copies of signatures, it does not delegate signature storage to Carol the Cashier).

Thus, the model outright assumes that Bob makes *some* mitigation to prevent signature deletion, as without *any* mitigation the model is insecure.

Otherwise I think we are mostly in agreement here.