Skip to content

Commit 4a15784

Browse files
committed
Add Multi Hop from Scriptless Scripts writeup
1 parent 2be29b2 commit 4a15784

File tree

4 files changed

+147
-0
lines changed

4 files changed

+147
-0
lines changed

md/images/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
all: multi-hop-locks.png
2+
3+
multi-hop-locks.png: multi-hop-locks.txt
4+
cat multi-hop-locks.txt | plantuml -pipe > multi-hop-locks.png

md/images/multi-hop-locks.png

86.6 KB
Loading

md/images/multi-hop-locks.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
@startuml
2+
title Multi-Hop Locks with Schnorr
3+
participant Alice
4+
participant Bob
5+
participant Carol
6+
participant Dave
7+
8+
== Setup ==
9+
10+
Dave->Alice : z*G
11+
note left
12+
z can be a proof of payment
13+
end note
14+
Alice->Alice : draw y0, y1, y2 at random
15+
note left
16+
Alice sets up tuple (L,y,R) for every hop
17+
end note
18+
Alice->Alice: z*G, y0, (z+y0)*G
19+
Alice->Bob : (z+y0)*G, y1, (z+y0+y1)*G
20+
Alice->Carol: (z+y0+y1)*G, y2, (z+y0+y1+y2)*G
21+
Alice->Dave : (z+y0+y1+y2)*G, y0+y1+y2, ...
22+
23+
== Update ==
24+
25+
Alice->Bob : add 2-of-2 MuSig(A,B) output with timelocked refund to A
26+
Bob->Alice : txB, psig(B,txB,(z+y0)*G)
27+
Alice->Bob : psig(A,txB,(z+y0)*G)
28+
Bob->Carol : add 2-of-2 MuSig(B,C) output with timelocked refund to B
29+
Carol->Bob : txC, psig(C,txC,(z+y0+y1)*G)
30+
Bob->Carol : psig(B,txC,(z+y0+y1)*G)
31+
Carol->Dave : add 2-of-2 MuSig(C,D) output with timelocked refund to C
32+
Dave->Carol : txD, psig(D,txD,(z+y0+y1+y2)*G)
33+
Carol->Dave : psig(C,txD,(z+y0+y1+y2)*G)
34+
35+
== Settlement ==
36+
37+
Dave->Dave : create adaptor_sig(D,txD,z+y0+y1+y2),\nMuSig combine with psig(C,txD,(z+y0+y1+y2)*G),\nbroadcast txD with combined sig
38+
Carol->Carol : compute z+y0+y1 = adaptor_sig(D,txD,z+y0+y1+y2) - psig(D,txD,(z+y0+y1+y2)*G) - y2\nto create adaptor_sig(C,txC,z+y0+y1),\nMuSig combine with psig(B,txC,(z+y0+y1)*G),\nbroadcast txC with combined sig
39+
Bob->Bob : compute y0 = adaptor_sig(C,txC,z+y0+y1) - psig(C,txC,(z+y0+y1)*G) - y1\nto create adaptor_sig(B,txB,z+y0),\nMuSig combine with psig(A,txB,z+y0*G),\nbroadcast txB with combined sig
40+
41+
@enduml

md/multi-hop-locks.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
Multi-Hop Locks from Scriptless Scripts
2+
===========================
3+
4+
Multi-hop locks are protocols that allow two parties to exchange coins and proof of payment without requiring a mutual funding multisig output.
5+
Instead, they are connected through intermediate hops such that every hop has a shared funding multisig output with the next hop.
6+
Multi-hop locks based on cryptographic hashes instead of scriptless scripts are used in the [Lightning Network protocol version 1.0](https://github.com/lightningnetwork/lightning-rfc) to route payments.
7+
8+
Scriptless script multi-hop locks were introduced in a [post to the mimblewimble mailing list](https://lists.launchpad.net/mimblewimble/msg00086.html) and formally defined in the paper [Privacy-preserving Multi-hop Locks for Blockchain Scalability and Interoperability](https://eprint.iacr.org/2018/472.pdf).
9+
By using scriptless scripts they result in smaller transactions which look like regular transactions and therefore improve privacy.
10+
More importantly, they allow [payment decorrelation](https://medium.com/@rusty_lightning/decorrelation-of-lightning-payments-7b6579db96b0) which means that hops in a multi-hop lock can not determine (absent timing and coin amount analysis) if they are on the same path, i.e. they don't know if they are forwarding the same payment.
11+
Correlation attacks are especially problematic if the first and last intermediate hops are colluding because they would learn source and destination of a payment.
12+
In addition, scriptless script multi-hop locks enable improved proof of payment and atomic multi path payments (see below).
13+
14+
15+
Notation
16+
---
17+
- `psig(i,m,T) := ki + H(R+T,m)*xi` is a partial 2-of-2 MuSig from user `i` for `m` with combined nonce `R` (note that `R` has nothing to do with the right lock `R` defined below and we won't use `R` to mean the nonce again).
18+
- `adaptor_sig(i,m,T) := psig(i,m,t*G) + t`
19+
- `sig(m,T) = psig(i,m,T) + adaptor_sig(j,m,T)` is the completed 2-of-2 MuSig from user i and j. It can be computed from a partial signature and an adaptor signature.
20+
21+
22+
Protocol
23+
---
24+
25+
![multi-hop-locks](images/multi-hop-locks.png)
26+
27+
In the setup phase the payee chooses `z` at random and sends the payer `z*G`.
28+
The payer will set up the multi-hop locks such that a successful payment reveals `z` to her and only her.
29+
Knowledge of `z` can be a proof of payment which is similar in concept to payment preimages in the Lightning v1.0 (see section below for details).
30+
31+
We picture the payment starting from the payer on the left side through intermediate hops to the payee on the right side.
32+
The setup phase continues with the payer setting up a tuple `(Li,yi,Ri)` consisting of the *left lock* `Li` and *right lock* `Ri` for every hop `i` in the following way:
33+
Every `yi` is a scalar uniformly chosen at random.
34+
The payers own left lock `L0` is set to `z*G` which was previously received from the payer.
35+
Now for every lock `Ri` for hop `0<=i<n` and `Lj` for hop `j=i+1` the payer sets `Ri <- Li + yi*G` and `Lj <- Ri` (see the diagram).
36+
37+
In the update phase adjacent hops add a multisig output to their off-chain transactions similar to how they would add an HTLC output in the Lightning v1.0.
38+
Despite significant differences between v1.0 HTLCs and the outputs used to forward payments in scripless scripts multi-hop locks we continue to call the outputs HTLCs because they have the same purpose and work similarly on the surface.
39+
Just like v1.0 HTLCs, scriptless script HTLCs have a time out condition such that the left hop can reclaim her coins if the payment fails.
40+
But otherwise scriptless script HTLCs are plain 2-of-2 MuSig outputs and the hashlock is only implicitly added to the output only when a partial signature is received (see below).
41+
For demonstration purposes we assume [eltoo](https://blockstream.com/eltoo.pdf)-style channels which means that both parties have symmetric state and there's no need for revocation.
42+
43+
If the payment does not time out, the coins in the scriptless script HTLC output shared by two adjacent hops will be spent by the right hop.
44+
Therefore, the right hop `j` prepares a transaction `txj` spending the HTLC and partially signs it as `psig(j,txj,Lj)` which is similar to a regular partial signature except that its left lock `Lj` is added to the combined signature nonce.
45+
The left hop verifies the partial signature and sends its own partial signature for `txj` to the right hop in the following two cases:
46+
47+
- the left hop is the payer
48+
- the left hop `i` received a signature `psig(i-1, txi, T-yi*G)` from the preceding hop `i-1` for the left hops transaction `txi`. In combination with the partial signature just received from the right hop, it is guaranteed that as soon as the right hop spends the coins, the left hop can open its left lock and spend the coins with `txi` as we will see below.
49+
50+
Therefore the update phase starts with the leftmost pair and continues to the right.
51+
After receiving the partial signature from the left, the right hop can complete it as soon as it learns the secret of its left lock.
52+
In order to reduce the overall number of communication rounds the setup phase and update phase can be merged together.
53+
54+
The settlement phase begins when the payee receives the partial signature from its left hop.
55+
Because the multi-hop locks were set up by the payer such that the payee knows the secret of her left lock, she can use it as the adaptor secret and create an adaptor signature.
56+
The adaptor signature is combined with the left hop's partial signature resulting in a final signature for the right hop's (the payee's) transaction.
57+
At this point the right hop can broadcast the transaction to settle on-chain.
58+
59+
In this case the left hop notices the combined signature and learns its right lock secret by subtracting the right hop's previously received partial signature and its own partial signature.
60+
```
61+
sig(tx,T) - psig(i,tx,Ri) - psig(j,tx,Lj) = adaptor_sig(j,tx,Lj) - psig(j,tx,Lj) = yj
62+
```
63+
Alternatively, the right hop can send its secret `yj` directly to the left hop and request to update commitment (Lightning v1.0) or settlement (eltoo) transaction such that the HTLC is removed, the left hop's output amount is decreased by the payment amount and the right hop's output amount is increased by that amount.
64+
If the left hop would not follow up with an update, the right hop can still broadcast the transaction until the HTLC times out.
65+
66+
Either way, once the payee claims the payment, the left hop learns the right lock secret, computes its left lock secret by subtracting `yi`, computes an adaptor signature, and so on until the payer learns the proof of payment `z` which completes the payment.
67+
68+
69+
Proof of Payment (PoP)
70+
---
71+
The main difference to Lightning v1.0 is that the proof of payment (`z`) is only obtained by the payer and not by every hop along the route.
72+
Therefore, the proof of payment can be used to authenticate the payer to the payee.
73+
It is not necessary to reveal the PoP itself but instead a signature of `z*G` can be provided.
74+
Due to payment decorrelation intermediate hops can not associate a payment with the PoP.
75+
76+
Obviously, not only the payer is able prove knowledge of `z`.
77+
Everyone the payee or payer choose to share `z` with can do so too which makes it unclear who actually paid.
78+
Therefore a signed statement (invoice) from payee should be sent to payer that includes `z*G` and the payers public key.
79+
Then the PoP is both a signature with the PoP and the payers secret key which can only be provided by the payer (or everyone the payer chooses to collaborate with).
80+
81+
Ideally a single static invoice would be payable by multiple parties allowing spontaneous payments without requiring extra communication with the payee.
82+
But this is not compatible with PoPs because the PoP must be created from fresh randomness for every payment.
83+
However, recurring payments from a single payer [can be done using hash chains](https://lists.linuxfoundation.org/pipermail/lightning-dev/2018-November/001496.html).
84+
85+
86+
Atomic Multipath Payments (AMP)
87+
---
88+
With scriptless script multi-hop locks it is possible to do AMP in a similarly to [*base AMP*](https://lists.linuxfoundation.org/pipermail/lightning-dev/2018-November/001577.html) while allowing payment decorrelation between the paths.
89+
The payer sets up multiple routes to the payee using uncorrelated locks such that any partial payment claimed by the payee reveals the proof of payment (`z`) to the payer.
90+
Because the payee doesn't want to give up the PoP for just a partial payment, she waits until all routes to her are fully established and claims the all partial payments at once.
91+
92+
93+
Resources
94+
---
95+
* [Lightning Network protocol version 1.0](https://github.com/lightningnetwork/lightning-rfc)
96+
* [Scripless Scripts in Lightning](https://lists.launchpad.net/mimblewimble/msg00086.html)
97+
* [Privacy-preserving Multi-hop Locks for Blockchain Scalability and Interoperability](https://eprint.iacr.org/2018/472.pdf)
98+
* [Payment Decorrelation](https://medium.com/@rusty_lightning/decorrelation-of-lightning-payments-7b6579db96b0)
99+
* [eltoo](https://blockstream.com/eltoo.pdf)
100+
* [Post-Schnorr Lightning Txs](https://lists.linuxfoundation.org/pipermail/lightning-dev/2018-February/001038.html)
101+
* [Bolt11 in the world of Scriptless Scripts](https://lists.linuxfoundation.org/pipermail/lightning-dev/2018-November/001496.html)
102+
* [Base AMP](https://lists.linuxfoundation.org/pipermail/lightning-dev/2018-November/001577.html)

0 commit comments

Comments
 (0)