Leonardo de Moura Microsoft Research. What is SMT? Experiments: Windows kernel verification. Extending SMT solvers. Garbage collector (Singularity) verification.

Slides:



Advertisements
Similar presentations
SMELS: Sat Modulo Equality with Lazy Superposition Christopher Lynch – Clarkson Duc-Khanh Tran - MPI.
Advertisements

Quantified Invariant Generation using an Interpolating Saturation Prover Ken McMillan Cadence Research Labs TexPoint fonts used in EMF: A A A A A.
Demand-driven inference of loop invariants in a theorem prover
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Quantified Invariant Generation using an Interpolating Saturation Prover Ken McMillan Cadence Research Labs TexPoint fonts used in EMF: A A A A A.
1/17 Automated Verification of Practical Garbage Collectors Chris Hawblitzel (Microsoft Research) Erez Petrank (Technion)
Using SMT solvers for program analysis Shaz Qadeer Research in Software Engineering Microsoft Research.
Synthesis, Analysis, and Verification Lecture 04c Lectures: Viktor Kuncak VC Generation for Programs with Data Structures “Beyond Integers”
50.530: Software Engineering
CS 267: Automated Verification Lecture 8: Automata Theoretic Model Checking Instructor: Tevfik Bultan.
Satisfiability Modulo Theories (An introduction)
SMT Solvers (an extension of SAT) Kenneth Roe. Slide thanks to C. Barrett & S. A. Seshia, ICCAD 2009 Tutorial 2 Boolean Satisfiability (SAT) ⋁ ⋀ ¬ ⋁ ⋀
Introducing Formal Methods, Module 1, Version 1.1, Oct., Formal Specification and Analytical Verification L 5.
Linked List Implementation class List { private List next; private Object data; private static List root; private static int size; public static void addNew(Object.
Proofs from SAT Solvers Yeting Ge ACSys NYU Nov
Extensibility, Safety and Performance in the SPIN Operating System Presented by Allen Kerr.
Panel on Decision Procedures Panel on Decision Procedures Randal E. Bryant Lintao Zhang Nils Klarlund Harald Ruess Sergey Berezin Rajeev Joshi.
Leonardo de Moura and Nikolaj Bjørner Microsoft Research.
SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt.
Nikolaj Bjørner Microsoft Research Lecture 3. DayTopicsLab 1Overview of SMT and applications. SAT solving, Z3 Encoding combinatorial problems with Z3.
1 Predicate Abstraction of ANSI-C Programs using SAT Edmund Clarke Daniel Kroening Natalia Sharygina Karen Yorav (modified by Zaher Andraus for presentation.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA part 0 Summer School on Logic and Theorem-Proving in Programming.
Yeting Ge Leonardo de Moura New York University Microsoft Research.
ECE Synthesis & Verification1 ECE 667 Spring 2011 Synthesis and Verification of Digital Systems Verification Introduction.
CSE 311 Foundations of Computing I Lecture 6 Predicate Logic Autumn 2011 CSE 3111.
Back to the Future: Revisiting Precise Program Verification Using SMT Solvers Shuvendu Lahiri Shaz Qadeer Microsoft Research, Redmond Presented earlier.
Nikolaj Bjørner Leonardo de Moura Nikolai Tillmann Microsoft Research August 11’th 2008.
1 A propositional world Ofer Strichman School of Computer Science, Carnegie Mellon University.
1 First order theories. 2 Satisfiability The classic SAT problem: given a propositional formula , is  satisfiable ? Example:  Let x 1,x 2 be propositional.
272: Software Engineering Fall 2012 Instructor: Tevfik Bultan Lecture 4: SMT-based Bounded Model Checking of Concurrent Software.
Deciding a Combination of Theories - Decision Procedure - Changki pswlab Combination of Theories Daniel Kroening, Ofer Strichman Presented by Changki.
Leonardo de Moura Microsoft Research. Quantifiers in Satisfiability Modulo Theories Logic is “The Calculus of Computer Science” (Z. Manna). High computational.
Nikolaj Bjørner, Leonardo de Moura Microsoft Research Bruno Dutertre SRI International.
Presentation of Singularity OS Seminar, winter 2005 by Jacob Munk-Stander November 23 rd, 2005.
SAT and SMT solvers Ayrat Khalimov (based on Georg Hofferek‘s slides) AKDV 2014.
Leonardo de Moura and Nikolaj Bjørner Microsoft Research.
Advances in Automated Theorem Proving Leonardo de Moura, Nikolaj Bjørner Ken McMillan, Margus Veanes presented by Thomas Ball
Solvers for the Problem of Boolean Satisfiability (SAT) Will Klieber Aug 31, 2011 TexPoint fonts used in EMF. Read the TexPoint manual before you.
Introduction to Satisfiability Modulo Theories
Leonardo de Moura Microsoft Research. Is formula F satisfiable modulo theory T ? SMT solvers have specialized algorithms for T.
SAT & SMT. Software Verification & Testing SAT & SMT Test case generation Predicate Abstraction Verifying Compilers.
1 MVD 2010 University of Iowa New York University Comparing Proof Systems for Linear Real Arithmetic Using LFSC Andrew Reynolds September 17, 2010.
Leonardo de Moura Microsoft Research. SATTheoriesSMT Arithmetic Bit-vectors Arrays …
Leonardo de Moura Microsoft Research. Quantifiers in Satisfiability Modulo Theories Logic is “The Calculus of Computer Science” (Z. Manna). High computational.
Decision methods for arithmetic Third summer school on formal methods Leonardo de Moura Microsoft Research.
Boolean Satisfiability Present and Future
Safe to the Last Instruction: Automated Verification of a Type-Safe Operating System Jean Yang MIT CSAIL Chris Hawblitzel Microsoft Research.
Leonardo de Moura and Nikolaj Bjørner Microsoft Research.
Automated tactics for separation logic VeriML Reconstruct Z3 Proof Safe incremental type checker Certifying code transformation Proof carrying hardware.
Symbolic and Concolic Execution of Programs Information Security, CS 526 Omar Chowdhury 10/7/2015Information Security, CS 5261.
© Copyright 2008 STI INNSBRUCK Intelligent Systems Propositional Logic.
1 First order theories (Chapter 1, Sections 1.4 – 1.5) From the slides for the book “Decision procedures” by D.Kroening and O.Strichman.
Reasoning about the Behavior of Semantic Web Services with Concurrent Transaction Logic Presented By Dumitru Roman, Michael Kifer University of Innsbruk,
Leonardo de Moura Microsoft Research. Applications and Challenges in Satisfiability Modulo Theories Verification/Analysis tools need some form of Symbolic.
Theory-Aided Model Checking of Concurrent Transition Systems Guy Katz, Clark Barrett, David Harel New York University Weizmann Institute of Science.
Daniel Kroening and Ofer Strichman Decision Procedures An Algorithmic Point of View Deciding Combined Theories.
CS357 Lecture 13: Symbolic model checking without BDDs Alex Aiken David Dill 1.
Logic Engines as a Service Leonardo de Moura and Nikolaj Bjørner Microsoft Research.
1/20 Arrays Changki PSWLAB Arrays Daniel Kroening and Ofer Strichman Decision Procedure.
Finding Conflicting Instances of Quantified Formulas in SMT Andrew Reynolds Cesare Tinelli Leonardo De Moura July 18, 2014.
Selected Decision Procedures and Techniques for SMT More on combination – theories sharing sets – convex theory Un-interpreted function symbols (quantifier-free.
1 Simulating Reachability using First-Order Logic with Applications to Verification of Linked Data Structures Tal Lev-Ami 1, Neil Immerman 2, Tom Reps.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Formal Verification – Robust and Efficient Code Lecture 1
Satisfiability Modulo Theories and DPLL(T) Andrew Reynolds March 18, 2015.
Mostly-Automated Verification of Low-Level Programs in Computational Separation Logic Adam Chlipala Harvard University PLDI 2011.
Matching Logic An Alternative to Hoare/Floyd Logic
Introduction to Software Verification
Over-Approximating Boolean Programs with Unbounded Thread Creation
Presentation transcript:

Leonardo de Moura Microsoft Research

What is SMT? Experiments: Windows kernel verification. Extending SMT solvers. Garbage collector (Singularity) verification Supporting decidable fragments. Experiments in Software Verification using SMT Solvers

SATTheoriesSMT Arithmetic Bit-vectors Arrays …

Experiments in Software Verification using SMT Solvers ArithmeticArithmetic

ArithmeticArithmetic Array Theory

Experiments in Software Verification using SMT Solvers ArithmeticArithmetic Array Theory Uninterpreted Functions

Experiments in Software Verification using SMT Solvers Z3 is a new solver developed at Microsoft Research. Development/Research driven by internal customers. Free for academic research. Interfaces: Z3 TextC/C++.NETOCaml

HAVOC Verifying Windows Components Lahiri & Qadeer, POPL’08, Also: Ball, Hackett, Lahiri, Qadeer, MSR-TR

Experiments in Software Verification using SMT Solvers

Doubly linked lists in Windows Kernel code Representative shape graph in Windows Kernel component

Pointer Arithmetic q = CONTAINING_RECORD(p, IRP, link) = (IRP *) ((char*)p – (char*)(&(((IRP *)0)  link))) Transitive Closure Reach(next, u)  {u, u->next, u->next->next, …} forall (x, Reach(next,p), CONTAINING_RECORD(x, IRP, link)->state == PENDING) next prev IRP link next prev IRP link p q PENDING state PENDING state

Procedure contracts requires, ensures, modifies Arbitrary C expressions program variables, resources Boolean connectives quantifiers Can express a rich set of contracts API usage (e.g. lock acquire/release) Synchronization protocols Memory safety Data structure invariants (linked list) Challenge: Retain efficiency Decidable fragments

Logic with Reach, Quantifiers, Arithmetic Expressive Careful use of quantifiers Encoding using quantifiers and triggers

Used to check Windows Kernel code. Found 50 bugs, most confirmed. 250 lines required to specify properties. 600 lines of manual annotations lines of inferred annotations. Experiments in Software Verification using SMT Solvers Houdini-like algorithm (Flanagan, Leino) Houdini-like algorithm (Flanagan, Leino)

Axioms Inference rules (not supported yet) Very lazy loop New Z3 theory (too complicated for users) Experiments in Software Verification using SMT Solvers

Easy if theory can be encoded in first-order logic. Example: partial orders.  x: p(x,x)  x,y,z: p(x,y), p(y,z)  p(x,z)  x,y: p(x,y), p(y,x)  x = y Problems: Is E-matching or SP a decision procedure for this theory? Model extraction Efficiency Experiments in Software Verification using SMT Solvers

Some users (e.g., HAVOC) want to provide inference rules to Z3. More flexibility (e.g., side conditions) High level language for implementing custom decision procedures. Experiments in Software Verification using SMT Solvers

Adding a theory T: 1. Replace T symbols with uninterpreted symbols. 2. Invoke Z3. 3. If unsatisfiable, then return UNSAT. 4. Inspect the model + implied equalities (i.e., assigned literals and equalities). 5. Check if the assigned theory literals + equalities are satisfiable. 6. If they are, then return SAT. 7. Otherwise, add a new lemma and/or implied equalities go back to step 2. Model Based Theory Combination [SMT’08] Experiments in Software Verification using SMT Solvers

 p(a,f(c)) or  p(a, f(d)) p(a,b) p(b,f(c)) c = d  p(a,f(c)) or  p(a, f(d)) p(a,b) p(b,f(c)) c = d Model:  p(a,f(c)), p(a,b), p(b,f(c)), b = c, f(c) = f(d) Model:  p(a,f(c)), p(a,b), p(b,f(c)), b = c, f(c) = f(d) z3z3 T-Lemma:  p(a,b) or  p(b,f(c)) or p(a,f(c)) T-Lemma:  p(a,b) or  p(b,f(c)) or p(a,f(c)) unsatunsat  p(a,f(c)) or  p(a, f(d)) p(a,b) p(b,f(c)) c = d  p(a,b) or  p(b,f(c)) or p(a,f(c)  p(a,f(c)) or  p(a, f(d)) p(a,b) p(b,f(c)) c = d  p(a,b) or  p(b,f(c)) or p(a,f(c) z3z3 unsat

Verifying Garbage Collectors - Automatically and fast Chris Hawblitzel Path=%24%2fsingularity%2fbase%2fKernel%2fBartok%2fVerifiedGCs&change SetId=14518

Singularity Safe micro-kernel 95% written in C# all services and drivers in processes Software isolated processes (SIPs) all user code is verifiably safe some unsafe code in trusted runtime processes and kernel sealed at execution static verification replaces hardware protection all SIPs run in ring 0 Communication via channels channel behavior is specified and checked fast and efficient communication Working research prototype not Windows replacement shared source download

Bartok MSIL  X86 Compiler BoogiePL Procedural low-level language Contracts Verification condition generator Garbage Collectors Mark&Sweep Copying GC Verify small garbage collectors more automated than interactive provers borrow ideas from type systems for regions

safety verifier trusted computing base (minimize this!) typed x86 untrusted code compiler MSIL exception handling I/O linker, loader garbage collector MSIL: MSFT Intermediary Language

A (root) BC mark-sweepcopying fromcopying to A B C A B C abstract graph A B

safety: gc does no harm type safety gc turns well-typed heap into well-typed heap graph isomorphism concrete graph represents abstract graph effectiveness after gc, unreachable objects reclaimed termination efficiency verified not verified

A (root) BC abstract graph A B procedure GarbageCollectMs() requires MsMutatorInv(root, Color, $toAbs, $AbsMem, Mem); modifies Mem, Color, $toAbs; ensures MsMutatorInv(root, Color, $toAbs, $AbsMem, Mem); { call Mark(root); call Sweep(); } concrete graph $toAbs function MsMutatorInv(...) returns (bool) { WellFormed($toAbs) && memAddr(root) && $toAbs[root] != NO_ABS && (forall i:int::{memAddr(i)} memAddr(i) ==> ObjInv(i, $toAbs, $AbsMem, Mem)) && (forall i:int::{memAddr(i)} memAddr(i) ==> White(Color[i])) && (forall i:int::{memAddr(i)} memAddr(i) ==> ($toAbs[i]==NO_ABS Unalloc(Color[i])))} function ObjInv(...) returns (bool) { memAddr(i) && $toAbs[i] != NO_ABS ==>... $toAbs[Mem[i, field1]] != NO_ABS $toAbs[Mem[i, field1]] == $AbsMem[$toAbs[i], field1]... } function MsMutatorInv(...) returns (bool) { WellFormed($toAbs) && memAddr(root) && $toAbs[root] != NO_ABS && (forall i:int::{memAddr(i)} memAddr(i) ==> ObjInv(i, $toAbs, $AbsMem, Mem)) && (forall i:int::{memAddr(i)} memAddr(i) ==> White(Color[i])) && (forall i:int::{memAddr(i)} memAddr(i) ==> ($toAbs[i]==NO_ABS Unalloc(Color[i])))} function ObjInv(...) returns (bool) { memAddr(i) && $toAbs[i] != NO_ABS ==>... $toAbs[Mem[i, field1]] != NO_ABS $toAbs[Mem[i, field1]] == $AbsMem[$toAbs[i], field1]... } $AbsMem Mem

Idea: use marker Relativize quantifiers using marker function{:expand false} T(i:int) returns (bool) { true } function GcInv(Color:[int]int, $toAbs:[int]int, $AbsMem:[int,int]int, Mem:[int,int]int) returns (bool) { WellFormed($toAbs) && (forall i:int::{T(i)} T(i) ==> memAddr(i) ==> ObjInv(i, $toAbs, $AbsMem, Mem) && 0 <= Color[i] && Color[i] < 4 && (Black(Color[i]) ==> !White(Color[Mem[i,0]]) && !White(Color[Mem[i,1]])) && ($toAbs[i] == NO_ABS Unalloc(Color[i]))) } function GcInv(Color:[int]int, $toAbs:[int]int, $AbsMem:[int,int]int, Mem:[int,int]int) returns (bool) { WellFormed($toAbs) && (forall i:int::{T(i)} T(i) ==> memAddr(i) ==> ObjInv(i, $toAbs, $AbsMem, Mem) && 0 <= Color[i] && Color[i] < 4 && (Black(Color[i]) ==> !White(Color[Mem[i,0]]) && !White(Color[Mem[i,1]])) && ($toAbs[i] == NO_ABS Unalloc(Color[i]))) }

Insert markers to enable triggers procedure Mark(ptr:int) requires GcInv(Color, $toAbs, $AbsMem, Mem); requires memAddr(ptr) && T(ptr); requires $toAbs[ptr] != NO_ABS; modifies Color; ensures GcInv(Color, $toAbs, $AbsMem, Mem); ensures (forall i:int::{T(i)} T(i) ==> !Black(Color[i]) ==> Color[i] == old(Color)[i]); ensures !White(Color[ptr]); { if (White(Color[ptr])) { Color[ptr] := 2; // make gray call Mark(Mem[ptr,0]); call Mark(Mem[ptr,1]); Color[ptr] := 3; // make black } procedure Mark(ptr:int) requires GcInv(Color, $toAbs, $AbsMem, Mem); requires memAddr(ptr) && T(ptr); requires $toAbs[ptr] != NO_ABS; modifies Color; ensures GcInv(Color, $toAbs, $AbsMem, Mem); ensures (forall i:int::{T(i)} T(i) ==> !Black(Color[i]) ==> Color[i] == old(Color)[i]); ensures !White(Color[ptr]); { if (White(Color[ptr])) { Color[ptr] := 2; // make gray call Mark(Mem[ptr,0]); call Mark(Mem[ptr,1]); Color[ptr] := 3; // make black } Can we do better?

EPR (Effectively Propositional) Aka: Bernays–Schönfinkel class Stratified EPR Array Property Fragment Stratified Array Property Fragment Experiments in Software Verification using SMT Solvers It can be used to verify the GC properties!

Prefix  *  * + no function symbols. Examples:  x,y,z:  p(x,y) or  p(y,z) or p(x,z)  x:  p(x,a) or  q(x,b) Why is it useful? Model checking problems QBF Finite model finding Useful theories: partial orders. Experiments in Software Verification using SMT Solvers

Finite Herbrand Universe. Experiments in Software Verification using SMT Solvers  x:  p(x,a) or  q(x,b)  x: p(x,x) p(c,a) or q(c, b)  x:  p(x,a) or  q(x,b)  x: p(x,x) p(c,a) or q(c, b) Herbrand Universe {a, b, c} Herbrand Universe {a, b, c}  p(a,a) or  q(a,b)  p(b,a) or  q(b,b)  p(c,a) or  q(c,b) p(a,a) p(b,b) p(c,c) p(c,a) or q(c, b)  p(a,a) or  q(a,b)  p(b,a) or  q(b,b)  p(c,a) or  q(c,b) p(a,a) p(b,b) p(c,c) p(c,a) or q(c, b) Exponential blowup

DPLL(SX) calculus: DPLL + substitution sets (BDDs) [IJCAR’08] Experiments in Software Verification using SMT Solvers  p(a,a) or  q(a,b)  p(b,a) or  q(b,b)  p(c,a) or  q(c,b)  p(a,a) or  q(a,b)  p(b,a) or  q(b,b)  p(c,a) or  q(c,b)  x:  p(x,a) or  q(x,b)  x:  p(x1,x2) or  q(x3,x4) + {(a,a,a,b), (b,a,b,b), (c,a,c,b)} Substitution set (BDD)

Many sorted first order logic. S 1 < S 2 if there is a function f : … S 1 … → S 2 A formula is stratified if there is no sort S s.t. S < S A stratified formula has a finite Herbrand Universe. Example: Experiments in Software Verification using SMT Solvers  x S 1 : f(g(x)) = a g(b) = c where: g : S 1 → S 2 f : S 2 → S 3 a : S 3 b : S 1 c : S 2  x S 1 : f(g(x)) = a g(b) = c where: g : S 1 → S 2 f : S 2 → S 3 a : S 3 b : S 1 c : S 2 Herbrand Universe: { a, b, c, g(b), f(g(b)), f(c)} Herbrand Universe: { a, b, c, g(b), f(g(b)), f(c)}

Sort inference + restrictions Problematic example: Experiments in Software Verification using SMT Solvers  x, y: f(x) != f(y) or x = y  x: f(x) != c  x: x = a  x, y: f(x) != f(y) or x = y  x: f(x) != c  x: x = a  x S 1, y S 1 : f(x) != f(y) or x = y  x S 1 : f(x) != c  x S 3 : x = a f : S 1 → S 2 c : S 2 a : S 3  x S 1, y S 1 : f(x) != f(y) or x = y  x S 1 : f(x) != c  x S 3 : x = a f : S 1 → S 2 c : S 2 a : S 3 Cardinality Constraint

Experiments in Software Verification using SMT Solvers (forall i:int::{T(i)} T(i) ==> memAddr(i) ==> ObjInv(i, $toAbs, $AbsMem, Mem) && 0 <= Color[i] && Color[i] < 4 && (Black(Color[i]) ==> !White(Color[Mem[i,0]]) && !White(Color[Mem[i,1]])) && ($toAbs[i] == NO_ABS Unalloc(Color[i]))) (forall i:int::{T(i)} T(i) ==> memAddr(i) ==> ObjInv(i, $toAbs, $AbsMem, Mem) && 0 <= Color[i] && Color[i] < 4 && (Black(Color[i]) ==> !White(Color[Mem[i,0]]) && !White(Color[Mem[i,1]])) && ($toAbs[i] == NO_ABS Unalloc(Color[i]))) (forall i: Addr ObjInv(i, $toAbs, $AbsMem, Mem) && (color[i] = black or color[i] = white or color[i] = gray) && (Black(color[i]) ==> !White(color[Mem[i,f0]]) && !White(Color[Mem[i,f1]])) && ($toAbs[i] == NO_ABS Unalloc(Color[i]))) (forall i: Addr ObjInv(i, $toAbs, $AbsMem, Mem) && (color[i] = black or color[i] = white or color[i] = gray) && (Black(color[i]) ==> !White(color[Mem[i,f0]]) && !White(Color[Mem[i,f1]])) && ($toAbs[i] == NO_ABS Unalloc(Color[i])))

 i 1, …, i n : F[i 1, …, i n ], F is in NNF, then the following atoms can contain universal variables: i k > t (t is ground) i k > i k’ i k != t (t is ground) i k != i k’ L[a[i k ]] (i k only appears in a[i k ]) Experiments in Software Verification using SMT Solvers

Array is sorted:  i,j: i <= j implies a[i] <= a[j], or equivalently:  i,j: i > j or a[i] <= a[j] Array update b = write(a, j,v) b[j] = v  x: x > j-1 or b[x] = a[x]  x: x < j+1 or b[x] = a[x] Experiments in Software Verification using SMT Solvers Equivalent to:  x: x = j or b[x] = a[x] Equivalent to:  x: x = j or b[x] = a[x]

Yeting Ge (Intern 2008) Nested (stratified) arrays in APF. Stratified EPR + some arithmetic. Example:  i,j: i <= j implies a[a’[i]] <= a[a’[j]] It supports other extensions for pointer arithmetic. Experiments in Software Verification using SMT Solvers

Users frequently need new theories. Quantifiers. Inference rules. Very lazy loop. Decidable fragments are useful in practice. Experiments in Software Verification using SMT Solvers Thank You!

Not yet… However, PEX (comes with Z3) and Chess will be available for commercial use for VS users. SLAM/SDV 2.0 (comes with Z3) is part of DDK and will ship with the next version of Windows. Experiments in Software Verification using SMT Solvers