21
Kaizen: Building a Performant Blockchain System Verified for Consensus and Integrity Faria Kalim , Karl Palmskog * , Jayasi Mehar , Adithya Murali , P. Madhusudan and Indranil Gupta University of Illinois at Urbana-Champaign * KTH; work done while at UT Austin and UIUC Facebook; work done while at UIUC 1 / 21

Kaizen: Building a Performant Blockchain System Verified

  • Upload
    others

  • View
    4

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Kaizen: Building a Performant Blockchain System Verified

Kaizen: Building a Performant BlockchainSystem Verified for Consensus and Integrity

Faria Kalim†, Karl Palmskog∗, Jayasi Mehar‡, Adithya Murali†,

P. Madhusudan† and Indranil Gupta†

†University of Illinois at Urbana-Champaign∗KTH; work done while at UT Austin and UIUC

‡Facebook; work done while at UIUC

1 / 21

Page 2: Kaizen: Building a Performant Blockchain System Verified

Blockchains and Cryptocurrencies

distributed ledger

disseminationtransactions+state

consensus

NakamotoAlgorand Ouroboros

BitcoinEthereum

2 / 21

Page 3: Kaizen: Building a Performant Blockchain System Verified

Consensus Protocol Challenges

Distributed protocols need to handle:

communication delays (asynchrony)

node crashes, corruption

message drops, duplication, forging

Protocol implementation challenges:

conformance to protocol specification

node-local performance

absence of bugs compromising safety

3 / 21

Page 4: Kaizen: Building a Performant Blockchain System Verified

Consensus System Formal Verification

Project Paper Protocol Tool LOC

Disel POPL ’18 2-phase commit Coq 5k+Verdi Raft CPP ’16 Raft Coq 50k+Velisarios ESOP ’18 PBFT Coq 50k+Ironfleet SOSP ’15 Paxos Dafny 20k+

Toychain CPP ’18 proof-of-X Coq 10k+

4 / 21

Page 5: Kaizen: Building a Performant Blockchain System Verified

Interactive vs. Mostly-Automated Verification

Coq proof assistant

- much training required

+ explicit proofs

+ many libraries

- purely functional (extraction to OCaml/Haskell)

Dafny verification environment

+ less training required

- implicit proofs

- few libraries

