43
Formal Verification, Language Extensibility, and Proof automation F* and Meta-F* https://fstar-lang.github.io https://project-everest.github.io/

F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Formal Verification,Language Extensibility, andProof automation

F* and Meta-F*

https://fstar-lang.github.io

https://project-everest.github.io/

Page 2: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Classified as Microsoft Confidential

• MSR Redmond• Barry Bond

• Chris Hawblitzel

• Qunyan Magnus

• Kiran Muthabatulla

• Jonathan Protzenko

• Tahina Ramananandro

• Nikhil Swamy

• Gustavo Varo

• MSR Cambridge• Antoine Delignat-Lavaud

• Cédric Fournet

• Christoph M. Wintersteiger

• Santiago Zanella-Béguelin

• MSR India• Aseem Rastogi

• INRIA Paris• Danel Ahman

• Kenji Maillard

• Benjamin Beurdouche

• Karthikeyan Bhargavan

• Victor Dumitrescu

• Cătălin Hriţcu

• Marina Polubelova

• CMU (Pittsburgh)• 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

Page 3: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val
Page 4: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Threat model

Goal: A secure channel

connect(server,port);

send “GET…”;

data = recv();

send “POST…”;

accept(port);

request = recv();

send “<html>…”;

order = recv();

Public Key

Infrastructure

20 years of attacks & fixesBuffer overflows

Incorrect state machines

Lax certificate parsing

Weak or poorly implemented crypto

Side channels

Informal security goals

Dangerous APIs

Flawed standards

Mainstream implementationsOpenSSL, SChannel, NSS, …

Page 5: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Much discussionsIETF, Google, Mozilla, Microsoft, CDNs, cryptographers, network engineers, …

Much improvements• Modern design

• Fewer roundtrips

• Stronger security

New implementationsrequired 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

Page 6: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

TLS

RSA SHA

Network buffers

Untrusted network (TCP, UDP, …)

Crypto

Algorithms

Project Everest

Verified Secure Componentsin the TLS Ecosystem

QUICECDH AES

Page 7: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

F*: A general

purpose

programming

language

and verification

tool

kreMLinCompiler from

(a subset of)

F* to C

Verification Tools and Methodology

val nbytes 16 →u32 →nbytes len →nbytes 32 ∧ →

ST unitrequires λ → ∈ ∧ ∈ ∧ ∈ensures λ →

let inlet inmodifies ∧

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

overhead

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);

}

Page 8: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

8

Protocol specs

Protocol security proofs

Security spec

Crypto assumptions

Implementation

AES is a pseudo-random function

= Verified

= Trusted

Secure authenticated channel

Page 9: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val
Page 10: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Everest in Action, so far

Production deployments of Everest Verified Cryptography

Page 11: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

So what is this F* thing anyway?

Page 12: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Two camps of program verification tools

Page 13: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

F*: Bridging the gap

Page 14: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val
Page 15: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val
Page 16: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Beyond Pure Code

Effects

Page 17: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Effectful programs with Hoare-style Specifications

STExn

True

Page 18: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Effectful programs with Hoare-style Specifications

STExn

Page 19: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Exploiting Expressiveness & Extensibility

Low*: A subset of F* that compiles to C

Page 20: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

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

Page 21: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val
Page 22: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

But SMT-based proofs can go awry

Page 23: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

And can be at a low level of abstraction

Page 24: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Domain-specific languages, ad hoc proof automation,extensibility

Page 25: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Domain-specific languages, ad hoc proof automation,extensibility

elaborator reflection

Page 26: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

A passive compiler pipeline

Parsing &

DesugaringTypechecker

Extraction aka

Code generation

Higher-order

UnificationNormalizer SMT Encoding

Page 27: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Scripting components with a metaprogram

Parsing &

DesugaringTypechecker

Extraction aka

Code generation

Higher-order

UnificationNormalizer SMT Encoding

Page 28: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Scripting a language implementationfrom within the language

Page 29: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

From F* to Meta-F*, In three easy steps

Page 30: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Proof-state: A collection of typed holes

Page 31: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

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

Page 32: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Step 2

Primitive operations on

Meta

Inl

“Goal is not an arrow”

Page 33: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Step 3

Reflecting on syntax

unquote Meta

Page 34: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Putting it together

id Type

Type

Type

Type

Page 35: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

And can be at a low level of abstraction

Remember this?

Page 36: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Metaprogramming mutually inverse parsers and formatters

Page 37: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Putting it together

f

assert

𝑥: 𝑛𝑎𝑡, ℎ: 𝑥 > 1 ⊢ _ ∶ (𝑥 ∗ 𝑥 > 𝑥)

Page 38: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

SMT: Just one of F*’s tactic primitivesMeta

f

assert

𝑥: 𝑛𝑎𝑡, ℎ: 𝑥 > 1 ⊢ _ ∶ (𝑥 ∗ 𝑥 > 𝑥)

Page 39: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

But SMT-based proofs can go awry

Remember this?

Page 40: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

SMT + Tactics for more automated, robust proofs

• Prior manual proof required 41 steps of explicit rewriting lemmas (!)

Page 41: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Language extension with native metaprograms

Page 42: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Language extension with native metaprograms

Page 43: F* and Meta-F* · 2020-07-18 · F*: A general purpose programming language and verification tool kreMLin Compiler from (a subset of) F* to C Verification Tools and Methodology val

Some takeaways

improve