Introduction
to the Lightning Network
Mainz
Feb 05th 2019
Introduction
to the Lightning Network
Gjøvik
Jan 09th 2019
I've been told I should start any talk with something everybody in the audience should know
A standard Bitcoin Transaction has 6 data fields
( The following is a brief summary of https://en.bitcoin.it/wiki/Transaction#Input )
(
Bitcoin Transaction with 3 inputs and 2 outputs
Data consists mainly of executable scripts!
A chain of Bitcoin Transactions with 2 UTXO
Spending a Pay-to-PubkeyHash (standard TX)
<sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
Execution of Pay-to-PubkeyHash Script
<sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
<sig>
Data is pushed on the stack
Execution of Pay-to-PubkeyHash Script
<sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
<sig>
<pubKey>
Data is pushed on the stack again
Execution of Pay-to-PubkeyHash Script
<sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
<sig>
<pubKey>
<pubKey>
The OP_CODE OP_DUP is being executed by pushing the top element to the stack again
Execution of Pay-to-PubkeyHash Script
<sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
<sig>
<pubKey>
The OP_CODE OP_HASH160 is being executed:
It takes the top element of the Stack
<pubKey>
Execution of Pay-to-PubkeyHash Script
<sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
<sig>
<pubKey>
<pubKeyHash>
The OP_CODE OP_HASH160 is being executed:
It takes the top element of the Stack
The RIPEMD-160 Hash is calculated
By design of the input and output script this will be the Hash of the Public Key (aka the Bitcoin Address)
<pubKey>
Execution of Pay-to-PubkeyHash Script
<sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
<sig>
<pubKey>
<pubKeyHash>
The OP_CODE OP_HASH160 is being executed:
It takes the top element of the Stack
The RIPEMD-160 Hash is calculated
And the result is pushed back on the stack
By design of the input and output script this will be the Hash of the Public Key (aka the Bitcoin Address)
<pubKey>
Execution of Pay-to-PubkeyHash Script
<sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
<sig>
<pubKey>
<pubKeyHash>
<pubKeyHash>
Data is pushed on the stack again
Execution of Pay-to-PubkeyHash Script
<sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
<sig>
<pubKey>
OP_EQUALVERIFY checks if the two top elements of the stack are equal.
While checking the elements will be removed
Like the instruction set in the ALU of the CPU OP_CODES know how much data they need to consume (and will do so or fail otherwise)
<pubKeyHash>
<pubKeyHash>
Execution of Pay-to-PubkeyHash Script
<sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
<True>
OP_CHECKSIG evaluates that the PubKey which was the top element fits to the signature which was the 2. Element on the stack
If this fits together ownership is proven and the Transaction will be added to the block with a new Output script.
After being mined the transaction is now considered to be spent. Double spending cannot take place since the assumption was that the output was not spent yet.
<sig>
<pubKey>
Broadcast / Publish that Transaction for the network to verify it
The Bitcoin miners will build the next block
Bitcoin Transaction with 3 inputs and 2 outputs
Be Brave!
Now is the moment to ask questions
Let's talk lightning!
I love taking photographs of lightning bolts...
Two main components lead to the Lightning Network
Purpose of a trustless bidirectional payment channel
→ How can this technically be possible?
A comparison with HTTP
How does a HTTP server push work?
More details at: https://en.wikipedia.org/wiki/Push_technology
Payment channels are constructed by deferring the publication or broadcast of some TXs to the future
A payment channel is a 2-2 multisig Address together with some (smart?) contract
Funding Transaction
Funding Transaction
Input (100 mBTC)
Output 0
(100 mBTC)
Alice's & Bob's Key
Output x
(100 mBTC)
Alice's Key
Reference
ScriptPubKey:
OP_HASH160 <scriptHash> OP_EQUALVERIVY
Inside
U
N
P
U
B
L
I
S
H
E
D
Legend for colors:
Broadcasted and mined
Not boradcasted
Cannot by minded / should not be broadcasted
Should be broadcasted
Funding Transaction
Funding Transaction
Input (100 mBTC)
Output 0
(100 mBTC)
Alice's & Bob's Key
Commitment Transaction 1
Input (100 mBTC)
Reference
Output 0
(70 mBTC)
Alice's Key
Output 1
(30 mBTC)
Bob's Key
Output x
(100 mBTC)
Alice's Key
Reference
ScriptPubKey:
OP_HASH160 <scriptHash> OP_EQUALVERIVY
sigScript:
<sig1>... <serializedScript>
Script:
OP_2 <Alice><Bob> OP_2 OP_CHECKMULTISIG
Inside
Inside
U
N
P
U
B
L
I
S
H
E
D
U
N
P
U
B
L
I
S
H
E
D
Funding Transaction
Funding Transaction
Input (100 mBTC)
Output 0
(100 mBTC)
Alice's & Bob's Key
Commitment Transaction 1
Input (100 mBTC)
Output 0
(70 mBTC)
Alice's Key
Output 1
(30 mBTC)
Bob's Key
Output x
(100 mBTC)
Alice's Key
Reference
ScriptPubKey:
OP_HASH160 <scriptHash> OP_EQUALVERIVY
sigScript:
<sig1>... <serializedScript>
Script:
OP_2 <Alice><Bob> OP_2 OP_CHECKMULTISIG
Inside
Inside
This Commitment Transaction (CTX1) encodes the balance sheet of the channel.
It is called commitment because both sides have already been committed to it.
They can be broadcasted to the blockchain at any time
Reference
P
U
B
L
I
S
H
E
D
With CTX2 Bob upates the channel Balance
Funding Transaction
Input (100 mBTC)
Output 0
(100 mBTC)
Alice's & Bob's Key
Commitment Transaction 1
Input (100 mBTC)
Reference
Output 0
(70 mBTC)
Alice's Key
Output 1
(30 mBTC)
Bob's Key
Commitment Transaction 2
Input (100 mBTC)
Reference
Output 0
(80 mBTC)
Alice's Key
Output 1
(20 mBTC)
Bob's Key
potential
double �spending?
Bob effectively sends 10 mBTC
to Alice
Anybody seeing a problem with this?
Funding Transaction
Input (100 mBTC)
Output 0
(100 mBTC)
Alice's & Bob's Key
Commitment Transaction 1
Input (100 mBTC)
Reference
Output 0
(70 mBTC)
Alice's Key
Output 1
(30 mBTC)
Bob's Key
Commitment Transaction 2
Input (100 mBTC)
Reference
Output 0
(80 mBTC)
Alice's Key
Output 1
(20 mBTC)
Bob's Key
potential
double �spending?
Bob broadcasts CTX1 which is successfully mined
Bob just effectively stole 10 mBTC from Alice
Funding Transaction
Input (100 mBTC)
Output 0
(100 mBTC)
Alice's & Bob's Key
Commitment Transaction 1
Input (100 mBTC)
Reference
Output 0
(70 mBTC)
Alice's Key
Output 1
(30 mBTC)
Bob's Key
Commitment Transaction 2
Input (100 mBTC)
Reference
Output 0
(80 mBTC)
Alice's Key
Output 1
(20 mBTC)
Bob's Key
Goal: Make old CTXs somehow unpublishable
Funding Transaction
Input (100 mBTC)
Output 0
(100 mBTC)
Alice's & Bob's Key
Commitment Transaction 1
Input (100 mBTC)
Reference
Output 0
(70 mBTC)
Alice's Key
Output 1
(30 mBTC)
Bob's Key
Commitment Transaction 2
Input (100 mBTC)
Reference
Output 0
(80 mBTC)
Alice's Key
Output 1
(20 mBTC)
Bob's Key
We modify the output scripts of CTXs that it can be spent by either one of the two Transactions
Commitment Transaction 1b (Bob)
Input (100 mBTC)
Output 0
(70 mBTC)
Alice's Key
Output 1
(30 mBTC)
RSMC
Reference
ScriptPubKey: (Output0)
OP_HASH160 <Alice's key> OP_EQUALVERIFY OP_CHECKSIG
Script: (Input Script to be able to spend Output1)
OP_IF
144 OP_CECKSEQUENCEVERIFY
OP_ DUP OP_HASH160 <Bob's key> OP_EQUALVERIFY OP_CHECKSIG
OP_ELSE
2 <Alice R_1><Bob R_1> 2 OP_CHECKMULTISIGVERIFY
OP_ENDIF
Revocable Delivery 1b (Bob)
Input (30 mBTC)
Output 0 (30 mBTC)
Bob's Key
Relative Time Lock (144)
Breach Remedy Tx 1b (Bob)
Input (30 mBTC)
Output 0 (30 mBTC)
Bob's & Alice's
Revocation Key #1
potential
double �spending?
Within 144 Blocks after CTX1b is mined only Alice can spend Output1 (if she has Bob's Revocation Key)
Commitment Transaction 1b (Bob)
Input (100 mBTC)
Output 0
(70 mBTC)
Alice's Key
Output 1
(30 mBTC)
RSMC
Reference
ScriptPubKey: (Output0)
OP_HASH160 <Alice's key> OP_EQUALVERIFY OP_CHECKSIG
Script: (Input Script to be able to spend Output1)
OP_IF
144 OP_CECKSEQUENCEVERIFY
OP_HASH160 <Bob's key> OP_EQUALVERIFY OP_CHECKSIG
OP_ELSE
2 <Alice R_1><Bob R_1> 2 OP_CHECKMULTISIGVERIFY
OP_ENDIF
Revocable Delivery 1b (Bob)
Input (30 mBTC)
Output 0 (30 mBTC)
Bob's Key
Relative Time Lock (144)
Breach Remedy Tx 1b (Bob)
Input (30 mBTC)
Output 0 (30 mBTC)
Bob's & Alice's
Revocation Key #1
After 144 Blocks Bob can redeem his 10 mBTC & Alice can't spent BRTX1b without Bob's Key
Commitment Transaction 1b (Bob)
Input (100 mBTC)
Output 0
(70 mBTC)
Alice's Key
Output 1
(30 mBTC)
RSMC
Reference
ScriptPubKey: (Output0)
OP_HASH160 <Alice's key> OP_EQUALVERIFY OP_CHECKSIG
Script: (Input Script to be able to spend Output1)
OP_IF
144 OP_CECKSEQUENCEVERIFY
OP_HASH160 <Bob's key> OP_EQUALVERIFY OP_CHECKSIG
OP_ELSE
2 <Alice R_1><Bob R_1> 2 OP_CHECKMULTISIGVERIFY
OP_ENDIF
Revocable Delivery 1b (Bob)
Input (30 mBTC)
Output 0 (30 mBTC)
Bob's Key
Relative Time Lock (144)
Breach Remedy Tx 1b (Bob)
Input (30 mBTC)
Output 0 (30 mBTC)
Bob's & Alice's
Revocation Key #1
A new Commitment Transaction is only signed if the other party reveals their previous revocation Key
Commitment Transaction 1b (Bob)
Input (100 mBTC)
Output 0
(70 mBTC)
Alice's Key
Output 1
(30 mBTC)
RSMC
Reference
Revocable Delivery 1b (Bob)
Input (30 mBTC)
Output 0 (30 mBTC)
Bob's Key
Relative Time Lock (144)
Breach Remedy Tx 1b (Bob)
Input (30 mBTC)
Output 0 (30 mBTC)
Bob's & Alice's
Revocation Key #1
Commitment Transaction 2b (Bob)
Input (100 mBTC)
Output 0
(80 mBTC)
Alice's Key
Output 1
(20 mBTC)
RSMC
Revocable Delivery 2b (Bob)
Input (20 mBTC)
Output 0 (20 mBTC)
Bob's Key
Relative Time Lock (144)
Breach Remedy Tx 2b (Bob)
Input (20 mBTC)
Output 0 (20 mBTC)
Bob's & Alice's
Revocation Key #2
Assume CTX1b is published an mined. Alice should immediately publish BRTX1b to punish Bob's breach
Commitment Transaction 1b (Bob)
Input (100 mBTC)
Output 0
(70 mBTC)
Alice's Key
Output 1
(30 mBTC)
RSMC
Reference
Revocable Delivery 1b (Bob)
Input (30 mBTC)
Output 0 (30 mBTC)
Bob's Key
Relative Time Lock (144)
Breach Remedy Tx 1b (Bob)
Input (30 mBTC)
Output 0 (30 mBTC)
Bob's & Alice's
Revocation Key #1
Commitment Transaction 2b (Bob)
Input (100 mBTC)
Output 0
(80 mBTC)
Alice's Key
Output 1
(20 mBTC)
RSMC
Revocable Delivery 2b (Bob)
Input (20 mBTC)
Output 0 (20 mBTC)
Bob's Key
Relative Time Lock (144)
Breach Remedy Tx 2b (Bob)
Input (20 mBTC)
Output 0 (20 mBTC)
Bob's & Alice's
Revocation Key #2
I
M
P
O
S
S
I
B
L
E
D
O
U
B
L
E
S
P
E
N
D
I
N
G
Some remarks on presented simplifications
Summary of what we have achieved now
Where is the (Lightning) Network of payment channels?
A trusting (Lightning) Network of payment channels
Alice
0.35 BTC
2-2 Multisignature Wallet
0.5 BTC
Bob
0.65 BTC
channel A-B
2-2 Multisignature Wallet
0.8 BTC
Carlie
0.3 BTC
channel B-C
0.35 BTC
0.5 BTC
0.15 BTC
0.3 BTC
A trusting (Lightning) Network of payment channels
Alice
0.35 BTC
2-2 Multisignature Wallet
0.5 BTC
Bob
0.65 BTC
channel A-B
2-2 Multisignature Wallet
0.8 BTC
Carlie
0.3 BTC
channel B-C
0.35 BTC
0.5 BTC
0.15 BTC
0.3 BTC
send
0.1 BTC to Charlie
A trusting (Lightning) Network of payment channels
Alice
0.25 BTC
2-2 Multisignature Wallet
0.5 BTC
Bob
0.75 BTC
channel A-B
2-2 Multisignature Wallet
0.8 BTC
Carlie
0.3 BTC
channel B-C
0.25 BTC
0.5 BTC
0.25 BTC
0.3 BTC
send
0.1 BTC to Charlie
A trusting (Lightning) Network of payment channels
Alice
0.25 BTC
2-2 Multisignature Wallet
0.5 BTC
Bob
0.75 BTC
channel A-B
2-2 Multisignature Wallet
0.8 BTC
Carlie
0.3 BTC
channel B-C
0.25 BTC
0.5 BTC
0.25 BTC
0.3 BTC
send
0.1 BTC to Charlie
I am honest and forward the payment
A trusting (Lightning) Network of payment channels
Alice
0.25 BTC
2-2 Multisignature Wallet
0.5 BTC
Bob
0.65 BTC
channel A-B
2-2 Multisignature Wallet
0.8 BTC
Carlie
0.4 BTC
channel B-C
0.25 BTC
0.4 BTC
0.25 BTC
0.4 BTC
send
0.1 BTC to Charlie
I am honest and forward the payment
Alice needed to trust Bob to forward the payment
A trustless (Lightning) Network of payment channels
Alice
0.35 BTC
2-2 Multisignature Wallet
0.5 BTC
Bob
0.65 BTC
channel A-B
2-2 Multisignature Wallet
0.8 BTC
Carlie
0.3 BTC
channel B-C
0.35 BTC
0.5 BTC
0.15 BTC
0.3 BTC
send
0.1 BTC to Charlie
Some Hash H of R
A trustless (Lightning) Network of payment channels
Alice
0.25 BTC
2-2 Multisignature Wallet
0.5 BTC
Bob
0.65 BTC
channel A-B
2-2 Multisignature Wallet
0.8 BTC
Carlie
0.3 BTC
channel B-C
0.25 BTC
0.5 BTC
0.15 BTC
0.3 BTC
Some Hash H of R
H
0.1 BTC
I can't claim 0.1 BTC without knowing R (within some time)
If Bob doesn't provide R
I can soon claim back 0.1 BTC
A trustless (Lightning) Network of payment channels
Alice
0.25 BTC
2-2 Multisignature Wallet
0.5 BTC
Bob
0.55 BTC
channel A-B
2-2 Multisignature Wallet
0.8 BTC
Carlie
0.3 BTC
channel B-C
0.25 BTC
0.4 BTC
0.15 BTC
0.3 BTC
Some Hash H of R
H
0.1 BTC
I can't claim 0.1 BTC without providing R (within some time)
I pay charly if she can provide R (within some shorter time)
H
0.1 BTC
A trustless (Lightning) Network of payment channels
Alice
0.25 BTC
2-2 Multisignature Wallet
0.5 BTC
Bob
0.65 BTC
channel A-B
2-2 Multisignature Wallet
0.8 BTC
Carlie
0.3 BTC
channel B-C
0.25 BTC
0.5 BTC
0.15 BTC
0.3 BTC
Some Hash H of R
H
0.1 BTC
H
0.1 BTC
Tell Charlie R
R
A trustless (Lightning) Network of payment channels
Alice
0.25 BTC
2-2 Multisignature Wallet
0.5 BTC
Bob
0.55 BTC
channel A-B
2-2 Multisignature Wallet
0.8 BTC
Carlie
0.4 BTC
channel B-C
0.25 BTC
0.4 BTC
0.15 BTC
0.4 BTC
Some Hash H of R
H
0.1 BTC
R
I can only claim 0.1 BTC by providing R to Bob
R
A trustless (Lightning) Network of payment channels
Alice
0.25 BTC
2-2 Multisignature Wallet
0.5 BTC
Bob
0.55 BTC
channel A-B
2-2 Multisignature Wallet
0.8 BTC
Carlie
0.4 BTC
channel B-C
0.25 BTC
0.4 BTC
0.15 BTC
0.4 BTC
Some Hash H of R
H
0.1 BTC
R
Great! Now I can also claim 0.1 BTC because I know R
R
A trustless (Lightning) Network of payment channels
Alice
0.25 BTC
2-2 Multisignature Wallet
0.5 BTC
Bob
0.65 BTC
channel A-B
2-2 Multisignature Wallet
0.8 BTC
Carlie
0.4 BTC
channel B-C
0.25 BTC
0.4 BTC
0.25 BTC
0.4 BTC
Some Hash H of R
R
Bob must have payed Charlie otherwise he would not have known R.
I didn't need to trust him.
R
R
There are more technical details (Read the BOLTs)
Problems with the Lightning Network (BOLT 1.0)
Disclaimer: Don't take this too seriously (yet)
A quick recap of chaincode labs
lightning residency
(Current) Autopilot in a nutshell
How does the LND Autopilot work?
Pitfalls with the lnd autopilot
Roasbeefs response (:
Why is it important to think about the autopilot early
Solution: Grow the network in a smart way to avoid future problems
Analogy to the Internet protocol stack
| Name | Example | Name | Example |
3. Layer | Application | WWW, Email, Bitcoin | Application | y'alls, satoshis place, bitrefill |
2. Layer | Internet Transport | TCP / IP | Transport | Lightning Network |
1. Layer | Link Layer | Ethernet / LAN | Blockchain | Bitcoin |
Analogy to the Internet protocol stack
| Name | Example | Name | Example |
3. Layer | Application | WWW, Email, Bitcoin | Application | y'alls, satoshis place, bitrefill schnellbezahlen.de |
2. Layer | Internet Transport | TCP / IP | Transport | Lightning Network |
1. Layer | Link Layer | Ethernet / LAN | Blockchain | Bitcoin, DOGE, Litecoin |
Analogy to the Internet protocol stack is not perfect
(Not perfect) analogy to routing and routed protocols
My approach / first prototype
Betweenness centrality
Betweenness centrality distribution by Kupreet Singh
Decreasing the diameter of the network
Some technical details
API overview
Balance selection for candidates
Future ideas
Roadmap
Conclusions / Thoughts about the autopilot
Other stuff I currently do
Thanks for your attention & Questions?
Copyright
Videos: