Off-Chain Protocols: (Virtual) State Channels
Total Page:16
File Type:pdf, Size:1020Kb
BDLT 2019, Vienna, Austria Off-chain Protocols: (Virtual) State Channels Sebastian Faust Credits: Stefan Dziembowski, Lisa Eckey, Julia Hesse, Kristina Hostakova, Sebastian Stammler 1 Hot topic in cryptocurrencies and academia “Channels” is our payment main focus in this talk. channels Plasma MVP Initiated by [Decker & state Wattenhofer] [Poon channels & Dryja] (plus many informal online Plasma channel Cash publications). networks “Plasma”initiated by [Poon & Buterin] (plus countless informal online publications). 2 Many interesting state channel projects We follow the terminology of Perun (L4 Counterfactual, Connext und Magmo are very similar) 3 Main goal: off-chain contracts On-chain contract: deployment and execution on-chain Chess contract Alice Bob Off-chain contract: deployment and execution off-chain Chess contract Bob Alice 4 State Channel Variants Goal: Off-chain execution of contracts Alice Ingrid Bob Ledger state channel: channel built „over ledger“ This talk Virtual state channel: channel built „over ledger channels“ Multiparty state channels: channels for multiparty contracts 5 Outline 1. Introduction 2. Ledger Channels a. Recap: Ledger Payment Channels b. Ledger State Channels 3. Virtual State Channels 4. Security analysis 5. Summary 6 Main ingredient of off-chain protocols Smart contract ≈ „programmable money“ 풙푨 + 풙푩 coins Examples: Ethereum Contract rules (in Ethereum written in Solidity) 푥 + 푥 Function퐴 call 퐵f 푥퐴coins Updating the 푥퐵 on input m coins state coins Alice Bob 1. Parties deploy contract and deposit coins to the contract 2. Execute the contract 3. Coins can be assigned back to the users 7 Ledger Payment Channels Goal: Execute payments off-chain directly over ledger Examples: Raiden Network in Ethereum, Lightning Network in Bitcoin ퟐ coins 1 coin 12 coincoins Payment channel contract 0.912 1.101 Alice BobBob 1. Create 2. Update 3. Close Dispute On-chain Off-chain! On-chain On-chain 8 Updating the ledger payment channel Goal: Update to new balance 0.99 for Alice and 1.01 for Bob Idea: exchange signatures on message containing new balance m := (0.99, 1.01, 1) An index called New balance of version number the parties 0.199 1.101 Alice Bob 흈퐀퐥퐢퐜퐞 ≔ 퐒퐢퐠퐧퐀퐥퐢퐜퐞(0.99, 1.01, 1) 흈퐁퐨퐛 ≔ 퐒퐢퐠퐧퐁퐨퐛(0.99, 1.01, 1) 흈퐀퐥퐢퐜퐞 흈퐁퐨퐛 9 Further updates For each update increase version number: version = version + 1 0.98 1.02 Alice Bob 흈퐀퐥퐢퐜퐞 ≔ 퐒퐢퐠퐧퐀퐥퐢퐜퐞(0.98, 1.02, 2) 흈퐁퐨퐛 ≔ 퐒퐢퐠퐧퐁퐨퐛(0.98, 1.02, 2) 흈퐀퐥퐢퐜퐞 흈퐁퐨퐛 10 Closing the payment channel Suppose Bob wants to close the channel 0.98 1.02 Alice Bob Payment channel Alice gets notified that contract Close(0.98, 1.02, 2, 흈퐀퐥퐢퐜퐞) close was sent Close(0.98, 1.02, 2, 흈퐀퐥퐢퐜퐞) Ping() Alice has 1 hour Verify 흈퐀퐥퐢퐜퐞 and pay time to react out balance 1.02 coins 0.98 coins 1 hour = maximal time needed to post on the ledger 11 Handling disuptes Suppose malicious Alice closes channel with earlier balance 0.98 1.02 Alice Bob Payment channel contract Close(0.99, 1.01, 1, 흈퐁퐨퐛) Close(0.99, 1.01, 1, 흈 ) 퐁퐨퐛 Close(0.98, 1.02, 2, 흈퐀퐥퐢퐜퐞) Close(0.98, 1.02, 2, 흈퐀퐥퐢퐜퐞) Verify 흈퐀퐥퐢퐜퐞 and 흈퐁퐨퐛 Pay out balance according to highest 0.98 coins 1.02 coins version number 12 Outline 1. Introduction 2. Ledger Channels a. Recap: Ledger Payment Channels b. Ledger State Channels 3. Virtual State Channels 4. Security analysis 5. Summary 13 State channels – motivation One way to look at the payment channels: Alice and Bob maintain a simulated ledger between themselves. The contents of the “simulated ledger” is registered on the “real ledger” only if: • the channel is closed, or • the parties run into a dispute. A natural question: can we also have contracts “inside of the simulated ledger”? 14 Ledger State Channels Goal: Execute contracts off-chain directly over ledger ퟐ coins 21 coinscoin 1 coin State channel contract 12 01 Alice BobBob 1. Create 2. Add 3. Execute 4. Close On-chain Off-chain! Off-chain! On-chain 15 Add a contract Recall: Contracts own coins and maintain state Idea: Extend signed tuple by coins and state of contract m := (풙푨, 풙푩, 풚, 풔풕풂풕풆, version) Alice’s Bob’s Contract’s Contract’s off- coins coins coins chain state 푦=푦퐴 + 푦퐵 풙풙푨-푨풚푨 풙풙푩푩-풚푩 Alice Initial state BobBob 흈푨풍풊풄풆= 푺풊품풏푨풍풊풄풆(풎) 흈푩풐풃= 푺풊품풏푩풐풃(풎) 16 Executing a contract Suppose Alice wants to execute contract on function Move with input a 풚 Function Input 풚 Move(a) Alice Current state New state’ How can a contract execution be done in a state channel? 1. Peaceful execution: optimistic (off-chain) 2. Forceful execution: in case of dispute (on-chain) 17 Peaceful execution Idea: Executing the contract in the state channel Suppose latest state was: (풙푨, 풙푩, 풚, 풔풕풂풕풆, version) Execute Move(a) Alice BobBob Both parties locally compute: 풚 풚 Move(a) Current state New state’ Parties exchange signatures on: (풙푨, 풙푩, 풚, 풔풕풂풕풆′, version+1) 18 Forceful execution Idea: If dispute during execution occurs, parties move on-chain Bob does Suppose latest state was: (풙푨, 풙푩, 풚, 풔tate, version) not reply Execute Move(x) Alice BobBob register Move(x,a) Register latest state (풙푨, 풙푩, 풚, 풔풕풂풕풆, version) in channel contract From then on: continue execution on-chain 19 Security and efficiency guarantees Consensus on create & add: Agreement required from Alice & Bob 1. Create: Contract requires confirmation from both parties 2. Add: Protocol requires signature from both parties Alice BobBob Guaranteed execution: Once contract is added, its execution cannot be halted achieved via forceful execution Optimistic execution in O(1) rounds: When both parties honest contract execution is in real time achieved via peaceful execution 20 Summary – ledger channels Main features compared to on-chain transactions • Low costs • Instantaneous updates/execution Payment channels State channels Purpose 2-party payments 2-party contracts Create channel On-chain On-chain Update/Execute Off-chain balance changes Off-chain contract execution Close On-chain On-chain 21 Outline 1. Introduction 2. Ledger Channels a. Recap: Ledger Payment Channels b. Ledger State Channels 3. Virtual State Channels 4. Security analysis 5. Summary 22 Channel networks Problem: every pair of parties requires a separate channel Can we do better? Yes! Alice Ingrid Bob Option 1: Routing each payment via Ingrid • Hashed Timelock Contract (HTLC): used for payments in e.g., Lightning Option 2: Creating virtual state channels • Used for state channel networks 23 Virtual state channel – overview virtual channel contract Bob, let’s play! Alice Ingrid Bob Off-chain! Off-chain! Off-chain! Off-chain! Virtual channel 1. Create 2. Add 3. Execute 4. Close Ledger channel 1. Create 2. Add 3. Execute 4. Close On-chain Off-chain! Off-chain! On-chain 24 Virtual state channel: create Add contract 푪푨 Add contract 푪푩 ퟏ ퟏ ퟏ ퟏ Alice Ingrid Bob ퟎ. ퟏ ퟎ. ퟐ Our goal 푪 푨 푪푩 ퟎ. ퟐ ퟎ. ퟏ ퟎ. ퟏ ퟎ. ퟐ Ingrid puts collateral ퟎ. ퟐ Ingrid puts collateral ퟎ. ퟏ to take role of Bob Virtual Channel Contract (VCC) to take role of Alice 25 Virtual state channel: create 푪 : OK! 푨 푪푩: OK! ퟏ ퟏ ퟏ ퟏ Alice Ingrid Bob Ingrid agreed Ingrid agreed 푪 푨 푪푩 ퟎ. ퟐ ퟎ. ퟏ ퟎ. ퟏ ퟎ. ퟐ Ingrid puts collateral ퟎ. ퟐ Ingrid puts collateral ퟎ. ퟏ to take role of Bob Virtual Channel Contract (VCC) to take role of Alice 26 Virtual state channel: create 푪 푪푨 푩 ퟎ. ퟗ ퟎ. ퟗ ퟎ. ퟏ ퟎ. ퟐ ퟎ. ퟖ ퟎ. ퟏ ퟎ. ퟐ ퟎ. ퟖ Alice Ingrid Bob ퟎ. ퟏ ퟎ. ퟐ Summary: Use sub-protocol „add“ of underlying state channel to add contract representing virtual state channel 27 Virtual state channel: contract lifecycle Alice Bob ퟎ. ퟏ ퟎ. ퟐ ퟎ. ퟐퟏ ퟎ..ퟐퟏ 1. Adding contract 2. Peacful execution of contract Exchanging signatures on new version tuples between parties 3. Closing contract 28 Virtual state channel: close Before close: Alice gained 0.1 coins and Bob lost 0.1 coins ퟎ. ퟗ ퟎ. ퟖ ퟎ. ퟗ ퟎ. ퟖ Alice Ingrid Bob ퟎ. ퟐ ퟎ. ퟏ After close: ퟏ. ퟏ ퟎ. ퟗ ퟏ. ퟏ ퟎ. ퟗ Alice Ingrid Bob ퟎ. ퟐ ퟎ. ퟏ Gained 0.1 coins Financially neutral Lost 0.1 coins 29 So far: All parties behave honestly How to handle malicious parties? Forceful execute protocol in virtual channels (Two methods: indirect vs. direct disputes) 30 Virtual state channel: forceful execute Forceful execute via indirect dispute: dispute resolution via intermediary Start registration Bob is not Start registration responding Bob is not responding Alice Ingrid Bob Move registration on-chain 31 Virtual state channel: forceful execute Forceful execute via indirect dispute: dispute resolution via intermediary Continue to Finalize registration execute off-chain Alice Ingrid Bob Move registration on-chain • Advantage: Alice does not need to go on-chain • Disadvantage: Longer time for dispute resolution 32 Virtual state channel: forceful execute Forceful execute via direct dispute: dispute resolution directly on blockchain dispute board ContinueBob is not to contract respondingexecute on-chain State registration Alice Bob • Advantage: Conflicts can be resolved faster • Disadvantage: Honest Alice needs to go to ledger 33 Extension: longer channels I want to I want to play play … Party 1 Party 2 Party 3 Party n-1 Party n … Idea: Underlying (ledger/virtual) state channels are used as building block 34 Two additional security and efficiency guarantees Balance neutrality: Ingrid never looses money ퟎ. ퟗ ퟎ. ퟏ ퟎ. ퟐ ퟎ. ퟖ ퟎ. ퟗ ퟎ. ퟏ ퟎ. ퟐ ퟎ. ퟖ Alice Ingrid Bob ퟎ. ퟏ ퟎ. ퟐ Whatever malicious Alice and Bob do, Ingrid will always receive back her 2 coins Pessimistic execution for virtual channels built over n ledger state channels: • Direct dispute: O(n) rounds • Indirect dispute: O(1) rounds 35 Summary – ledger vs.