Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of...

115
SMT@Microsoft Midwest Verification Day, Iowa, 2009 Leonardo de Moura Microsoft Research

Transcript of Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of...

Page 1: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

SMT@MicrosoftMidwest Verification Day, Iowa, 2009

Leonardo de MouraMicrosoft Research

Page 2: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Symbolic Reasoning

SMT@Microsoft

Verification/Analysis tools need some form of

Symbolic Reasoning

Page 3: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Symbolic Reasoning

PSpace-complete(QBF)

Semi-decidable(First-order logic)

NP-complete(Propositional logic)

NEXPTime-complete(EPR)

P-time(Equality)

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

SMT@Microsoft

Undecidable(FOL + LA)

Page 4: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Applications

SMT@Microsoft

Test case generation

Verifying Compilers

Predicate Abstraction

Invariant Generation

Type Checking

Model Based Testing

Page 5: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Some Applications @ Microsoft

VCC

Hyper-VTerminator T-2

NModel

HAVOC

F7SAGE

VigilanteSpecExplorer

SMT@Microsoft

Page 6: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Test case generation

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.

(y0 > 0) and

(m0 = x0 % y0) and

not (m0 = 0) and

(x1 = y0) and

(y1 = m0) and

(m1 = x1 % y1) and

(m1 = 0)

Solver

x0 = 2

y0 = 4

m0 = 2

x1 = 4

y1 = 2

m1 = 0

SSA

SMT@Microsoft

Page 7: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Type checking

Signature:div : int, { x : int | x 0 } int

SMT@Microsoft

SubtypeCall site:if a 1 and a b then

return div(a, b)

Verification conditiona 1 and a b implies b 0

Page 8: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Satisfiability Modulo Theories (SMT)

SMT@Microsoft

Is formula F satisfiable modulo theory T ?

SMT solvers have specialized algorithms for

T

Page 9: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Satisfiability Modulo Theories (SMT)

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

SMT@Microsoft

Page 10: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Satisfiability Modulo Theories (SMT)

Arithmetic

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

SMT@Microsoft

Page 11: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Satisfiability Modulo Theories (SMT)

ArithmeticArray Theory

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

SMT@Microsoft

Page 12: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Satisfiability Modulo Theories (SMT)

ArithmeticArray TheoryUninterpreted

Functions

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

SMT@Microsoft

Page 13: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

SMT@Microsoft: Solver

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

http://research.microsoft.com/projects/z3

Z3

TextC/C++.NET

OCaml

SMT@Microsoft

Page 14: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Ground formulas

For most SMT solvers: F is a set of ground formulas

Many ApplicationsBounded Model Checking

Test-Case Generation

SMT@Microsoft

Page 15: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Little Engines of Proof

An SMT Solver is a collection ofLittle Engines of Proof

SMT@Microsoft

Page 16: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Deciding Equality

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

SMT@Microsoft

a b c d e s t

Page 17: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Deciding Equality

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

SMT@Microsoft

a b c d e s ta,b

Page 18: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Deciding Equality

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

SMT@Microsoft

c d e s ta,ba,b,

c

Page 19: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

d,e

Deciding Equality

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

SMT@Microsoft

d e s ta,b,c

Page 20: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

a,b,c,s

Deciding Equality

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

SMT@Microsoft

s ta,b,c

d,e

Page 21: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Deciding Equality

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

SMT@Microsoft

td,ea,b,c,s

d,e,t

Page 22: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Deciding Equality

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

SMT@Microsoft

a,b,c,s

d,e,t

Page 23: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Deciding Equality

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

SMT@Microsoft

a,b,c,s

d,e,t

Unsatisfiable

Page 24: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Deciding Equality

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

SMT@Microsoft

a,b,c,s

d,e,t

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

Page 25: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Deciding Equality + (uninterpreted) Functions

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

SMT@Microsoft

a,b,c,s

d,e,t

g(d)

f(a,g(d))

g(e)

f(b,g(e))

Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)

Page 26: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Deciding Equality + (uninterpreted) Functions

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

SMT@Microsoft

a,b,c,s

d,e,t

g(d)

f(a,g(d))

g(e)

f(b,g(e))

Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)

g(d),g(e)

Page 27: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Deciding Equality + (uninterpreted) Functions

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

SMT@Microsoft

a,b,c,s

d,e,t

f(a,g(d))

f(b,g(e))

Congruence Rule:x1 = y1, …, xn = yn implies f(x1, …, xn) = f(y1, …, yn)

g(d),g(e)

f(a,g(d)),f(b,g(e))

Page 28: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Deciding Equality + (uninterpreted) Functions

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

SMT@Microsoft

a,b,c,s

d,e,t

g(d),g(e)

f(a,g(d)),f(b,g(e))

Unsatisfiable

Page 29: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Deciding Equality + (uninterpreted) Functions

(fully shared) DAGs for representing termsUnion-find data-structure + Congruence Closure

O(n log n)

SMT@Microsoft

Page 30: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Combining Solvers

In practice, we need a combination of theory solvers.

Nelson-Oppen combination method.Reduction techniques.

Model-based theory combination.

SMT@Microsoft

Page 31: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

SAT (propositional checkers): Case Analysis

SMT@Microsoft

p q, p q,p q,p q

Page 32: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

SAT (propositional checkers):Case Analysis

SMT@Microsoft

p q, p q,p q,p q

Assignment:p = false,q = false

Page 33: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

SAT (propositional checkers): Case Analysis

SMT@Microsoft

p q, p q,p q,p q

Assignment:p = false,q = true

Page 34: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

SAT (propositional checkers):Case Analysis

SMT@Microsoft

p q, p q,p q,p q

Assignment:p = true,q = false

Page 35: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

SAT (propositional checkers): Case Analysis

SMT@Microsoft

p q, p q,p q,p q

Assignment:p = true,q = true

Page 36: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

DPLL

M | F

SMT@Microsoft

Partial model Set of clauses

Page 37: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

DPLL

Guessing

SMT@Microsoft

p, q | p q, q r

p | p q, q r

Page 38: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

DPLL

Deducing

SMT@Microsoft

p, s| p q, p s

p | p q, p s

Page 39: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

DPLL

Backtracking

SMT@Microsoft

p, s| p q, s q, p q

p, s, q | p q, s q, p q

Page 40: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Modern DPLL

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

SMT@Microsoft

Page 41: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Solvers = DPLL + Decision Procedures

Efficient decision procedures for conjunctions of ground literals.

a=b, a<5 | a=b f(a)=f(b), a < 5 a > 10

SMT@Microsoft

Page 42: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Theory Conflicts

SMT@Microsoft

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

backtrack

Page 43: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Naïve recipe?

SMT@Microsoft

SMT Solver = DPLL + Decision Procedure

Standard question:

Why don’t you use CPLEX for handling linear arithmetic?

Page 44: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Efficient SMT solvers

SMT@Microsoft

Decision Procedures must be:Incremental & BacktrackingTheory Propagation

a=b, a<5 | … a<6 f(a) = a

a=b, a<5, a<6 | … a<6 f(a) = a

Page 45: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Efficient SMT solvers

SMT@Microsoft

