SLIDE 1 Language Extensibility, Metaprogramming and Proof automation
Meta-F*
https://fstar-lang.github.io https://project-everest.github.io/
SLIDE 2 Classified as Microsoft Confidential
MSR R Redm dmond
- nd
- Barry Bond
- Chris Hawblitzel
- Qunyan Magnus
- Kiran Muthabatulla
- Jonathan Protzenko
- Tahina Ramananandro
- Nikhil Swamy
- Gustavo Varo
- MS
MSR R Camb mbridg ridge
- Antoine Delignat-Lavaud
- Cédric Fournet
- Christoph M. Wintersteiger
- Santiago Zanella-Béguelin
- MS
MSR R India ia
A Paris
- Danel Ahman
- Kenji Maillard
- Benjamin Beurdouche
- Karthikeyan Bhargavan
- Victor Dumitrescu
- Cătălin Hriţcu
- Marina Polubelova
- CMU
MU (P (Pitts ttsbu burgh) gh)
- Jay Bosamiya
- Aymeric Fromherz
- Bryan Parno
- Edinburgh
- Markulf Kohlweiss
- Interns, open-source
contributors, visitors, alumns
- Guido Martinez
- Zoe Paraskevopoulou
- Yao Li
- Joonwon Choi
- Clément Pit-Claudel
- Nick Giannarakis
- Niklas Grimm
- Anita Gollamudi
- Nadim Kobeissi
- Matteo Maffei
- Asher Manning
- Monal Narasimhamurthy
- Gordon Plotkin
- Perry Wang
- Jean-Karim Zinzindohoue
SLIDE 3 Classified as Microsoft Confidential
MSR R Redm dmond
- nd
- Barry Bond
- Chris Hawblitzel
- Qunyan Magnus
- Kiran Muthabatulla
- Jonathan Protzenko
- Tahina Ramananandro
- Nikhil Swamy
- Gustavo Varo
- MS
MSR R Camb mbridg ridge
- Antoine Delignat-Lavaud
- Cédric Fournet
- Christoph M. Wintersteiger
- Santiago Zanella-Béguelin
- MS
MSR R India ia
A Paris
- Danel Ahman
- Kenji Maillard
- Benjamin Beurdouche
- Karthikeyan Bhargavan
- Victor Dumitrescu
- Cătălin Hriţcu
- Marina Polubelova
- CMU
MU (P (Pitts ttsbu burgh) gh)
- Jay Bosamiya
- Aymeric Fromherz
- Bryan Parno
- Edinburgh
- Markulf Kohlweiss
- Interns, open-source
contributors, visitors, alumns
- Guido Martinez
- Zoe Paraskevopoulou
- Yao Li
- Joonwon Choi
- Clément Pit-Claudel
- Nick Giannarakis
- Niklas Grimm
- Anita Gollamudi
- Nadim Kobeissi
- Matteo Maffei
- Asher Manning
- Monal Narasimhamurthy
- Gordon Plotkin
- Perry Wang
- Jean-Karim Zinzindohoue
SLIDE 4
SLIDE 5 Threat model
Goal: A secure channel
connect(server,port); send “GET…”; data = recv(); send “POST…”; … accept(port); request = recv(); send “<html>…”;
…
Public Key Infrastructure
SLIDE 6 Threat model
Goal: A secure channel
connect(server,port); send “GET…”; data = recv(); send “POST…”; … accept(port); request = recv(); send “<html>…”;
…
Public Key Infrastructure
20 years of attacks & fixes
Buffer overflows Incorrect state machines Lax certificate parsing Weak or poorly implemented crypto Side channels Informal security goals Dangerous APIs Flawed standards
Mainstream implementations
OpenSSL, SChannel, NSS, …
SLIDE 7 Much discussions
IETF, Google, Mozilla, Microsoft, CDNs, cryptographers, network engineers, …
Much improvements
- Modern design
- Fewer roundtrips
- Stronger security
New implementations required for all
- An early implementer and verified too!
- Find & fix flaws before it’s too late
RFC 8446: Aug 2018 Including many of our proposals
Mentioning many formal models of the protocol, including our verified implementation of the record layer
SLIDE 8 … TLS RSA SHA Network buffers Untrusted network (TCP, UDP, …)
Crypto Algorithms
Pr Proje ject t Ever erest est Ver erif ified ied Sec ecur ure e Compon ponents ents in in th the e TL TLS Ecosystem system
QUIC ECDH AES
SLIDE 9 F*: A general purpose programming language and verification tool
Ver erification fication T
s an and d Met ethodo
logy gy
SLIDE 10 F*: A general purpose programming language and verification tool
Ver erification fication T
s an and d Met ethodo
logy gy
val nbytes 16 → u32 → nbytes len → nbytes 32 ∧ → ST unit requires λ → ∈ ∧ ∈ ∧ ∈ ensures λ → let in let in modifies ∧
Math spec in F*
poly1305_mac computes a
polynomial in GF(2130-5), storing the result in tag, and not modifying anything else
SLIDE 11 F*: A general purpose programming language and verification tool
kreMLin
Compiler from (a subset of) F* to C
Ver erification fication T
s an and d Met ethodo
logy gy
val nbytes 16 → u32 → nbytes len → nbytes 32 ∧ → ST unit requires λ → ∈ ∧ ∈ ∧ ∈ ensures λ → let in let in modifies ∧
Math spec in F*
poly1305_mac computes a
polynomial in GF(2130-5), storing the result in tag, and not modifying anything else Efficient C implementation Verification imposes no runtime performance
void poly1305_mac(uint8_t *tag, uint32_t len, uint8_t *msg, uint8_t *key) { uint64_t tmp [10] = { 0 }; uint64_t *acc = tmp uint64_t *r = tmp + (uint32_t)5; uint8_t s[16] = { 0 }; Crypto_Symmetric_Poly1305_poly1305_init(r, s, key); Crypto_Symmetric_Poly1305_poly1305_process(msg, len, acc, r); Crypto_Symmetric_Poly1305_poly1305_finish(tag, acc, s); }
SLIDE 12 8
Protocol specs Protocol security proofs Security spec Crypto assumptions
Implementation
AES is a pseudo-random function
= Verified = Trusted
Secure authenticated channel
SLIDE 13
SLIDE 14 Everest est in Action, n, so so fa far Production deployments of Everest Verified Cryptography
SLIDE 15 … TLS RSA SHA Network buffers Untrusted network (TCP, UDP, …)
Crypto Algorithms
Pr Proje ject t Ever erest est Ver erif ified ied Sec ecur ure e Compon ponents ents in in th the e TL TLS Ecosystem system
QUIC ECDH AES
SLIDE 16
So what is this F* thing anyway?
SLIDE 17 Two
ps of program
erificatio fication n to tool
SLIDE 18
F*: Bridging the gap
SLIDE 19
F*: Bridging the gap
SLIDE 20
F*: Bridging the gap
SLIDE 21
F*: Bridging the gap
SLIDE 22
F*: Bridging the gap
SLIDE 23
SLIDE 24
SLIDE 25
Beyond Pure Code
Effects
SLIDE 26
Beyond Pure Code
Effects
SLIDE 27
Beyond Pure Code
Effects
SLIDE 28
Beyond Pure Code
Effects
SLIDE 29
Effectful programs with Hoare-style Specifications
SLIDE 30 Effectful programs with Hoare-style Specifications
STEx > Tr
SLIDE 31 Effectful programs with Hoare-style Specifications
STExn
SLIDE 32
Exploiting Expressiveness & Extensibility
Low*: A subset of F* that compiles to C
SLIDE 33 Low* to C
And to support compilation to C, in nearly 1-1 correspondence, for auditability of our generated code Designed to allow manipulating a C-like view of memory
SLIDE 34 Low* to C
And to support compilation to C, in nearly 1-1 correspondence, for auditability of our generated code Designed to allow manipulating a C-like view of memory
SLIDE 35 Low* to C
And to support compilation to C, in nearly 1-1 correspondence, for auditability of our generated code Designed to allow manipulating a C-like view of memory
Stack allocation
SLIDE 36 Low* to C
And to support compilation to C, in nearly 1-1 correspondence, for auditability of our generated code Designed to allow manipulating a C-like view of memory
Pointer arithmetic Stack allocation
SLIDE 37 Low* to C
And to support compilation to C, in nearly 1-1 correspondence, for auditability of our generated code Designed to allow manipulating a C-like view of memory
Pointer arithmetic Stack allocation Erased specification
SLIDE 38
SLIDE 39
But SMT-based proofs can go awry
SLIDE 40
And can be at a low level of abstraction
SLIDE 41
Domain-specific languages, ad hoc proof automation, extensibility
SLIDE 42
Domain-specific languages, ad hoc proof automation, extensibility
elaborator reflection
SLIDE 43 A passive compiler pipeline
Parsing & Desugaring Typechecker Extraction aka Code generation
SLIDE 44 A passive compiler pipeline
Parsing & Desugaring Typechecker Extraction aka Code generation Higher-order Unification Normalizer SMT Encoding
SLIDE 45 Scripting components with a metaprogram
Parsing & Desugaring Typechecker Extraction aka Code generation Higher-order Unification Normalizer SMT Encoding
SLIDE 46 Scripting components with a metaprogram
Parsing & Desugaring Typechecker Extraction aka Code generation Higher-order Unification Normalizer SMT Encoding
SLIDE 47
Scripting a language implementation from within the language
SLIDE 48
From F* to Meta-F*, In three easy steps
SLIDE 49
Proof-state: A collection of typed holes
SLIDE 50 Metaprograms are proofstate transformers
- Uses an existing F* effect for non-termination: Dv
- The type of the state is an abstract type: proofstate
- error is the type of exceptions
State + Exception + Non-termination monad
SLIDE 51 Metaprogramming as a user-defined effect
- Standard definitions of return, bind, get, raise
- Exceptions reset the state
SLIDE 52
Metaprogramming as a user-defined effect
SLIDE 53 Metaprogramming as a user-defined effect
put
SLIDE 54 Step 2
Primitive operations on
Inl “Goal is not an arrow”
SLIDE 55 Step 2
Primitive operations on
Inl “Goal is not an arrow”
SLIDE 56 Step 2
Primitive operations on
Meta Inl “Goal is not an arrow”
SLIDE 57 Step 2
Primitive operations on
Meta “Goal is not an arrow”
SLIDE 58 Step 2
Primitive operations on
Meta “Goal is not an arrow” “Goal is not an arrow”
SLIDE 59 Step 3
Reflecting on syntax
SLIDE 60 Step 3
Reflecting on syntax
SLIDE 61 Step 3
Reflecting on syntax
unquot Met
SLIDE 62 Putting it together
id Type
Type Type Type
SLIDE 63 Putting it together
id Type
Type Type Type
SLIDE 64 Putting it together
id Type
Type Type
SLIDE 65 Putting it together
id Type
Type
SLIDE 66
Putting it together
id Type
SLIDE 67 And can be at a low level of abstraction
Remember this?
SLIDE 68
Metaprogramming mutually inverse parsers and formatters
SLIDE 69
Metaprogramming mutually inverse parsers and formatters
SLIDE 70 Putting it together
f assert
𝑦: 𝑜𝑏𝑢, ℎ: 𝑦 > 1 ⊢ _ ∶ (𝑦 ∗ 𝑦 > 𝑦)
SLIDE 71 SMT: Just one of F*’s tactic primitives
Meta
f assert
𝑦: 𝑜𝑏𝑢, ℎ: 𝑦 > 1 ⊢ _ ∶ (𝑦 ∗ 𝑦 > 𝑦)
SLIDE 72 But SMT-based proofs can go awry
Remember this?
SLIDE 73
SMT + T actics for more automated, robust proofs
SLIDE 74 SMT + T actics for more automated, robust proofs
- Prior manual proof required 41 steps of
explicit rewriting lemmas (!)
SLIDE 75
Language extension with native metaprograms
SLIDE 76
Language extension with native metaprograms
SLIDE 77
Language extension with native metaprograms
SLIDE 78
Language extension with native metaprograms
SLIDE 79
Some takeaways
SLIDE 80
Some takeaways
SLIDE 81
Some takeaways
improve
SLIDE 82
Some takeaways
improve
SLIDE 83 … TLS RSA SHA Network buffers Untrusted network (TCP, UDP, …)
Crypto Algorithms
Pr Proje ject t Ever erest est Ver erif ified ied Sec ecur ure e Compon ponents ents in in th the e TL TLS Ecosystem system
QUIC ECDH AES
Meta-
https://fstar-lang.github.io https://project-everest.github.io/