+ functional & imperative (C# code generation)

5 / 21

Page 6: Kaizen: Building a Performant Blockchain System Verified

Our Contributions

novel combination of Coq & Dafny to build performant andverified blockchain system, Kaizen

methodology based on continuous refinement

adapted & instantiated Coq modeltranslated Coq code (not proofs) to Dafny imperative coderefined C# code and linked to network shim

performed evaluation measuring minting and consensus time

6 / 21

Page 7: Kaizen: Building a Performant Blockchain System Verified

Methodology Overview∗

PHASE 1 PHASE 2 PHASE 3 PHASE 4 PHASE 5 PHASE 6 PHASE 7

STAGE I STAGE II STAGE III

Abstract protocol design &

verification in Coq

Translation of abstract

protocol to Dafny

contracts

Refinement to imperative

code in Dafny

Implementing application

specific functions in C#

Translation to executable code on a

distributed network

Refinement in Coq

Refinement in Dafny for

performance

Coq experts Dafny experts Dafny experts and systems engineers Systems engineers

∗system is fully verified until Stage III

7 / 21

Page 8: Kaizen: Building a Performant Blockchain System Verified

Stage I: Modeling and Verification Using Coq

1 encode system in higher-order functional language (Gallina)

2 prove specification interactively using powerful tactics

3 check soundness of every low-level step

user logic engine type checker

Coqtactics

subgoals

proof term

8 / 21

Page 9: Kaizen: Building a Performant Blockchain System Verified

Toychain Examples

Record Block := mkB { prevBlockHash : Hash;

txs : seq Transaction; proof : VProof }.

Record State := mkS { id: Address; peers: seq Address;

forest: map Hash Block; txpool: seq Transaction }.

Definition valid_chain_block (bc:seq Block) (b:Block):=

VAF (proof b) bc (txs b) && all [pred t | txValid t bc] (txs b).

9 / 21

Page 10: Kaizen: Building a Performant Blockchain System Verified

Toychain Results and Extensions

Toychain proves that in quiescent state, all nodes know thesame (canonical) chain

we added support for coinbase transactions

we added checking of proof-of-work validity of chains

we changed Toychain nodes to avoid unncessary messages

All changes are proof-preserving and now merged into Toychain.

10 / 21

Page 11: Kaizen: Building a Performant Blockchain System Verified

Stage II: Refinement and Verification Using Dafny

1 encode programs and their contracts in imperative language

2 try to prove automatically that contracts are fulfilled

3 add more annotations if necessary

user Dafny Boogie Z3

?

Dfy program IVL program VCs

11 / 21

Page 12: Kaizen: Building a Performant Blockchain System Verified

Dafny Examples

datatype Block = Block(prevBlockHash : Hash,txs : seq<Transaction>, proof : VProof)

datatype State = Node(id : Address, peers : seq<Address>,forest : map<Hash,Block>, txpool : seq<Transaction>)

class StateImpl {

var id : Address;var peers : . . .; var forest : . . .; var txpool : . . .;ghost var st : State;

predicate Valid() { . . .}

method ProcMsgImpl(from : Address, msg : Message, ts : Timestamp)returns (pt : seq<Packet>)requires Valid();

ensures Valid();

ensures st =procMsg(old(st), from, msg, ts).0;

ensures pt =procMsg(old(st), from, msg, ts).1;

{ . . .}}

12 / 21

Page 13: Kaizen: Building a Performant Blockchain System Verified

Stage III: Refinements in C#

block and proof-of-work generation

define and inject miner rewards

store pre-computed chains

add network shim based on UDP

13 / 21

Page 14: Kaizen: Building a Performant Blockchain System Verified

Implementation Architecture

Shim Layer

BitcoinFunctions

BlockchainFunctions

Verified Implementation

Message Queue

Shim Layer

Bitcoin Functions

BlockchainFunctions

Verified Implementation

Message Queue

Network Peer Network Peer

14 / 21

Page 15: Kaizen: Building a Performant Blockchain System Verified

Evaluation Setup

metrics: block minting time and consensus time

use 30-node cluster of 2.4GHz processors w/ 64GB RAM

baseline: performance of stock Bitcoin implementation

workload: traces of arrival times of 50 transactions fromrealistic dataset

15 / 21

Page 16: Kaizen: Building a Performant Blockchain System Verified

Evaluation: Block Minting Time

100 500 1000Initial Number of Blocks

0.0

0.2

0.4

0.6

0.8

Tim

e to

Min

t Blo

ck (S

econ

ds)

Bitcoin: 30 NodesKznCoin: 10 Nodes

KznCoin: 20 NodesKznCoin: 30 Nodes

16 / 21

Page 17: Kaizen: Building a Performant Blockchain System Verified

Evaluation: Consensus Time

100 500 1000Initial Number of Blocks

0

1

2

Tim

e to

Con

sens

us (S

econ

ds)

Bitcoin KznCoin

17 / 21

Page 18: Kaizen: Building a Performant Blockchain System Verified

Evaluation: Scalability

10 20 30Cluster Size

0

2

4

6

8

10

Tim

e to

Con

sens

us (S

econ

ds)

Bitcoin - 50KznCoin - 50

Bitcoin - 250KznCoin - 250

18 / 21

Page 19: Kaizen: Building a Performant Blockchain System Verified

Components and Effort

Component Lines of Code

Coq refinement ≈ 1kDafny refinement ≈ 5kC# refinement ≈ 1kC# network shim ≈ 4k

Development effort ≈ 6 person months across four people

19 / 21

Page 20: Kaizen: Building a Performant Blockchain System Verified

Lessons Learned and Future Work

holistic expertise necessary in Coq/Dafny/systems for Kaizen

“easy” change can require large changes at earlier stages

local node computation took most effort to optimize (ratherthan network messaging)

future Coq proofs of Toychain Byzantine tolerancetransferrable to Kaizen (see WIP by Gopinathan and Sergey,CoqPL ’19)

20 / 21

Page 21: Kaizen: Building a Performant Blockchain System Verified

Conclusion

system development methodology combines interactive andmostly-automated verification, Coq & Dafny

verified executable blockchain system Kaizen

evaluation gives encouraging results on performance

More information:

GitHub: https://github.com/palmskog/kaizen

contact me: Karl Palmskog [email protected]

21 / 21