Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf ·...

64
James R. Wilcox Zach Tatlock Ilya Sergey Programming Language Abstractions for Modularly Verified Distributed Systems {P } c {Q} `

Transcript of Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf ·...

Page 1: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

James R. Wilcox Zach Tatlock Ilya Sergey

Programming Language Abstractions for Modularly Verified Distributed Systems

{P} c {Q}`

Page 2: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Distributed Systems

Page 3: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Distributed Infrastructure

Page 4: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Distributed Applications

Page 5: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Verified Distributed Systems

Page 6: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Verified Distributed Systems

Page 7: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Verified Distributed Infrastructure

Page 8: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Verified Distributed Infrastructure

-Cert

Veri-

Iron

Wow

Page 9: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Verified Distributed Applications

Page 10: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Verified Distributed Applications

-Cert

Veri-

Iron

Wow

Page 11: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Verified Distributed Applications

-Cert

Veri-

Iron

Wow

Challenging to verify apps in terms of infra. verify clients by starting over!

Indicates deeper problems with composition one node’s client is another’s server!

Page 12: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Verified Distributed Applications

-Cert

Veri-

Iron

Wow

Challenging to verify apps in terms of infra. verify clients by starting over!Indicates deeper problems with composition one node’s client is another’s server!

(Make it possible to) verify clients verify clients without starting over!

Will also enable more general composition

Page 13: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Composition: A way to make proofs harder

Page 14: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Composition: A way to make proofs harder

When distracting language issues are removed and the underlying mathematics is revealed, compositional reasoning is seen to be of little use.

Page 15: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Approach

`{P} c {Q}

Distributed Hoare Type Theory

Page 16: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Distributed InteractionsServers and Clients

Optimizations

Combining Services

Horizons

gcc -O3

Page 17: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Compute

SC

21

Page 18: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Compute

Page 19: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Compute

Page 20: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Computewhile True: (from, n) <- recv send (n, factors(n)) to from

: Server

Page 21: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Computewhile True: (from, n) <- recv send (n, factors(n)) to from

: Server

Traditional specification: messages from server have correct factors

Proved by finding an invariant of the system

Page 22: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Compute: Server

Page 23: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Compute: Client

Page 24: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Compute: Clientsend 21 to server (_, ans) <- recv assert ans == {3, 7}

Page 25: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Compute: Clientsend 21 to server (_, ans) <- recv assert ans == {3, 7}

Expand system to include clients

Need to reason about client-server interaction introduce protocol

Page 26: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Protocols

Page 27: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Protocols

Page 28: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Protocols

Protocols make it possible to verify clients!

Page 29: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Protocols

Page 30: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Protocols

State:abstract state of each node

Page 31: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Protocols

State:

Transitions:

abstract state of each node

allowed sends and receives

Page 32: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Compute Protocol

State:

Transitions:

Page 33: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Compute Protocol

State:

Transitions:

permissions: Set<Msg>

Page 34: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Compute Protocol

Send Req

Recv Req

Send Resp

Recv Resp

State:

Transitions:

permissions: Set<Msg>

Page 35: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Compute: Protocol

Send Req

Recv Req

Send Resp

Recv Resp

State:

Transitions:

perm: Set<Msg>Effect: add (from, n) to perm

Recv Request n

Page 36: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Compute: Protocol

Send Req

Recv Req

Send Resp

Recv Resp

State:

Transitions:

perm: Set<Msg>

Effect:removes (n,to) from perm

Send Response (n,l)

Requires:l == factors(n)

(n,to) in perm

Page 37: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Compute: Protocol

Send Req

Recv Req

Send Resp

Recv Resp

State:

Transitions:

perm: Set<Msg>Recv Response l

Ensures:l == factors(n)

(n,to) in perm

Page 38: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Compute: Protocol

Send Req

Recv Req

Send Resp

Recv Resp

State:

Transitions:

permissions: Set<Msg>

Page 39: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Compute: Protocol

Send Req

Recv Req

Send Resp

Recv Resp

State:

Transitions:

permissions: Set<Msg>Protocols make it possible to verify clients!

Page 40: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

From Protocols to Types

`{P} c {Q}

Page 41: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

From Protocols to Types