Decision Procedures must be:Incremental & BacktrackingTheory PropagationPrecise (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

Page 46: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

SMT x SAT

For some theories, SMT can be reduced to SAT

bvmul32(a,b) = bvmul32 (b,a)

Higher level of abstraction

SMT@Microsoft

Page 47: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

SMT x First-order provers

F T

First-order Theor

em Prove

rT may not have a finite axiomatization

SMT@Microsoft

Page 48: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

SMT: Some Applications

SMT@Microsoft

Z3

Test case generation

Verifying CompilerPredicate

Abstraction

Page 49: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

SMT: Some Applications

SMT@Microsoft

Z3

Test case generation

Verifying CompilerPredicate

Abstraction

Page 50: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Test-case generation

SMT@Microsoft

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 FuzzingUnit test case generation

Page 51: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Security is critical

SMT@Microsoft

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 bugsWrite A/VRead A/VNull pointer dereferenceDivision by zero

Page 52: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Hunting for Security Bugs.

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 testingAt MS: several internal tools.Conceptually simple yet effective in practice

SMT@Microsoft

Page 53: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Directed Automated Random Testing ( DART)

SMT@Microsoft

Execution Path

Run Test and Monitor Path Condition

Solve

seed

New input

TestInputs

Constraint System

KnownPaths

Page 54: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

DARTish projects at Microsoft

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.

SMT@Microsoft

Page 55: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

What is Pex?

Test input generatorPex starts from parameterized unit testsGenerated tests are emitted as traditional unit tests

SMT@Microsoft

Page 56: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

ArrayList: The Spec

SMT@Microsoft

Page 57: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

ArrayList: AddItem Test

SMT@Microsoft

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

Page 58: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

ArrayList: Starting Pex…

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

Page 59: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

ArrayList: Run 1, (0,null)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); }}

Page 60: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

ArrayList: Run 1, (0,null)Inputs Observed

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

Page 61: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

ArrayList: Run 1, (0,null)Inputs Observed

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

Page 62: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

ArrayList: Run 1, (0,null)Inputs Observed

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.

Page 63: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

ArrayList: Picking the next branch to coverConstraints to solve

Inputs Observed 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); }}

Page 64: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

ArrayList: Solve constraints using SMT solver

Constraints to solve

Inputs Observed 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); }}

Page 65: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

ArrayList: Run 2, (1, null)Constraints to solve

Inputs Observed 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

Page 66: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

ArrayList: Pick new branchConstraints to solve

Inputs Observed 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); }}

Page 67: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

ArrayList: Run 3, (-1, null)Constraints to solve

Inputs Observed 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); }}

Page 68: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

ArrayList: Run 3, (-1, null)Constraints to solve

Inputs Observed 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

Page 69: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

ArrayList: Run 3, (-1, null)Constraints to solve

Inputs Observed 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); }}

Page 70: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

PEX ↔ Z3Rich

Combination

Linear arithmeti

cBitvector Arrays

FreeFunction

s

Models Model used as test inputs

-QuantifierUsed to model custom

theories (e.g., .NET type system)

APIHuge number of small

problems. Textual interface is too inefficient.

SMT@Microsoft

Page 71: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

PEX ↔ Z3: Incrementality

Pex “sends” several similar formulas to Z3.Plus: backtracking primitives in the Z3 API.

pushpop

Reuse (some) lemmas.

SMT@Microsoft

Page 72: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

PEX ↔ Z3: Small models

Given a set of constraints C, find a model M that minimizes the interpretation for x0, …, xn.In the ArrayList example:

Why is the model where c = 2147483648 less desirable than the model with c = 1?

!(c<0) && 0!=c

Simple solution:Assert Cwhile satisfiable

Peek xi such that M[xi] is big Assert xi < n, where n is a small constant

Return last found model SMT@Microsoft

Page 73: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

PEX ↔ Z3: Small models

Given a set of constraints C, find a model M that minimizes the interpretation for x0, …, xn.In the ArrayList example:

Why is the model where c = 2147483648 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 xi) may prevent us from finding a good solution.Use push and pop to retract “bad” choices.

SMT@Microsoft

Page 74: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

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.

SAGE

SMT@Microsoft

parent

generation 1

Page 75: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Zero to Crash in 10 Generations

Starting with 100 zero bytes …SAGE generates a crashing test for Media1 parser

SMT@Microsoft

00000000h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000010h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000020h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000030h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000040h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000050h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000060h: 00 00 00 00 ; ....

Generation 0 – seed file

Page 76: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Zero to Crash in 10 Generations

Starting with 100 zero bytes …SAGE generates a crashing test for Media1 parser

SMT@Microsoft

00000000h: 52 49 46 46 00 00 00 00 00 00 00 00 00 00 00 00 ; RIFF............00000010h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000020h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000030h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000040h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000050h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000060h: 00 00 00 00 ; ....

