from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean,...

30
From Z3 to Lean, Ecient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de Moura, Microsoft Research

Transcript of from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean,...

Page 1: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

From Z3 to Lean, Efficient VerificationTuring Gateway to Mathematics, 19 July 2017

Leonardo de Moura, Microsoft Research

Page 2: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Joint work with Nikolaj Bjorner and Christoph Wintersteiger

Page 3: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Satisfiability

  

  unsat, Proof

Is execution path P feasible? Is assertion X violated?

SAGE

Is Formula F Satisfiable?

Solution/Model

Page 4: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Symbolic Reasoning Engine

Test Case Generation Verifying Compilers

Model Based TestingInvariant Generation

Type Checking Model Checking

Page 5: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Some Applications at Microsoft

HAVOCSAGE

Vigilante

Page 6: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

ImpactUsed by many research groups

Awards:

• “The most influential tool paper in the first 20 years of TACAS”(> 3500 citations) • Programming Languages Software Award from ACM SIGPLAN

Ships with many popular systems

• Isabelle, Pex, SAGE, SLAM/SDV, Visual Studio, …

Solved more than 5 billion constraints created by SAGE when checking Win8/Office

Page 7: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Logic is “the calculus of computer science” (Z. Manna)

Page 8: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Logic is “the calculus of computer science” (Z. Manna)

Yes, we cannot solve arbitrary problems from the “complexity ladder”, but …

Page 9: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Logic is “the calculus of computer science” (Z. Manna)

We can try to solve the problems we find in real applications

Page 10: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Security is critical

• Security bugs can be very expensive

• Cost of each MS security bulletin: $millions

• Cost due to worms: $billions

• Most security exploits are initiated via files or packets

• Ex: Internet browsers parse dozens of file formats

• Security testing: hunting million dollar bugs

Page 11: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Directed Automated Random Testing

SAGE (one of the most successful Z3 applications) developed by Patrice Godefroid

Page 12: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Software verification

• Specifications

• Methods contracts

• Invariants

• Field and type annotations

• Program logic: Dijkstra’s weakest precondition

• Verification condition generation

Page 13: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Software verification & automated provers

• Easy to use for simple properties

• Main problems:

• Scalability issues

• Proof stability

• in many verification projects:

• Hyper-V

• Ironclad & Ironfleet (https://github.com/Microsoft/Ironclad)

• Everest (https://project-everest.github.io/)

Page 14: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

joint work with Jeremy Avigad, Mario Carneiro, Floris van Doorn, Gabriel Ebner, Johannes Hölzl, Rob Lewis, Jared Roesch, Daniel Selsam and Sebastian Ullrich

Page 15: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Lean aims to bridge the gap between interactive and automated theorem proving

Page 16: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Lean

• New open source theorem prover (and programming language)Soonho Kong and I started coding in the Fall of 2013

• Platform for

• Software verification

• Formalized Mathematics

• Domain specific languages

• de Bruijn’s principle: small trusted kernel

• Dependent Type Theory

• Partial constructions: automation fills the "holes"

Page 17: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Inductive Families

Page 18: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Recursive equations

Page 19: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Proofs

Page 20: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Metaprogramming

• Introduced in Lean 3 (mid 2016)

• Extend Lean using Lean

• Access Lean internals using Lean• Type inference• Unifier• Simplifier• Decision procedures• Type class resolution• …

• Proof/Program synthesis

Page 21: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Metaprogramming

Page 22: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Reflecting expressions

Page 23: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

• 2200 lines of code

Superposition prover

Page 24: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

dlist

Page 25: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

transfer tactic

• Developed by Johannes Hölzl (approx. 200 lines of code)

• Q

• We also use it to transfer results from nat to int.

Page 26: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Lean to Z3

Lean

LOL

Z3

lemma n_gt_0(a : nat) : a >= 0 :=by z3

decl n : int {n >= 0}assert (not (n >= 0))

(declare-const n Int)(assert (>= n 0))(assert (not (>= n 0))

• Goal: translate a Lean local context, and goal into Z3 query.

• Recognize fragment and translate to low-order logic (LOL).

• Logic supports some higher order features, is successively lowered to FOL, finally Z3.

Page 27: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

simple expression language

Page 28: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Writing your own search strategies

Page 29: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

simple expression language

Page 30: from z3 to leanleanprover.github.io/talks/from_z3_to_lean.pdf · 2021. 2. 12. · From Z3 to Lean, Efficient Verification Turing Gateway to Mathematics, 19 July 2017 Leonardo de

Conclusion

• SMT solvers (like Z3) are very successful in bug finding tools

• Scalability and proof stability issues

• Lean aims to bring the best of automated and interactive systems

• Users can create their on automation, extend and customize Lean

• Domain specific automation

• Internal data structures and procedures are exposed to users

• Whitebox automation