Introduction to Lightning Network for Bitcoin and Litecoin presented at the first Blockchain Developers Malaysia meetup by TM Lee, co-founder of https://www.coingecko.com
Presented images cited from BitcoinMagazine and Lightning Network Slide Decks
4. What is the Lightning Network (LN) ?
- Proposed by Joseph Poon & Thaddeus Dryja
(https://lightning.network/lightning-network-paper.pdf)
- Specifications for a Payment Channel on top of the bitcoin/litecoin blockchain
- Layer 2
- “Decentralized”, Trustless, High Volume, Instant Micropayment
5. Implementations of the LN Specs
=> Follow the BOLTs spec https://github.com/lightningnetwork/lightning-rfc
1. LND (GoLang) by Lightning
2. Eclair (Scala) by ACINQ
3. Lightning-C (C) by Blockstream
4. Thunder (Java) by Blockchain.com
6. Applications
1. Micropayments
○ Send satoshis with small transaction fees
2. Payment Streaming
○ Sending small amount of money frequently (ie. secondly, minutely, hourly)
○ Eg. pay per second when watching video on Youtube
3. Machine-to-Machine Payments
○ Bandwidth, data, storage, cpu times, data, can be traded
○ API endpoints usages
4. There could be more...
9. CheckLockTimeVerify (CLTV)
- Specific time
- Eg. at Block N, specific date/time
Time-Lock
Source: https://bitcoinmagazine.com/articles/understanding-the-lightning-network-part-building-a-bidirectional-payment-channel-1464710791/
CheckSequenceVerify (CSV)
- Relative time
- N blocks from now, time from now
11. Transaction in a lightning network
ALICE BOB
Open
Channel TX
Payment Channel Remains Open….
microTX
10m฿
microTX
10m฿
microTX
10m฿
Close
Channel TX
12. 1. Alice opens payment channel with
Bob
2. Bob opens payment channel with
Alice
3. Alice & Bob both stake 5 BTC each
to a multisig address
4. TX broadcast and mined into
Blockchain
5. Once the TX is confirmed, the
payment channel is now OPEN!
Open Payment Channel
Source: https://bitcoinmagazine.com/articles/understanding-the-lightning-network-part-building-a-bidirectional-payment-channel-1464710791/
13. 1. Alice sends 1 BTC to Bob via payment
channel
2. Alice creates a TX
a. Input from Open TX Multisig
b. Outputs
i. 4 BTC to herself
ii. 6 BTC to a New Special
Multisig
c. Creates a key1
d. Alice signs the TX
3. Instead of broadcast, Alice hands TX
directly to Bob
4. Bob does the same, creates a TX
a. Input from Open TX Multisig
b. Outputs
i. 6 BTC to himself
ii. 4 BTC to a New Special
Multisig
c. Creates a key1
d. Bob signs the TX
5. Instead of broadcast, Bob hands TX
directly to Alice
Source: https://bitcoinmagazine.com/articles/understanding-the-lightning-network-part-building-a-bidirectional-payment-channel-1464710791/
14. 1. Bob sends 1 BTC to Alice via payment
channel
2. Bob creates a new TX
a. Input from Open TX Multisig
b. Outputs
i. 5 BTC to himself
ii. 5 BTC to a New Special
Multisig
c. Creates a new key2
d. Bob signs the TX
3. Instead of broadcast, Bob hands TX
directly to Alice & key1
4. Alice does the same, creates a TX
a. Input from Open TX Multisig
b. Outputs
i. 5 BTC to herself
ii. 5 BTC to a New Special
Multisig
c. Creates a new key2
d. Alice signs the TX
5. Instead of broadcast, Alice hands TX
directly to Bob & key1
Source: https://bitcoinmagazine.com/articles/understanding-the-lightning-network-part-building-a-bidirectional-payment-channel-1464710791/
16. Close Payment Channel (Usual Case)
Source: https://bitcoinmagazine.com/articles/understanding-the-lightning-network-part-building-a-bidirectional-payment-channel-1464710791/
17. #1 “Double Spend” Problem
tn
tn+1
Alice sends 1 BTC to Bob Bob sends 1 BTC to Alice
Bob buys
a Car from
Alice
Previous
Event
Source: https://bitcoinmagazine.com/articles/understanding-the-lightning-network-part-building-a-bidirectional-payment-channel-1464710791/
18. #1 “Double Spend” Problem
tn
tn+1
Alice sends 1 BTC to Bob Bob sends 1 BTC to Alice
Bob buys
a Car from
Alice
Previous
Event
Bob Signs
Source: https://bitcoinmagazine.com/articles/understanding-the-lightning-network-part-building-a-bidirectional-payment-channel-1464710791/
19. Time-locks
- Locks spending this UTXO to a later time
Bob Signs
Bob Signs
Source: https://bitcoinmagazine.com/articles/understanding-the-lightning-network-part-building-a-bidirectional-payment-channel-1464710791/
20. Bob Signs
Bob Signs
If Bob cheats...
Alice gets to sweep all the funds!
Source: https://bitcoinmagazine.com/articles/understanding-the-lightning-network-part-building-a-bidirectional-payment-channel-1464710791/
22. #2 Payment Network
ALICE BOB CAROL
Open Channel... Open Channel...
1. Alice wants to send 1 BTC to Carol via Bob
2. Alice pays 1 BTC to Bob, Bob pays 1 BTC
to Carol
Things that may go wrong here...
- Alice does not trust Bob or Carol
- Alice can pay Bob, Bob can choose not to
pay Carol
- Bob can pay Carol, but Carol can claim that
she did not receive the funds
23. #2 Payment Network Alice wants to send 1 BTC to Carol
1. Carol needs to create an Invoice consists of
a. Vrandom
& hash(Vrandom
)
b. Carol sends the hash(Vrandom
) to Alice
Alice tells Carol to receive 1 BTC from
Bob
2. Alice tells Bob that she will pay him 1 BTC if
he can produce hash(Vrandom
), Bob needs
Vrandom
3. Bob gives 1 BTC to Carol
Carol gives the Vrandom
to Bob
4. Bob gives the Vrandom
to Alice as a proof
Alice gives 1 BTC to Bob
Source: https://bitcoinmagazine.com/articles/understanding-the-lightning-network-part-creating-the-network-1465326903/
24. - Decentralized, Instant, Off-chain transfer of Bitcoin without Trust
- 1 On-Chain TX to Open Channel, 1 On-Chain TX to Close Channel
- Bitcoin can be transferred between parties, without broadcasting to network
- New TX replaces Old TX locally within the parties, as long as Channel is
Open
To Summarize...
ALICE BOB CAROL
Open Channel (on-chain)
Close Channel (on-chain)
Open Channel (on-chain)
Close Channel (on-chain)
Transfer Funds (off-chain) Transfer Funds (off-chain)
25. Things you can do as a developer
1. Spin up a Lightning Network node
2. Full node to watch blockchain for Lightning users
3. Build hardware/apps that transacts off-chain
4. Implement authentication & paywall using Lightning
5. Contribute to the Lightning implementations
○ Ie. LND, Eclair, Lightning-C, Thunder
6. List of resources https://github.com/tmlee/awesome-lightning-network
26. To Summarize...
➔ Is Lightning a new coin?
◆ No, LN is a play on the way transaction works; uses the bitcoin or litecoin blockchain
➔ Custodian Risk? Trust 3rd Party?
◆ No, LN is designed to not require that; using MultiSig & Hash Time Lock Contracts
➔ Will Lightning lock up my fund?
◆ Yes, you will not be able spend the fund on-chain while the channel is open
◆ No, you will be able to participate in the LN network and send zero confirmation tx
➔ Will there be a block explorer for Lightning?
◆ No, all tx records are stored locally between the 2 parties
◆ Blockchain only records the transaction to Open and Close a channel
➔ Is there mining required?
◆ No, LN transactions are instant
◆ When open/closing the channel, needs to be mined. In this case by bitcoin/litecoin miners
➔ Who collects the fees in the LN?
◆ Middlemen facilitating LN tx between parties
28. Hash Time-Lock Contract
1. Bob generates Vrandom
and produces
2. Bob creates and signs a TX
a. Input
i. MultiSig
b. Outputs
i. 5 BTC to Bob (himself)
ii. 4 BTC to New Multisig
iii. 1 BTC to HTLC Multisig
3. Bob hands the TX to Alice
4. Alice creates and signs a TX
a. Input
i. MultiSig
b. Outputs
i. 4 BTC to Alice (herself)
ii. 5 BTC to New Multisig
iii. 1 BTC to HTLC Multisig
Source: https://bitcoinmagazine.com/articles/understanding-the-lightning-network-part-completing-the-puzzle-and-closing-the-channel-1466178980/
29. Time-locks
- Allows locking of spending UTXO to a later
point in time
- CheckLockTimeVerify (CLTV)
- Specific time
- At Block N, On Date
Hash Time-Lock Contract
Source: https://bitcoinmagazine.com/articles/understanding-the-lightning-network-part-completing-the-puzzle-and-closing-the-channel-1466178980/