Generation 1

Page 77: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

`

Zero to Crash in 10 Generations

Starting with 100 zero bytes …SAGE generates a crashing test for Media1 parser

SMT@Microsoft

00000000h: 52 49 46 46 00 00 00 00 ** ** ** 20 00 00 00 00 ; RIFF....*** ....00000010h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000020h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000030h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000040h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000050h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000060h: 00 00 00 00 ; ....

Generation 2

Page 78: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Zero to Crash in 10 Generations

Starting with 100 zero bytes …SAGE generates a crashing test for Media1 parser

SMT@Microsoft

00000000h: 52 49 46 46 3D 00 00 00 ** ** ** 20 00 00 00 00 ; RIFF=...*** ....00000010h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000020h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000030h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000040h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000050h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000060h: 00 00 00 00 ; ....

Generation 3

Page 79: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Zero to Crash in 10 Generations

Starting with 100 zero bytes …SAGE generates a crashing test for Media1 parser

SMT@Microsoft

00000000h: 52 49 46 46 3D 00 00 00 ** ** ** 20 00 00 00 00 ; RIFF=...*** ....00000010h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000020h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000030h: 00 00 00 00 73 74 72 68 00 00 00 00 00 00 00 00 ; ....strh........00000040h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000050h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000060h: 00 00 00 00 ; ....

Generation 4

Page 80: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Zero to Crash in 10 Generations

Starting with 100 zero bytes …SAGE generates a crashing test for Media1 parser

SMT@Microsoft

00000000h: 52 49 46 46 3D 00 00 00 ** ** ** 20 00 00 00 00 ; RIFF=...*** ....00000010h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000020h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000030h: 00 00 00 00 73 74 72 68 00 00 00 00 76 69 64 73 ; ....strh....vids00000040h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000050h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000060h: 00 00 00 00 ; ....

Generation 5

Page 81: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Zero to Crash in 10 Generations

Starting with 100 zero bytes …SAGE generates a crashing test for Media1 parser

SMT@Microsoft

00000000h: 52 49 46 46 3D 00 00 00 ** ** ** 20 00 00 00 00 ; RIFF=...*** ....00000010h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000020h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000030h: 00 00 00 00 73 74 72 68 00 00 00 00 76 69 64 73 ; ....strh....vids00000040h: 00 00 00 00 73 74 72 66 00 00 00 00 00 00 00 00 ; ....strf........00000050h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000060h: 00 00 00 00 ; ....

Generation 6

Page 82: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Zero to Crash in 10 Generations

Starting with 100 zero bytes …SAGE generates a crashing test for Media1 parser

SMT@Microsoft

00000000h: 52 49 46 46 3D 00 00 00 ** ** ** 20 00 00 00 00 ; RIFF=...*** ....00000010h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000020h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000030h: 00 00 00 00 73 74 72 68 00 00 00 00 76 69 64 73 ; ....strh....vids00000040h: 00 00 00 00 73 74 72 66 00 00 00 00 28 00 00 00 ; ....strf....(...00000050h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000060h: 00 00 00 00 ; ....

Generation 7

Page 83: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Zero to Crash in 10 Generations

Starting with 100 zero bytes …SAGE generates a crashing test for Media1 parser

SMT@Microsoft

00000000h: 52 49 46 46 3D 00 00 00 ** ** ** 20 00 00 00 00 ; RIFF=...*** ....00000010h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000020h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000030h: 00 00 00 00 73 74 72 68 00 00 00 00 76 69 64 73 ; ....strh....vids00000040h: 00 00 00 00 73 74 72 66 00 00 00 00 28 00 00 00 ; ....strf....(...00000050h: 00 00 00 00 00 00 00 00 00 00 00 00 C9 9D E4 4E ; ............ÉäN�00000060h: 00 00 00 00 ; ....

Generation 8

Page 84: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Zero to Crash in 10 Generations

Starting with 100 zero bytes …SAGE generates a crashing test for Media1 parser

SMT@Microsoft

00000000h: 52 49 46 46 3D 00 00 00 ** ** ** 20 00 00 00 00 ; RIFF=...*** ....00000010h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000020h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000030h: 00 00 00 00 73 74 72 68 00 00 00 00 76 69 64 73 ; ....strh....vids00000040h: 00 00 00 00 73 74 72 66 00 00 00 00 28 00 00 00 ; ....strf....(...00000050h: 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 ; ................00000060h: 00 00 00 00 ; ....

Generation 9

Page 85: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Zero to Crash in 10 Generations

Starting with 100 zero bytes …SAGE generates a crashing test for Media1 parser

SMT@Microsoft

00000000h: 52 49 46 46 3D 00 00 00 ** ** ** 20 00 00 00 00 ; RIFF=...*** ....00000010h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000020h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................00000030h: 00 00 00 00 73 74 72 68 00 00 00 00 76 69 64 73 ; ....strh....vids00000040h: 00 00 00 00 73 74 72 66 B2 75 76 3A 28 00 00 00 ; ....strf²uv:(...00000050h: 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 ; ................00000060h: 00 00 00 00 ; ....

Generation 10 – CRASH

Page 86: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

SAGE (cont.)

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

SMT@Microsoft

Page 87: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

SAGE↔ 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.

SMT@Microsoft

Page 88: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

SMT: Some Applications

SMT@Microsoft

Z3

Test case generation

Verifying CompilerPredicate

Abstraction

Page 89: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Spec# Approach for a Verifying Compiler

Source LanguageC# + goodies = Spec#

Specificationsmethod contracts,invariants,field and type annotations.

Program Logic: Dijkstra’s weakest preconditions.

Automatic Verificationtype checking,verification condition generation (VCG),automatic theorem proving Z3

Spec# (annotated C#)

Boogie PL

Spec# Compiler

VC Generator

Formulas

Z3

Page 90: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

V

Sta

tic

pro

gra

m v

eri

fier

(Boogie

)

MSIL

Z3

V.C. generatorVerification condition

“correct” or list of errors

Spec# compiler

Spec#Verification architecture

C

Bytecode translator

C

Boogie

VCC HAVOC

Page 91: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

HAVOC

SMT@Microsoft

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.

Page 92: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

A Verifying C Compiler

VCC translates an annotated C program into a Boogie PL program.A C-ish memory model

Abstract heapsBit-level precision

Microsoft Hypervisor: verification grand challenge.

SMT@Microsoft

Page 93: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Hypervisor: A Manhattan Project

Meta OS: small layer of software between hardware and OSMini: 60K lines of non-trivial concurrent systems C codeCritical: must provide functional resource abstractionTrusted: a verification grand challenge

Hardware

Hypervisor

Page 94: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Hypervisor: Some Statistics

VCs have several MbThousands of non ground clausesDevelopers are willing to wait at most 5 min per VC

SMT@Microsoft

Page 95: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Main Challenge

Quantifiers, quantifiers, quantifiers, …Modeling the runtime h,o,f:

IsHeap(h) o ≠ null read(h, o, alloc) = tread(h,o, f) = null read(h, read(h,o,f),alloc)

= t

SMT@Microsoft

Page 96: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Main Challenge

Quantifiers, quantifiers, quantifiers, …Modeling the runtimeFrame axioms o, f:

o ≠ null read(h0, o, alloc) = t read(h1,o,f) = read(h0,o,f) (o,f) M

SMT@Microsoft

Page 97: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Main Challenge

Quantifiers, quantifiers, quantifiers, …Modeling the runtimeFrame axiomsUser provided assertions i,j: i j read(a,i) read(b,j)

SMT@Microsoft

Page 98: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Main Challenge

Quantifiers, quantifiers, quantifiers, …Modeling the runtimeFrame axiomsUser provided assertionsTheories" 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

SMT@Microsoft

Page 99: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Main Challenge

Quantifiers, quantifiers, quantifiers, …Modeling the runtimeFrame axiomsUser provided assertionsTheoriesSolver must be fast in satisfiable instances.

SMT@Microsoft

We want to find bugs!

Page 100: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Bad news

There is no sound and refutationally completeprocedure for

linear integer arithmetic + free function symbols

SMT@Microsoft

Page 101: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Many Approaches

Heuristic quantifier instantiation

Combining SMT with Saturation provers

Complete quantifier instantiation

Decidable fragments

Model based quantifier instantiation

SMT@Microsoft

Page 102: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Challenge: modeling runtime

Is the axiomatization of the runtime consistent?False implies everythingPartial solution: SMT + Saturation ProversFound many bugs using this approach

SMT@Microsoft

Page 103: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Challenge: Robustness

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 undecidablePartial solution: parallelization

SMT@Microsoft

Page 104: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Parallel Z3

Joint work with Y. Hamadi (MSRC) and C. WintersteigerMulti-core & Multi-node (HPC)Different strategies in parallelCollaborate exchanging lemmas

Strategy 1

Strategy 2

Strategy 3

Strategy 4

Strategy 5

SMT@Microsoft

Page 105: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

SMT: Some Applications

SMT@Microsoft

Z3

Test case generation

Verifying CompilerPredicate

Abstraction

Page 106: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Overview

SMT@Microsoft

http://research.microsoft.com/slam/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.

Page 107: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Predicate Abstraction: c2bp

Given a C program P and F = {p1, … , pn}.Produce a Boolean program B(P, F)

Same control flow structure as P.Boolean variables {b1, … , bn} to match {p1, … , pn}.Properties true in B(P, F) are true in P.

Each pi is a pure Boolean expression.Each pi represents set of states for which pi is true.Performs modular abstraction.

SMT@Microsoft

Page 108: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Abstracting Expressions via F

ImpliesF (e)Best Boolean function over F that implies e.

ImpliedByF (e)Best Boolean function over F that is implied by e.ImpliedByF (e) = not ImpliesF (not e)

SMT@Microsoft

Page 109: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Computing ImpliesF(e)

minterm m = l1 ... ∧ ∧ ln, where li = pi, or li = not pi.ImpliesF (e): disjunction of all minterms that imply e.Naive approach

Generate all 2n possible minterms.For each minterm m, use SMT solver to check validity of m

⇒ e.Many possible optimizations

SMT@Microsoft

Page 110: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Computing ImpliesF(e)F = { x < y, x = 2}e : y > 1Minterms over F

!x<y, !x=2 implies y>1 x<y, !x=2 implies y>1!x<y, x=2 implies y>1 x<y, x=2 implies y>1

ImpliesF(y>1) = x<y x=2ImpliesF(y>1) = b1 b2

SMT@Microsoft

Page 111: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Newton

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.

SMT@Microsoft

Page 112: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

SLAM ↔ Z3

All-SATBetter (more precise) Predicate Abstraction

Unsatisfiable coresWhy the abstract path is not feasible?Fast Predicate Abstraction

SMT@Microsoft

Page 113: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

SLAM ↔ Z3: Unsatisfiable cores

Let S be an unsatisfiable set of formulas.S’ S is an unsatisfiable core of S if:

S’ is also unsatisfiable, andThere is not S’’ S’ that is also unsatisfiable.

Computing ImpliesF(e) with F = {p1, p2, p3, p4}Assume p1, p2, p3, p4 e is validThat is p1, p2, p3, p4, e is unsatNow assume p1, p3, e is the unsatisfiable coreThen it is unnecessary to check:

p1, p2, p3, p4 ep1, p2, p3, p4 ep1, p2, p3, p4 e

Page 114: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Other Microsoft clients

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@Microsoft

Page 115: Leonardo de Moura Microsoft Research. SMT@Microsoft Verification/Analysis tools need some form of Symbolic Reasoning.

Conclusion

SMT@Microsoft

SMT is hot at Microsoft.Many applications.Z3 is a new and very efficient SMT solver.http://research.microsoft.com/projects/z3

Thank You!