`{P} { }tsent ( )m h,send m to h

Page 42: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

From Protocols to Types

` send m to ht{P} { }tsent ( )m h,

Page 43: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

From Protocols to Types

` send m to ht

t 2

{P} { }tsent ( )m h,

Page 44: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

From Protocols to Types

` send m to ht

t 2

{P} { }tsent ( )m h,

P ) Pre t

Page 45: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

From Protocols to Types

` send m to ht

t 2

{P} { }tsent ( )m h,

P ) Pre t

Page 46: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Compute: Clientsend 21 to server (_, ans) <- recv assert ans == {3, 7}

Page 47: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Compute: Clientsend 21 to server (_, ans) <- recv assert ans == {3, 7}

recv ensures correct factors

Page 48: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Compute: More Clientssend 21 to server1 send 35 to server2 (_, ans1) <- recv (_, ans2) <- recv assert ans1 ans2 == {3, 5, 7}[

Page 49: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Compute: More Clientssend 21 to server1 send 35 to server2 (_, ans1) <- recv (_, ans2) <- recv assert ans1 ans2 == {3, 5, 7}[

Same protocol enables verification

Page 50: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Compute: More Clientssend 21 to server1 send 35 to server2 (_, ans1) <- recv (_, ans2) <- recv assert ans1 ans2 == {3, 5, 7}[

Same protocol enables verification

Page 51: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Computewhile True: (from, n) <- recv send (n, factors(n)) to from

: Server

Page 52: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Computewhile True: (from, n) <- recv send (n, factors(n)) to from

: Server

Precondition on send requires correct factors

Page 53: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Computecache = {}while True: (from, n) <- recv ans = if n cache then cache[n] else factors(n) cache[n] = ans send (n, ans) to from

: More Servers

2

Page 54: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Computecache = {}while True: (from, n) <- recv ans = if n cache then cache[n] else factors(n) cache[n] = ans send (n, ans) to from

: More Servers

2

Still follows protocol!

Page 55: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Computewhile True: (from, n) <- recv send n to backend (_, ans) <- recv send (n, ans) to from

: More Servers

Page 56: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Computewhile True: (from, n) <- recv send n to backend (_, ans) <- recv send (n, ans) to from

: More ServersStill follows protocol!

Page 57: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Cloud Computewhile True: (from, n) <- recv send n to backend (_, ans) <- recv send (n, ans) to from

: More ServersStill follows protocol!

One node’s client is another’s server!

Any combination of transitions follows protocolWell-typed programs don’t go wrong!

Page 58: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Horizons

Adding other effects

Sophisticated protocol compositione.g. computation uses separate database

e.g. mutable heap, threads, failure…

Fault tolerancewhat do Verdi’s VSTs look like here?

Page 59: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Verified Distributed Applications

Page 60: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Verified Distributed Applications

-Cert

Veri-

Iron

Wow

Page 61: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Verified Distributed Applications

-Cert

Veri-

Iron

Wow

Challenging to verify apps in terms of infra. verify clients by starting over!

Indicates deeper problems with composition one node’s client is another’s server!

Page 62: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Verified Distributed Applications

-Cert

Veri-

Iron

Wow

Challenging to verify apps in terms of infra. verify clients by starting over!Indicates deeper problems with composition one node’s client is another’s server!

Protocols make it possible to verify clients reason about client-server interactionAlso enable more general composition

Any combination of transitions follows protocolWell-typed programs don’t go wrong!

Page 63: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Verified Distributed Applications

-Cert

Veri-

Iron

Wow

Protocols make it possible to verify clients reason about client-server interactionAlso enable more general composition

Any combination of transitions follows protocolWell-typed programs don’t go wrong!

Page 64: Programming Language Abstractions for Modularly Verified ...jamesrwilcox.com/snapl17-talk.pdf · -Cert Veri-Iron Wow Challenging to verify apps in terms of infra. verify clients

Verified Distributed Applications

-Cert

Veri-

Iron

Wow

Composition is hard but important for infrastructure

Achieve with types syntactic theory of composition

Protocols make it possible to verify clients reason about client-server interactionAlso enable more general composition

Any combination of transitions follows protocolWell-typed programs don’t go wrong!