Leonardo de Moura Microsoft Research. Verification/Analysis tools need some form of Symbolic Reasoning.

Slides:



Advertisements
Similar presentations
Quantified Invariant Generation using an Interpolating Saturation Prover Ken McMillan Cadence Research Labs TexPoint fonts used in EMF: A A A A A.
Advertisements

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?
Challenges in increasing tool support for programming K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 23 Sep 2004 ICTAC Guiyang, Guizhou, PRC joint.
Leonardo de Moura Microsoft Research. Z3 is a new solver developed at Microsoft Research. Development/Research driven by internal customers. Free for.
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
Semantics Static semantics Dynamic semantics attribute grammars
Satisfiability Modulo Theories (An introduction)
Abstraction and Modular Reasoning for the Verification of Software Corina Pasareanu NASA Ames Research Center.
UIUC CS 497: Section EA Lecture #2 Reasoning in Artificial Intelligence Professor: Eyal Amir Spring Semester 2004.
Software Engineering & Automated Deduction Willem Visser Stellenbosch University With Nikolaj Bjorner (Microsoft Research, Redmond) Natarajan Shankar (SRI.
Symbolic execution © Marcelo d’Amorim 2010.
Logic as the lingua franca of software verification Ken McMillan Microsoft Research TexPoint fonts used in EMF: A A A A A Joint work with Andrey Rybalchenko.
Interpolants from Z3 proofs Ken McMillan Microsoft Research TexPoint fonts used in EMF: A A A A A.
Panel on Decision Procedures Panel on Decision Procedures Randal E. Bryant Lintao Zhang Nils Klarlund Harald Ruess Sergey Berezin Rajeev Joshi.
Automatic Predicate Abstraction of C-Programs T. Ball, R. Majumdar T. Millstein, S. Rajamani.
Leonardo de Moura and Nikolaj Bjørner Microsoft Research.
An Integration of Program Analysis and Automated Theorem Proving Bill J. Ellis & Andrew Ireland School of Mathematical & Computer Sciences Heriot-Watt.
Leonardo de Moura Microsoft Research. Verification/Analysis tools need some form of Symbolic Reasoning.
Leonardo de Moura Microsoft Research. Satisfiability Modulo Theories: A Calculus of Computation Verification/Analysis tools need some form of Symbolic.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt.
Plan for today Proof-system search ( ` ) Interpretation search ( ² ) Quantifiers Equality Decision procedures Induction Cross-cutting aspectsMain search.
Johannes Kepler University Linz, Austria 2008 Leonardo de Moura and Nikolaj Bjørner Microsoft Research.
Nikolaj Bjørner Microsoft Research Lecture 3. DayTopicsLab 1Overview of SMT and applications. SAT solving, Z3 Encoding combinatorial problems with Z3.
Proof-system search ( ` ) Interpretation search ( ² ) Main search strategy DPLL Backtracking Incremental SAT Natural deduction Sequents Resolution Main.
Synergy: A New Algorithm for Property Checking
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.
Search in the semantic domain. Some definitions atomic formula: smallest formula possible (no sub- formulas) literal: atomic formula or negation of an.
Program Exploration with Pex Nikolai Tillmann, Peli de Halleux Pex
Last time Proof-system search ( ` ) Interpretation search ( ² ) Quantifiers Equality Decision procedures Induction Cross-cutting aspectsMain search strategy.
Nikolaj Bjørner Leonardo de Moura Nikolai Tillmann Microsoft Research August 11’th 2008.
Austin, Texas 2011 Theorem Proving Tools for Program Analysis SMT Solvers: Yices & Z3 Austin, Texas 2011 Nikolaj Bjørner 2, Bruno Dutertre 1, Leonardo.
272: Software Engineering Fall 2012 Instructor: Tevfik Bultan Lecture 4: SMT-based Bounded Model Checking of Concurrent Software.
Leonardo de Moura Microsoft Research. Many approaches Graph-based for difference logic: a – b  3 Fourier-Motzkin elimination: Standard Simplex General.
Nikolaj Bjørner and Leonardo de Moura Microsoft Research Microsoft Corporation McMaster University, November 28, 2007.
Leonardo de Moura Microsoft Research. Quantifiers in Satisfiability Modulo Theories Logic is “The Calculus of Computer Science” (Z. Manna). High computational.
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
Nikolaj Bjørner, Leonardo de Moura Microsoft Research Bruno Dutertre SRI International.
CMU, Oct 4 DPLL-based Checkers for Satisfiability Modulo Theories Cesare Tinelli Department of Computer Science The University of Iowa Joint work with.
SAT and SMT solvers Ayrat Khalimov (based on Georg Hofferek‘s slides) AKDV 2014.
Leonardo de Moura and Nikolaj Bjørner Microsoft Research.
Introduction to Satisfiability Modulo Theories
Leonardo de Moura Microsoft Research. Satisfiability Modulo Theories: An Appetizer Verification/Analysis tools need some form of Symbolic Reasoning.
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.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Leonardo de Moura Microsoft Research. SATTheoriesSMT Arithmetic Bit-vectors Arrays …
Lazy Annotation for Program Testing and Verification Speaker: Chen-Hsuan Adonis Lin Advisor: Jie-Hong Roland Jiang November 26,
Analyzing relational logic Daniel Jackson, MIT WG 2.3 · Newcastle April 2000.
Explorations in Artificial Intelligence Prof. Carla P. Gomes Module Logic Representations.
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
Leonardo de Moura and Nikolaj Bjørner Microsoft Research.
Lecture 5 1 CSP tools for verification of Sec Prot Overview of the lecture The Casper interface Refinement checking and FDR Model checking Theorem proving.
Symbolic and Concolic Execution of Programs Information Security, CS 526 Omar Chowdhury 10/7/2015Information Security, CS 5261.
Nikolaj Bjørner Microsoft Research DTU Winter course January 2 nd 2012 Organized by Flemming Nielson & Hanne Riis Nielson.
Random Interpretation Sumit Gulwani UC-Berkeley. 1 Program Analysis Applications in all aspects of software development, e.g. Program correctness Compiler.
Leonardo de Moura Microsoft Research. Applications and Challenges in Satisfiability Modulo Theories Verification/Analysis tools need some form of Symbolic.
Logic Engines as a Service Leonardo de Moura and Nikolaj Bjørner Microsoft Research.
Daniel Kroening and Ofer Strichman 1 Decision Procedures An Algorithmic Point of View Basic Concepts and Background.
Selected Decision Procedures and Techniques for SMT More on combination – theories sharing sets – convex theory Un-interpreted function symbols (quantifier-free.
Knowledge Repn. & Reasoning Lecture #9: Propositional Logic UIUC CS 498: Section EA Professor: Eyal Amir Fall Semester 2005.
Formal Verification – Robust and Efficient Code Lecture 1
Solving Linear Arithmetic with SAT-based MC
Lecture 5 Floyd-Hoare Style Verification
Presentation transcript:

Leonardo de Moura Microsoft Research

Verification/Analysis tools need some form of Symbolic Reasoning

Logic is “The Calculus of Computer Science” (Z. Manna). High computational complexity

Test case generationVerifying CompilersPredicate Abstraction Invariant Generation Type Checking Model Based Testing

VCC Hyper-V Terminator T-2 NModel HAVOC F7 SAGE Vigilante SpecExplorer

unsigned GCD(x, y) { requires(y > 0); while (true) { unsigned m = x % y; if (m == 0) return y; x = y; y = m; } We want a trace where the loop is executed twice. (y 0 > 0) and (m 0 = x 0 % y 0 ) and not (m 0 = 0) and (x 1 = y 0 ) and (y 1 = m 0 ) and (m 1 = x 1 % y 1 ) and (m 1 = 0) SolverSolver x 0 = 2 y 0 = 4 m 0 = 2 x 1 = 4 y 1 = 2 m 1 = 0 SSASSA

Signature: div : int, { x : int | x  0 }  int Subtype Call site: if a  1 and a  b then return div(a, b) Verification condition a  1 and a  b implies b  0

Is formula F satisfiable modulo theory T ? SMT solvers have specialized algorithms for T

b + 2 = c and f(read(write(a,b,3), c-2) ≠ f(c-b+1)

ArithmeticArithmetic b + 2 = c and f(read(write(a,b,3), c-2) ≠ f(c-b+1)

ArithmeticArithmetic Array Theory b + 2 = c and f(read(write(a,b,3), c-2) ≠ f(c-b+1)

ArithmeticArithmetic Array Theory Uninterpreted Functions b + 2 = c and f(read(write(a,b,3), c-2) ≠ f(c-b+1)

Z3 is a new solver developed at Microsoft Research. Development/Research driven by internal customers. Free for academic research. Interfaces: Z3 TextC/C++.NETOCaml

For most SMT solvers: F is a set of ground formulas Many Applications Bounded Model Checking Test-Case Generation

An SMT Solver is a collection of Little Engines of Proof

a = b, b = c, d = e, b = s, d = t, a  e, a  s a a b b c c d d e e s s t t

a = b, b = c, d = e, b = s, d = t, a  e, a  s a a b b c c d d e e s s t t a,b

a = b, b = c, d = e, b = s, d = t, a  e, a  s c c d d e e s s t t a,b a,b,c

d,e a = b, b = c, d = e, b = s, d = t, a  e, a  s d d e e s s t t a,b,c

a,b,c,s a = b, b = c, d = e, b = s, d = t, a  e, a  s s s t t a,b,c d,e

a = b, b = c, d = e, b = s, d = t, a  e, a  s t t d,e a,b,c,s d,e,t

a = b, b = c, d = e, b = s, d = t, a  e, a  s a,b,c,s d,e,t

a = b, b = c, d = e, b = s, d = t, a  e, a  s a,b,c,s d,e,t Unsatisfiable

a = b, b = c, d = e, b = s, d = t, a  e a,b,c,s d,e,t Model |M| = { 0, 1 } M(a) = M(b) = M(c) = M(s) = 0 M(d) = M(e) = M(t) = 1

a = b, b = c, d = e, b = s, d = t, f(a, g(d))  f(b, g(e)) a,b,c,s d,e,t g(d) f(a,g(d)) g(e) f(b,g(e)) Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n )

a = b, b = c, d = e, b = s, d = t, f(a, g(d))  f(b, g(e)) a,b,c,s d,e,t g(d) f(a,g(d)) g(e) f(b,g(e)) Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n ) g(d),g(e)

a = b, b = c, d = e, b = s, d = t, f(a, g(d))  f(b, g(e)) a,b,c,s d,e,t f(a,g(d)) f(b,g(e)) Congruence Rule: x 1 = y 1, …, x n = y n implies f(x 1, …, x n ) = f(y 1, …, y n ) g(d),g(e) f(a,g(d)),f(b,g(e))

a = b, b = c, d = e, b = s, d = t, f(a, g(d))  f(b, g(e)) a,b,c,s d,e,t g(d),g(e) f(a,g(d)),f(b,g(e)) Unsatisfiable

(fully shared) DAGs for representing terms Union-find data-structure + Congruence Closure O(n log n)

In practice, we need a combination of theory solvers. Nelson-Oppen combination method. Reduction techniques. Model-based theory combination.

p  q, p   q,  p  q,  p   q

p  q, p   q,  p  q,  p   q Assignment: p = false, q = false

p  q, p   q,  p  q,  p   q Assignment: p = false, q = true

p  q, p   q,  p  q,  p   q Assignment: p = true, q = false

p  q, p   q,  p  q,  p   q Assignment: p = true, q = true

M | F Partial model Set of clauses

Guessing p,  q | p  q,  q  r p | p  q,  q  r

Deducing p, s| p  q,  p  s p | p  q,  p  s

Backtracking p, s| p  q, s  q,  p   q p,  s, q | p  q, s  q,  p   q

Efficient indexing (two-watch literal) Non-chronological backtracking (backjumping) Lemma learning …

Efficient decision procedures for conjunctions of ground literals. a=b, a 10

a=b, a > 0, c > 0, a + c < 0 | F backtrack

SMT Solver = DPLL + Decision Procedure Standard question: Why don’t you use CPLEX for handling linear arithmetic? Standard question: Why don’t you use CPLEX for handling linear arithmetic?

Decision Procedures must be: Incremental & Backtracking Theory Propagation a=b, a<5 | … a<6  f(a) = a a=b, a<5, a<6 | … a<6  f(a) = a

Decision Procedures must be: Incremental & Backtracking Theory Propagation Precise (theory) lemma learning a=b, a > 0, c > 0, a + c < 0 | F Learn clause:  (a=b)   (a > 0)   (c > 0)   (a + c < 0) Imprecise! Precise clause:  a > 0   c > 0   a + c < 0

For some theories, SMT can be reduced to SAT bvmul 32 (a,b) = bvmul 32 (b,a) Higher level of abstraction

F  TF  T First-order Theorem Prover T may not have a finite axiomatization

Z3 Test case generation Verifying Compiler Predicate Abstraction

Z3 Test case generation Verifying Compiler Predicate Abstraction

Test (correctness + usability) is 95% of the deal: Dev/Test is 1-1 in products. Developers are responsible for unit tests. Tools: Annotations and static analysis (SAL + ESP) File Fuzzing Unit test case generation

Security is critical Security bugs can be very expensive: Cost of each MS Security Bulletin: $600k to $Millions. Cost due to worms: $Billions. The real victim is the customer. Most security exploits are initiated via files or packets. Ex: Internet Explorer parses dozens of file formats. Security testing: hunting for million dollar bugs Write A/V Read A/V Null pointer dereference Division by zero

Two main techniques used by “black hats”: Code inspection (of binaries). Black box fuzz testing. Black box fuzz testing: A form of black box random testing. Randomly fuzz (=modify) a well formed input. Grammar-based fuzzing: rules to encode how to fuzz. Heavily used in security testing At MS: several internal tools. Conceptually simple yet effective in practice

Execution Path Run Test and Monitor Path Condition Solve seed New input Test Inputs Constraint System Known Paths

PEX Implements DART for.NET. SAGE Implements DART for x86 binaries. YOGI Implements DART to check the feasibility of program paths generated statically using a SLAM-like tool. Vigilante Partially implements DART to dynamically generate worm filters.

Test input generator Pex starts from parameterized unit tests Generated tests are emitted as traditional unit tests

class ArrayList { object[] items; int count; ArrayList(int capacity) { if (capacity < 0) throw...; items = new object[capacity]; } void Add(object item) { if (count == items.Length) ResizeArray(); items[this.count++] = item; }... class ArrayListTest { [PexMethod] void AddItem(int c, object item) { var list = new ArrayList(c); list.Add(item); Assert(list[0] == item); } }

class ArrayList { object[] items; int count; ArrayList(int capacity) { if (capacity < 0) throw...; items = new object[capacity]; } void Add(object item) { if (count == items.Length) ResizeArray(); items[this.count++] = item; }... class ArrayListTest { [PexMethod] void AddItem(int c, object item) { var list = new ArrayList(c); list.Add(item); Assert(list[0] == item); } } Inputs

(0,null) class ArrayList { object[] items; int count; ArrayList(int capacity) { if (capacity < 0) throw...; items = new object[capacity]; } void Add(object item) { if (count == items.Length) ResizeArray(); items[this.count++] = item; }... class ArrayListTest { [PexMethod] void AddItem(int c, object item) { var list = new ArrayList(c); list.Add(item); Assert(list[0] == item); } }

InputsObserved Constraints (0,null)!(c<0) class ArrayList { object[] items; int count; ArrayList(int capacity) { if (capacity < 0) throw...; items = new object[capacity]; } void Add(object item) { if (count == items.Length) ResizeArray(); items[this.count++] = item; }... class ArrayListTest { [PexMethod] void AddItem(int c, object item) { var list = new ArrayList(c); list.Add(item); Assert(list[0] == item); } } c < 0  false

InputsObserved Constraints (0,null)!(c<0) && 0==c class ArrayList { object[] items; int count; ArrayList(int capacity) { if (capacity < 0) throw...; items = new object[capacity]; } void Add(object item) { if (count == items.Length) ResizeArray(); items[this.count++] = item; }... class ArrayListTest { [PexMethod] void AddItem(int c, object item) { var list = new ArrayList(c); list.Add(item); Assert(list[0] == item); } } 0 == c  true

InputsObserved Constraints (0,null)!(c<0) && 0==c class ArrayList { object[] items; int count; ArrayList(int capacity) { if (capacity < 0) throw...; items = new object[capacity]; } void Add(object item) { if (count == items.Length) ResizeArray(); items[this.count++] = item; }... class ArrayListTest { [PexMethod] void AddItem(int c, object item) { var list = new ArrayList(c); list.Add(item); Assert(list[0] == item); } } item == item  true This is a tautology, i.e. a constraint that is always true, regardless of the chosen values. We can ignore such constraints.

Constraints to solve InputsObserved Constraints (0,null)!(c<0) && 0==c !(c<0) && 0!=c class ArrayList { object[] items; int count; ArrayList(int capacity) { if (capacity < 0) throw...; items = new object[capacity]; } void Add(object item) { if (count == items.Length) ResizeArray(); items[this.count++] = item; }... class ArrayListTest { [PexMethod] void AddItem(int c, object item) { var list = new ArrayList(c); list.Add(item); Assert(list[0] == item); } }

Constraints to solve InputsObserved Constraints (0,null)!(c<0) && 0==c !(c<0) && 0!=c(1,null) class ArrayList { object[] items; int count; ArrayList(int capacity) { if (capacity < 0) throw...; items = new object[capacity]; } void Add(object item) { if (count == items.Length) ResizeArray(); items[this.count++] = item; }... class ArrayListTest { [PexMethod] void AddItem(int c, object item) { var list = new ArrayList(c); list.Add(item); Assert(list[0] == item); } }

Constraints to solve InputsObserved Constraints (0,null)!(c<0) && 0==c !(c<0) && 0!=c(1,null)!(c<0) && 0!=c class ArrayList { object[] items; int count; ArrayList(int capacity) { if (capacity < 0) throw...; items = new object[capacity]; } void Add(object item) { if (count == items.Length) ResizeArray(); items[this.count++] = item; }... class ArrayListTest { [PexMethod] void AddItem(int c, object item) { var list = new ArrayList(c); list.Add(item); Assert(list[0] == item); } } 0 == c  false

Constraints to solve InputsObserved Constraints (0,null)!(c<0) && 0==c !(c<0) && 0!=c(1,null)!(c<0) && 0!=c c<0 class ArrayList { object[] items; int count; ArrayList(int capacity) { if (capacity < 0) throw...; items = new object[capacity]; } void Add(object item) { if (count == items.Length) ResizeArray(); items[this.count++] = item; }... class ArrayListTest { [PexMethod] void AddItem(int c, object item) { var list = new ArrayList(c); list.Add(item); Assert(list[0] == item); } }

Constraints to solve InputsObserved Constraints (0,null)!(c<0) && 0==c !(c<0) && 0!=c(1,null)!(c<0) && 0!=c c<0(-1,null) class ArrayList { object[] items; int count; ArrayList(int capacity) { if (capacity < 0) throw...; items = new object[capacity]; } void Add(object item) { if (count == items.Length) ResizeArray(); items[this.count++] = item; }... class ArrayListTest { [PexMethod] void AddItem(int c, object item) { var list = new ArrayList(c); list.Add(item); Assert(list[0] == item); } }

Constraints to solve InputsObserved Constraints (0,null)!(c<0) && 0==c !(c<0) && 0!=c(1,null)!(c<0) && 0!=c c<0(-1,null)c<0 class ArrayList { object[] items; int count; ArrayList(int capacity) { if (capacity < 0) throw...; items = new object[capacity]; } void Add(object item) { if (count == items.Length) ResizeArray(); items[this.count++] = item; }... class ArrayListTest { [PexMethod] void AddItem(int c, object item) { var list = new ArrayList(c); list.Add(item); Assert(list[0] == item); } } c < 0  true

Constraints to solve InputsObserved Constraints (0,null)!(c<0) && 0==c !(c<0) && 0!=c(1,null)!(c<0) && 0!=c c<0(-1,null)c<0 class ArrayList { object[] items; int count; ArrayList(int capacity) { if (capacity < 0) throw...; items = new object[capacity]; } void Add(object item) { if (count == items.Length) ResizeArray(); items[this.count++] = item; }... class ArrayListTest { [PexMethod] void AddItem(int c, object item) { var list = new ArrayList(c); list.Add(item); Assert(list[0] == item); } }

Rich Combination Linear arithmetic BitvectorArrays Free Functions Models Model used as test inputs  -Quantifier Used to model custom theories (e.g.,.NET type system) API Huge number of small problems. Textual interface is too inefficient.

Pex “sends” several similar formulas to Z3. Plus: backtracking primitives in the Z3 API. push pop Reuse (some) lemmas.

Given a set of constraints C, find a model M that minimizes the interpretation for x 0, …, x n. In the ArrayList example: Why is the model where c = less desirable than the model with c = 1? !(c<0) && 0!=c Simple solution: Assert C while satisfiable Peek x i such that M[x i ] is big Assert x i < n, where n is a small constant Return last found model

Given a set of constraints C, find a model M that minimizes the interpretation for x 0, …, x n. In the ArrayList example: Why is the model where c = less desirable than the model with c = 1? !(c<0) && 0!=c Refinement: Eager solution stops as soon as the system becomes unsatisfiable. A “bad” choice (peek x i ) may prevent us from finding a good solution. Use push and pop to retract “bad” choices.

Apply DART to large applications (not units). Start with well-formed input (not random). Combine with generational search (not DFS). Negate 1-by-1 each constraint in a path constraint. Generate many children for each parent run. parent generation 1

Starting with 100 zero bytes … SAGE generates a crashing test for Media1 parser h: ; h: ; h: ; h: ; h: ; h: ; h: ;.... Generation 0 – seed file

Starting with 100 zero bytes … SAGE generates a crashing test for Media1 parser h: ; RIFF h: ; h: ; h: ; h: ; h: ; h: ;.... Generation 1

` Starting with 100 zero bytes … SAGE generates a crashing test for Media1 parser h: ** ** ** ; RIFF....*** h: ; h: ; h: ; h: ; h: ; h: ;.... Generation 2

Starting with 100 zero bytes … SAGE generates a crashing test for Media1 parser h: D ** ** ** ; RIFF=...*** h: ; h: ; h: ; h: ; h: ; h: ;.... Generation 3

Starting with 100 zero bytes … SAGE generates a crashing test for Media1 parser h: D ** ** ** ; RIFF=...*** h: ; h: ; h: ;....strh h: ; h: ; h: ;.... Generation 4

Starting with 100 zero bytes … SAGE generates a crashing test for Media1 parser h: D ** ** ** ; RIFF=...*** h: ; h: ; h: ;....strh....vids h: ; h: ; h: ;.... Generation 5

Starting with 100 zero bytes … SAGE generates a crashing test for Media1 parser h: D ** ** ** ; RIFF=...*** h: ; h: ; h: ;....strh....vids h: ;....strf h: ; h: ;.... Generation 6

Starting with 100 zero bytes … SAGE generates a crashing test for Media1 parser h: D ** ** ** ; RIFF=...*** h: ; h: ; h: ;....strh....vids h: ;....strf....( h: ; h: ;.... Generation 7

Starting with 100 zero bytes … SAGE generates a crashing test for Media1 parser h: D ** ** ** ; RIFF=...*** h: ; h: ; h: ;....strh....vids h: ;....strf....( h: C9 9D E4 4E ; ɝäN h: ;.... Generation 8

Starting with 100 zero bytes … SAGE generates a crashing test for Media1 parser h: D ** ** ** ; RIFF=...*** h: ; h: ; h: ;....strh....vids h: ;....strf....( h: ; h: ;.... Generation 9

Starting with 100 zero bytes … SAGE generates a crashing test for Media1 parser h: D ** ** ** ; RIFF=...*** h: ; h: ; h: ;....strh....vids h: B A ;....strf²uv:( h: ; h: ;.... Generation 10 – CRASH

SAGE is very effective at finding bugs. Works on large applications. Fully automated Easy to deploy (x86 analysis – any language) Used in various groups inside Microsoft Powered by Z3.

Formulas are usually big conjunctions. SAGE uses only the bitvector and array theories. Pre-processing step has a huge performance impact. Eliminate variables. Simplify formulas. Early unsat detection.

Z3 Test case generation Verifying Compiler Predicate Abstraction

Source Language C# + goodies = Spec# Specifications method contracts, invariants, field and type annotations. Program Logic: Dijkstra’s weakest preconditions. Automatic Verification type checking, verification condition generation (VCG), automatic theorem proving Z3 Spec# (annotated C#) Boogie PL Spec# Compiler VC Generator Formulas Z3

V V Static program verifier (Boogie) MSIL Z3 V.C. generator Verification condition “correct” or list of errors Spec# compiler Spec# C Bytecode translator C Boogie VCC HAVOC

A tool for specifying and checking properties of systems software written in C. It also translates annotated C into Boogie PL. It allows the expression of richer properties about the program heap and data structures such as linked lists and arrays. HAVOC is being used to specify and check: Complex locking protocols over heap-allocated data structures in Windows. Properties of collections such as IRP queues in device drivers. Correctness properties of custom storage allocators.

VCC translates an annotated C program into a Boogie PL program. A C-ish memory model Abstract heaps Bit-level precision Microsoft Hypervisor: verification grand challenge.

Meta OS: small layer of software between hardware and OS Mini: 60K lines of non-trivial concurrent systems C code Critical: must provide functional resource abstraction Trusted: a verification grand challenge Hardware Hypervisor

VCs have several Mb Thousands of non ground clauses Developers are willing to wait at most 5 min per VC

Quantifiers, quantifiers, quantifiers, … Modeling the runtime  h,o,f: IsHeap(h)  o ≠ null  read(h, o, alloc) = t  read(h,o, f) = null  read(h, read(h,o,f),alloc) = t

Quantifiers, quantifiers, quantifiers, … Modeling the runtime Frame axioms  o, f: o ≠ null  read(h 0, o, alloc) = t  read(h 1,o,f) = read(h 0,o,f)  (o,f)  M

Quantifiers, quantifiers, quantifiers, … Modeling the runtime Frame axioms User provided assertions  i,j: i  j  read(a,i)  read(b,j)

Quantifiers, quantifiers, quantifiers, … Modeling the runtime Frame axioms User provided assertions Theories  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

Quantifiers, quantifiers, quantifiers, … Modeling the runtime Frame axioms User provided assertions Theories Solver must be fast in satisfiable instances. We want to find bugs!

There is no sound and refutationally complete procedure for linear integer arithmetic + free function symbols

Heuristic quantifier instantiationCombining SMT with Saturation proversComplete quantifier instantiationDecidable fragmentsModel based quantifier instantiation

Is the axiomatization of the runtime consistent? False implies everything Partial solution: SMT + Saturation Provers Found many bugs using this approach

Standard complain “I made a small modification in my Spec, and Z3 is timingout” This also happens with SAT solvers (NP-complete) In our case, the problems are undecidable Partial solution: parallelization

Joint work with Y. Hamadi (MSRC) and C. Wintersteiger Multi-core & Multi-node (HPC) Different strategies in parallel Collaborate exchanging lemmas Strategy 1 Strategy 2 Strategy 3 Strategy 4 Strategy 5

Z3 Test case generation Verifying Compiler Predicate Abstraction

SLAM/SDV is a software model checker. Application domain: device drivers. Architecture: c2bp C program → boolean program (predicate abstraction). bebop Model checker for boolean programs. newton Model refinement (check for path feasibility) SMT solvers are used to perform predicate abstraction and to check path feasibility. c2bp makes several calls to the SMT solver. The formulas are relatively small.

Given a C program P and F = {p 1, …, p n }. Produce a Boolean program B(P, F) Same control flow structure as P. Boolean variables {b 1, …, b n } to match {p 1, …, p n }. Properties true in B(P, F) are true in P. Each p i is a pure Boolean expression. Each p i represents set of states for which p i is true. Performs modular abstraction.

Implies F (e) Best Boolean function over F that implies e. ImpliedBy F (e) Best Boolean function over F that is implied by e. ImpliedBy F (e) = not Implies F (not e)

minterm m = l 1 ∧... ∧ l n, where l i = p i, or l i = not p i. Implies F (e): disjunction of all minterms that imply e. Naive approach Generate all 2 n possible minterms. For each minterm m, use SMT solver to check validity of m ⇒ e. Many possible optimizations

F = { x < y, x = 2} e : y > 1 Minterms over F !x 1 x 1 !x 1 x 1 Implies F (y>1) = x<y  x=2 Implies F (y>1) = b 1  b 2

Given an error path p in the Boolean program B. Is p a feasible path of the corresponding C program? Yes: found a bug. No: find predicates that explain the infeasibility. Execute path symbolically. Check conditions for inconsistency using Z3.

All-SAT Better (more precise) Predicate Abstraction Unsatisfiable cores Why the abstract path is not feasible? Fast Predicate Abstraction

Let S be an unsatisfiable set of formulas. S’  S is an unsatisfiable core of S if: S’ is also unsatisfiable, and There is not S’’  S’ that is also unsatisfiable. Computing Implies F (e) with F = {p 1, p 2, p 3, p 4 } Assume p 1, p 2, p 3, p 4  e is valid That is p 1, p 2, p 3, p 4,  e is unsat Now assume p 1, p 3,  e is the unsatisfiable core Then it is unnecessary to check: p 1,  p 2, p 3, p 4  e p 1,  p 2, p 3,  p 4  e p 1, p 2, p 3,  p 4  e

Model programs (M. Veanes – MSRR) Termination (B. Cook – MSRC) Security protocols (A. Gordon and C. Fournet - MSRC) Business Application Modeling (E. Jackson - MSRR) Cryptography (R. Venki – MSRR) Verifying Garbage Collectors (C. Hawblitzel – MSRR) Model Based Testing (L. Bruck – SQL) Semantic type checking for D models (G. Bierman – MSRC) More coming soon…

SMT is hot at Microsoft. Many applications. Z3 is a new and very efficient SMT solver. Thank You!