Off-chain Protocols: (Vir irtual) State Channels
Sebastian Faust
BDLT 2019, Vienna, Austria
Credits: Stefan Dziembowski, Lisa Eckey, Julia Hesse, Kristina Hostakova, Sebastian Stammler
1
(Vir irtual) State Channels Sebastian Faust Credits: Stefan - - PowerPoint PPT Presentation
BDLT 2019, Vienna, Austria Off-chain Protocols: (Vir irtual) State Channels Sebastian Faust Credits: Stefan Dziembowski, Lisa Eckey, Julia Hesse, Kristina Hostakova, Sebastian Stammler 1 Hot topic in cryptocurrencies and academia Channels
BDLT 2019, Vienna, Austria
Credits: Stefan Dziembowski, Lisa Eckey, Julia Hesse, Kristina Hostakova, Sebastian Stammler
1
payment channels state channels Plasma MVP Plasma Cash channel networks
“Channels” is our main focus in this talk. Initiated by [Decker & Wattenhofer] [Poon & Dryja] (plus many informal online publications). “Plasma”initiated by [Poon & Buterin] (plus countless informal online publications).
2
We follow the terminology of Perun
(L4 Counterfactual, Connext und Magmo are very similar)
3
Chess contract
Bob Alice
On-chain contract: deployment and execution on-chain Off-chain contract: deployment and execution off-chain
Chess contract
Bob Alice
4
Goal: Off-chain execution of contracts
Ledger state channel: channel built „over ledger“ Virtual state channel: channel built „over ledger channels“ Multiparty state channels: channels for multiparty contracts
Bob Alice Ingrid
This talk
5
1. Introduction
a. Recap: Ledger Payment Channels b. Ledger State Channels
6
Bob Alice
Smart contract ≈ „programmable money“ Examples: Ethereum
1. Parties deploy contract and deposit coins to the contract 2. Execute the contract 3. Coins can be assigned back to the users
𝑦𝐵 coins 𝑦𝐶 coins
Contract rules
(in Ethereum written in Solidity)
𝒚𝑩 + 𝒚𝑪 coins Function call f
𝑦𝐵 + 𝑦𝐶 coins
Updating the state
7
Alice
1 coin 1 coin 2 coins
Off-chain! On-chain 1 On-chain Dispute On-chain Bob Bob
Goal: Execute payments off-chain directly over ledger Examples: Raiden Network in Ethereum, Lightning Network in Bitcoin
Payment channel contract 1 0.9 1.1 2 𝟑 coins
8
𝝉𝐁𝐦𝐣𝐝𝐟 ≔ 𝐓𝐣𝐡𝐨𝐁𝐦𝐣𝐝𝐟(0.99, 1.01, 1) 𝝉𝐂𝐩𝐜 ≔ 𝐓𝐣𝐡𝐨𝐂𝐩𝐜(0.99, 1.01, 1)
Bob Alice
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)
1 1
New balance of the parties An index called version number
𝝉𝐁𝐦𝐣𝐝𝐟 𝝉𝐂𝐩𝐜
0.99 1.01
9
Bob Alice
For each update increase version number: version = version + 1
0.98 1.02
𝝉𝐁𝐦𝐣𝐝𝐟 𝝉𝐂𝐩𝐜 𝝉𝐁𝐦𝐣𝐝𝐟 ≔ 𝐓𝐣𝐡𝐨𝐁𝐦𝐣𝐝𝐟(0.98, 1.02, 2) 𝝉𝐂𝐩𝐜 ≔ 𝐓𝐣𝐡𝐨𝐂𝐩𝐜(0.98, 1.02, 2)
10
Bob Alice
Suppose Bob wants to close the channel
0.98 1.02
Payment channel contract
Close(0.98, 1.02, 2, 𝝉𝐁𝐦𝐣𝐝𝐟) Alice gets notified that close was sent Alice has 1 hour time to react 1 hour = maximal time needed to post on the ledger Ping() 1.02 coins 0.98 coins Verify 𝝉𝐁𝐦𝐣𝐝𝐟 and pay
Close(0.98, 1.02, 2, 𝝉𝐁𝐦𝐣𝐝𝐟)
11
Bob Alice
Suppose malicious Alice closes channel with earlier balance
0.98 1.02
Payment channel contract
Close(0.99, 1.01, 1, 𝝉𝐂𝐩𝐜) 1.02 coins 0.98 coins Verify 𝝉𝐁𝐦𝐣𝐝𝐟 and 𝝉𝐂𝐩𝐜 Close(0.98, 1.02, 2, 𝝉𝐁𝐦𝐣𝐝𝐟) Pay out balance according to highest version number Close(0.99, 1.01, 1, 𝝉𝐂𝐩𝐜) Close(0.98, 1.02, 2, 𝝉𝐁𝐦𝐣𝐝𝐟)
12
1. Introduction
a. Recap: Ledger Payment Channels b. Ledger State Channels
13
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:
A natural question: can we also have contracts “inside of the simulated ledger”?
14
Alice
1 coin 1 coin 2 coins
Off-chain! On-chain 1 On-chain Bob Bob
Goal: Execute contracts off-chain directly over ledger
State channel contract 1 2
Off-chain! 𝟑 coins
15
Alice Bob Bob
Recall: Contracts own coins and maintain state Idea: Extend signed tuple by coins and state of contract m := (𝒚𝑩, 𝒚𝑪, 𝒛, 𝒕𝒖𝒃𝒖𝒇, version)
𝒚𝑪
Alice’s coins Bob’s coins Contract’s off- chain state Contract’s coins
𝑧=𝑧𝐵 + 𝑧𝐶
Initial state
𝝉𝑩𝒎𝒋𝒅𝒇= 𝑻𝒋𝒉𝒐𝑩𝒎𝒋𝒅𝒇(𝒏) 𝝉𝑪𝒑𝒄= 𝑻𝒋𝒉𝒐𝑪𝒑𝒄(𝒏)
𝒚𝑩 𝒚𝑪-𝒛𝑪 𝒚𝑩-𝒛𝑩
16
Alice
Suppose Alice wants to execute contract on function Move with input a How can a contract execution be done in a state channel? 1. Peaceful execution: optimistic (off-chain)
Move(a) Function
Current state
𝒛
New state’
𝒛
Input
17
Alice
Idea: Executing the contract in the state channel Suppose latest state was: (𝒚𝑩, 𝒚𝑪, 𝒛, 𝒕𝒖𝒃𝒖𝒇, version) Both parties locally compute: Parties exchange signatures on: (𝒚𝑩, 𝒚𝑪, 𝒛, 𝒕𝒖𝒃𝒖𝒇′, version+1)
Bob Bob
Execute Move(a) Move(a)
Current state
𝒛
New state’
𝒛
18
Alice
Idea: If dispute during execution occurs, parties move on-chain Suppose latest state was: (𝒚𝑩, 𝒚𝑪, 𝒛, 𝒕tate, version) Register latest state (𝒚𝑩, 𝒚𝑪, 𝒛, 𝒕𝒖𝒃𝒖𝒇, version) in channel contract From then on: continue execution on-chain
Bob Bob
Execute Move(x) Bob does not reply register Move(x,a)
19
Consensus on create & add: Agreement required from Alice & Bob 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
Alice Bob Bob
1. Create: Contract requires confirmation from both parties
from both parties
20
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
Main features compared to on-chain transactions
21
1. Introduction
a. Recap: Ledger Payment Channels b. Ledger State Channels
22
Problem: every pair of parties requires a separate channel Can we do better? Yes! Option 1: Routing each payment via Ingrid
Option 2: Creating virtual state channels
Bob Alice Ingrid
23
Bob Alice Ingrid Bob, let’s play!
virtual channel contract
Off-chain! On-chain On-chain
Off-chain!
Virtual channel
Ledger channel
Off-chain! Off-chain! Off-chain! Off-chain!
24
Bob Alice Ingrid
𝟏. 𝟐 𝟏. 𝟑
𝟐 𝟐 𝟐 𝟐
Our goal
Virtual Channel Contract (VCC)
𝟏. 𝟐 𝟏. 𝟑 𝟏. 𝟑 𝟏. 𝟐
Ingrid puts collateral 𝟏. 𝟑 to take role of Bob
Add contract 𝑫𝑩 Add contract 𝑫𝑪
𝑫𝑩 𝑫𝑪 Ingrid puts collateral 𝟏. 𝟐 to take role of Alice
25
Bob Alice Ingrid
𝟐 𝟐 𝟐 𝟐
𝑫𝑩: OK! 𝑫𝑪: OK!
Virtual Channel Contract (VCC)
𝟏. 𝟐 𝟏. 𝟑 𝟏. 𝟑 𝟏. 𝟐
Ingrid puts collateral 𝟏. 𝟑 to take role of Bob 𝑫𝑩 𝑫𝑪 Ingrid puts collateral 𝟏. 𝟐 to take role of Alice Ingrid agreed Ingrid agreed
26
Bob Alice Ingrid
𝟏. 𝟐 𝟏. 𝟑 𝟏. 𝟐 𝟏. 𝟑
𝟏. 𝟐 𝟏. 𝟑 𝟏. 𝟘 𝟏. 𝟗 𝟏. 𝟗 𝟏. 𝟘
Summary: Use sub-protocol „add“ of underlying state channel to add contract representing virtual state channel
𝑫𝑩 𝑫𝑪
27
Bob Alice 𝟏. 𝟐 𝟏. 𝟑
1. Adding contract
𝟏. 𝟐 𝟏. 𝟑
Exchanging signatures on new version tuples between parties
𝟏. 𝟑 𝟏. 𝟐
28
Bob Alice Bob Alice Ingrid
𝟏. 𝟘 𝟏. 𝟗 𝟏. 𝟗 𝟏. 𝟘
After close:
𝟏. 𝟑 𝟏. 𝟐
Bob Bob Alice Alice Ingrid
𝟐. 𝟐 𝟏. 𝟘 𝟏. 𝟘 𝟐. 𝟐 Gained 0.1 coins Lost 0.1 coins Financially neutral
Before close: Alice gained 0.1 coins and Bob lost 0.1 coins
𝟏. 𝟑 𝟏. 𝟐
29
30
Alice Bob Bob Alice Ingrid Bob is not responding Bob Bob
Start registration Start registration
Bob is not responding
Move registration on-chain
Forceful execute via indirect dispute: dispute resolution via intermediary
31
Alice Bob Bob Alice Ingrid Bob Bob
Move registration on-chain
Forceful execute via indirect dispute: dispute resolution via intermediary
Finalize registration
Continue to execute
32
Bob
Alice
Bob is not responding Continue to execute
dispute board contract
Forceful execute via direct dispute: dispute resolution directly on blockchain
State registration
33
Idea: Underlying (ledger/virtual) state channels are used as building block
Party 3 Party 1 Party 2 Party n
…
Party n-1
I want to play I want to play
34
Balance neutrality: Ingrid never looses money 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:
Bob Alice Ingrid
𝟏. 𝟐 𝟏. 𝟑
𝟏. 𝟘 𝟏. 𝟗 𝟏. 𝟗 𝟏. 𝟘
𝟏. 𝟐 𝟏. 𝟑 𝟏. 𝟐 𝟏. 𝟑
35
Ledger channels Virtual channels Create On-chain Off-chain Update/Execute Off-chain Off-chain Close On-chain
Technique to connect ledger channels
Minimize interaction with intermediary
36
1. Introduction
a. Recap: Ledger Payment Channels b. Ledger State Channels
37
38
39
Define security
Design protocol Prove security
Provable security: Sound methodology for complex protocols Two ways of defining security:
Example: IND-CPA security for encryption
„better“ than in ideal world. Example: crypto protocols in the universal composability model.
Adversary 𝑛0, 𝑛1 𝐹𝑜𝑑(𝑛𝑐) Challenger Real world Ideal world Ideal adversary
≈
40
Describes “everything else” happening in the world (e.g., other protocol executions etc.)
Protocol P
Environment API Side effects
Environment orchestrates:
communicate with environment in each step of protocol execution via side effects (communication, consumed time and resources, etc.)
Analyse security of protocol by analysing its effects on the environment
41
How to analyse the effects that a protocol has on its environment?
ℱ
Environment 𝓕
Simulator 𝒯
API Ideal side effects Simulated side effects
Protocol P
Environment API Side effects
42
P UC-realizes 𝓖 if ∃ 𝓣 s.t. ∀ 𝓕 the interaction with (ℱ, 𝓣) is indistinguishable from the interaction with P
Might be difficult to prove if P very complex
Technique: Modularize protocol and proofs ℱ
Environment 𝓕
Simulator 𝒯
API Ideal side effects Simulated side effects
Protocol P
Environment API Side effects
43
Ideal world Hybrid world Real world
𝓕
𝜍
𝝆 𝝆 𝝆
𝓕
ℋ ℋ ℋ
ℱ 𝒯
𝓕
𝜍
Show hybrid protocol (𝜍, ℋ) UC-realizes ideal functionality ℱ
Modularize protocol P: P composed of (𝜍, 𝜌) with 𝜍 the main protocol and 𝜌 sub-routines Show that 𝜌 UC-realizes ℋ
ℋ 𝝆 𝒯
≈
𝓕 𝓕
44
Ideal world Real world
1. Ideal functionality ℱ
2. Protocol P
3. Simulator 𝒯
world indistinguishable
ℱ
𝒯
𝓕 𝓕
45
How to model a public ledger in UC?
in real and ideal world
Ideal world Real world
ℱ𝑑ℎ input input
Ledger Alice 5 Bob 6 … Ledger Alice 5 Bob 6 … Also the environment!
46
State Channel Functionality Create Add Close Execute Ledger Alice 5 Bob 6 …
input
input
47
Ledger Alice 5 Bob 6 …
input
input
State channel smart contract hybrid world
State Channel Smart Contract
48
Ideal world Hybrid world
ℱ𝑑ℎ Ledger Alice 5 Bob 6 input input
Ledger Alice 5 Bob 6 𝑢1 𝑢2 𝑢3 𝑢1 𝑢2 𝑢3 Ledger Alice 4 Bob 6 Ledger Alice 4 Bob 6
𝒯
Transact now! Output now!
49
Ideal world Hybrid world
ℱ𝑑ℎ Ledger Alice 5 Bob 6 input input
Ledger Alice 5 Bob 6 𝑢1 𝑢2 𝑢1 𝑢2 𝑢′3 Ledger Alice 4 Bob 6 Ledger Alice 4 Bob 6
𝒯
𝑢′3
Ledger Ledger ℱ𝑑ℎ(2) 𝛲(2) ℱ𝑑ℎ(1) Ledger ℱ𝑑ℎ(3) = = 𝛲(3) Ledger 𝛲(1) = Recall: protocol design Proof steps
1. Channel of length 𝑗 build on top of channels of length ≤ 𝑗 − 1 2. UC Composition 3. Channel of length 1 build using state channel smart contract 4. UC Composition
P
1. Introduction
a. Recap: Ledger Payment Channels b. Ledger State Channels
52
53
state channels, Services, Privacy, Routing, Optimizations,…
a) More formal modelling and proofs needed b) Hybrids of Channels & Plasma c) Explore limitations via lower bounds d) Optimization and implementation e) ...
Icons made by Freepik, Smashicons, and Nikita Golubev from www.flaticon.com
54