software model checking with smt

80
Software Model Checking with SMT Ken McMillan Microsoft Research

Upload: ouida

Post on 24-Feb-2016

73 views

Category:

Documents


0 download

DESCRIPTION

Software Model Checking with SMT. Ken McMillan Microsoft Research. TexPoint fonts used in EMF: A A A A A. Software model checking and SMT. In checking properties of software as opposed to hardware or protocols, we have several interesting issues to deal with: Software is not finite-state - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Software Model Checking with SMT

Software Model Checking with SMT

Ken McMillanMicrosoft Research

Page 2: Software Model Checking with SMT

Software model checking and SMT• In checking properties of software as opposed to hardware or protocols,

we have several interesting issues to deal with:– Software is not finite-state– Extensive use is made of arithmetic– We have arrays and linked data structures

• The theory reasoning capabilities of SMT solvers are thus extensively used in software model checking.

• This also means software verification relies heavily on abstraction.• Moreover, software has structure that we can exploit such as

– Sequential control flow– Procedural abstraction

• Software model checking algorithms are specialized to exploit this structure.

Page 3: Software Model Checking with SMT

Role of SMT• In this lecture, we'll consider the uses of SMT in software model

checking.• SMT is used in three distinct roles:

– Counterexample generation (from satisfying assignments)– Testing and strengthening conjectures (from UNSAT cores)– Abstraction refinement (from interpolants)

In this lecture, we will focus in the latter two roles, using theSMT solver as an engine for generating proofs.

Finding counterexamples using SMT is essentially similar tothe finite state case. As we'll see, counterexamples are often aby-product of abstraction refinement.

Page 4: Software Model Checking with SMT

Model Checking

yes!

no!

pq

ModelChecker

p

q

SystemModel

G(p ) F q)LogicalSpecification

Counterexample

A great advantage of model checking is the ability to producebehavioral counterexamples to explain what is going wrong.

Page 5: Software Model Checking with SMT

Temporal logic (LTL)

• A logical notation that allows to succinctly express relationships of events in time

• Temporal operators– “henceforth p”– “eventually p”– “p at the next time”– “p unless q”

𝑝 ¬𝑝 ¬𝑝 ¬𝑝 𝑝 𝑝 𝑝 ...

¬𝐺𝑝 𝐺𝑝 𝐺𝑝 𝐺𝑝¬𝐺𝑝 ¬𝐺𝑝 ¬𝐺𝑝

Page 6: Software Model Checking with SMT

Types of temporal properties

• Safety (nothing bad happens) “mutual exclusion”

“ must hold until ”

• Liveness (something good happens)“if , eventually ”

• Fairness“if infinitely often , infinitely often ”

We will focus on safety properties.

Page 7: Software Model Checking with SMT

Safety and reachability

I

States = valuations of state variablesTransitions = execution stepsInitial state(s)

F

Bad state(s)Breadth-first searchCounterexample!

Page 8: Software Model Checking with SMT

Reachable state set

I

F

Remove the “bug”Breadth-first searchFixed point = reachable state set

Safety property verified!

Model checking is a little more complex than this, butreachability captures the essence for our purposes.

Model checking can find very subtle bugs in circuitsand protocols, but suffers from state explosion, anddoesn't terminate in the infinite-state case.

Page 9: Software Model Checking with SMT

Abstraction• Problem: verify a shallow property of a very large system• Solution: Abstraction

– Extract just the facts about the system state that are relevant to the proving the shallow property.

• An abstraction is a restricted deduction system that focuses our reasoning on relevant facts, and thus makes proof easier.

Page 10: Software Model Checking with SMT

Relevance and refinement• Problem: how do we decide what deductions are relevant to a property?

– Is relevance even a well defined notion?• Relevance:

– A relevant deduction is one that is used in a simple proof of the desired property.

• Generalization principle:– Deductions used in the proof of special cases tend to be relevant to the

overall proof.

Page 11: Software Model Checking with SMT

Proofs• A proof is a series of deductions, from premises to conclusions• Each deduction is an instance of an inference rule• Usually, we represent a proof as a tree...

P1 P2

P3 P4 P5

C

Premises

Conclusion

P1 P2

C

If the conclusion is “false”, the proof is a refutation

SMT solvers can be instrumented to provide refutations in the UNSAT case.

Page 12: Software Model Checking with SMT

Inference rules• The inference rules depend on the theory we are reasoning in

p : p D

_ D

Resolution rule:

Boolean logic Linear arithmetic

x1 · y1

x2 · y2

x1+x2 · y1+y2

Sum rule:

A summation resulting in the contradiction is a Farkas proof.

Page 13: Software Model Checking with SMT

Reachable states: complex

Inductive invariants

I

F

A Boolean-valued formula over the system state

:

Partitions the state space into two regionsForms a barrier between the initial states and bad states

No transitions cross this way

Inductive invariant: simple!

Page 14: Software Model Checking with SMT

Invariants and relevance• A predicate is relevant if it is used in a simple inductive invariant

l1: x = y = 0;l2: while(*)l3: x++, y++;l4: while(x != 0)l5: x--, y--;l6: assert (y == 0);

state variables: pc, x, y

inductive invariant = property +

pc = l1 Ç x = y

• Relevant predicates: pc = l1 and x = y• Irrelevant (but provable) predicate: x ¸ 0

property: pc = l6 ) y = 0

Page 15: Software Model Checking with SMT

What is Abstraction• By abstraction, we mean something like "reasoning with limited

information".• The purpose of abstraction is to let us ignore irrelevant details, and thus

simplify our reasoning.• In abstract interpretation, we think of an abstraction as a restricted

domain of information about the state of a system.• Here, we will take a slightly broader view:

An abstraction is a restricted deduction system

• We can think of an abstraction as a language for expressing facts, and a set of deduction rules for inferring conclusions in that language.

Page 16: Software Model Checking with SMT

The function of abstraction• The function of abstraction is to reduce the cost of proof search by

reducing the space of proofs.

RichDeduction

System

Abstraction

Automated toolcan search this spacefor a proof.

• An abstraction is a way to express our knowledge of what deductions may be relevant to proving a particular fact.

Page 17: Software Model Checking with SMT

Symbolic transition systems• Normally, we think of a discrete system as a state graph, with:

– a set of states – a set of initial states – a set of transitions .

• This defines a set of execution sequences of the system• It is often useful to represent and symbolically, as formulas:

• Note, we use for " at the next time", so can be thought of as representing a set of pairs

• The system describe above has one execution sequence

Page 18: Software Model Checking with SMT

Proof by Inductive Invariant• In a proof by inductive invariant, we prove a safety property according to

the following proof rule:

• This rule leaves great flexibility in choosing an abstraction (restricted deduction system). We can choose:1. A language for expressing the inductive invariant .2. A deductive system for proving the three obligations.

Many different choices have been made in practice. We will discussa few...

Page 19: Software Model Checking with SMT

Inductive invariants from fixed points• In abstract interpretation, we use our abstraction to deduce facts about

executions of increasing length until a fixed point is reached.

𝜙0=𝐼 𝑇⊢𝜙0⇒𝜌1′

𝜙1=𝜙0∨𝜌1 𝑇⊢𝜙1⇒ 𝜌2′

𝜙2=𝜙1∨2 𝑇⊢𝜙2⇒ 𝜌3′

until

• In general, might mean "the strongest sentence in our language implied by both and ".

Page 20: Software Model Checking with SMT

Abstraction languages• Difference bounds

is all conjunctions of constraints like and .

• Affine equalities

is all conjunctions of constraints .

• Houdini (given a fixed finite set of formulas

is all conjunctions of formulas in .

Page 21: Software Model Checking with SMT

Abstraction languages• Predicate abstraction (given a fixed finite set of formulas

• Program invariants (given language of data predicates)

is all conjunctions of where .

is all Boolean combinations of formulas in .

Note

Page 22: Software Model Checking with SMT

Example• Let's try some abstraction languages on an example...

l1: x = y = 0;l2: while(*)l3: x++, y++;l4: while(x != 0)l5: x--, y--;l6: assert (y == 0);

• Difference bounds• Affine equalities• Houdini with

(𝑝𝑐=𝑙2)⇒𝑥=𝑦(𝑝𝑐=𝑙3 )⇒𝑥=𝑦

(𝑝𝑐=𝑙2)⇒𝑥=𝑦(𝑝𝑐=𝑙3 )⇒𝑥=𝑦

Page 23: Software Model Checking with SMT

Another example• Let's try an even simpler example...

l1: x = 0;l2: if(*)l3: x++;l4: elsel5: x--;l6: assert (x != 0);

• Difference bounds• Affine equalities• Houdini with

(𝑝𝑐=𝑙6 )⇒𝑥≥−1∧𝑥≤1

(𝑝𝑐=𝑙2)⇒𝑥=0(𝑝𝑐=𝑙3 )⇒𝑥=0

(𝑝𝑐=𝑙5 )⇒ 𝑥=0(𝑝𝑐=𝑙6 )⇒𝑡𝑟𝑢𝑒

(𝑝𝑐=𝑙6 )⇒𝑡𝑟𝑢𝑒

• Predicate abstraction with

(𝑝𝑐=𝑙6 )⇒¬𝑥 ≤0∨¬𝑥≥0

Page 24: Software Model Checking with SMT

Deduction systems• Up to now, we have implicitly assumed we have an oracle that can

prove any valid formulas of the forms:

• Thus, any valid inductive invariant can be proved. However, these proofs may be very costly, especially the consecution test . Moreover we may have to test a large number of candidates .

• For this reason, we may choose to use a more restricted deduction system. We will consider two cases of this idea:– Localization abstraction– The Boolean Programs abstraction

Page 25: Software Model Checking with SMT

Localization abstraction• Suppose that where each is a fact about some system component.• We choose some subset of the 's that are considered relevant, and

allow ourselves any valid facts of the form:

• By restricting our prover to use only a subset of the available deductions, we reduce the space of proofs and make the proof search easier.

• If the proof fails, we may add components to .

𝜙∧𝑇⇒𝜙 ′

Page 26: Software Model Checking with SMT

Example

Boolean Programs• Another way to restrict deductions is to reduce the space of conclusions.• The Boolean programs abstraction (as in SLAM) uses the same

language as predicate abstraction, but restricts deductions to the form:

where and

A Boolean program is defined by a set of such facts.

l1: int x = *;l2: if(x > 0){l3: x--;l4: assert(x >= 0);l5: }

Let

In practice, we may add some disjunctions to our setof allowed deductions, to avoid adding more predicates.

Page 27: Software Model Checking with SMT

Boolean Programs with SMT• We can carry out deduction within our restricted proof system using an

SMT solver.• This amounts to testing a collection of conjectures.

𝑃= {𝑝1 ,𝑝2 } ,where𝑝1 is 𝑥=0 ,𝑝2 is𝑥 ≥0

• Use SMT solver to test a set of conjectures, replacing with each minterm over

Example:

𝑇⊢¬𝑝1∧¬𝑝2⇒𝑝′1𝑇⊢¬𝑝1∧¬𝑝2⇒¬𝑝 ′ 1

Page 28: Software Model Checking with SMT

Boolean Programs with SMT• The valid conjectures, form the Boolean program. We can pass these to

a finite state model checker such as Bebop.– Note, we use Boolean variables for , not their actual definitions, since Bebop

doesn't understand arithmetic.• We can also think of the valid conjectures as defining a truth table:

F F F F

F T ? ?

T F F F

T T

𝑥>0𝑥=0 𝑥′=0 𝑥 ′>0x--

In one case, we get no information, one is infeasible

𝑇 :𝑥 ′=𝑥−1

Page 29: Software Model Checking with SMT

Conjecture explosion• Number of conjectures to test is exponential in .• One solution: limit to cubes of size 2 or 3, instead of minterms.• This produces a weaker conjecture set at lower cost.

Eager deduction: conjectures tested without evidence thatthey are useful.

• Important general point: eager deduction must be limited to a tractable amount (example: Boolean constraint propagation in SAT)

• In case the proof fails because of weakening, we can recover by adding a conjecture that is relevant to the failure (lazy deduction)

Page 30: Software Model Checking with SMT

Strengthening by UNSAT core• Let's say we check this conjecture:

𝑇⊢𝑝1∧𝑝2∧𝑝3⇒𝑝1′

• We do this by checking unsatisfiability of the following formula:

𝑇 ∧𝑝1∧𝑝2∧𝑝3∧¬𝑝1′

• If UNSAT, the solver can produce an UNSAT core, e.g.:

𝑇∧𝑝1∧𝑝3∧¬𝑝1′

• This gives us a strengthened fact:

𝑇⊢𝑝1∧𝑝3⇒𝑝1′

• This can strengthen conjectures based on counterexamples (see IC3) and also reduce the space of conjectures to test.

Page 31: Software Model Checking with SMT

Generalized counterexamples• A generalized counterexample for formula is a formula , where is a

subset of the variables, such that .• That is a guarantee that is false, no matter the value of the other

variables.• The advantage of a generalized counterexample is that it can rule out a

large space of conjectures at once (we can find a cube such that no extensions to minterms yield a valid conjecture).

• In general, finding required quantifier elimination, so in practice this is only done in special cases (see again IC3).

Page 32: Software Model Checking with SMT

Predicate abstraction and SMT• Moving to predicate abstraction, we now have the same abstract

language, but we allow to deduce disjunctions on the RHS, e.g.,

𝑇⊢𝑝1∧𝑝2⇒𝑝1′ ∨𝑝2

• Note this is the same as saying entails a clause:

𝑇⊢(¬𝑝1∨¬𝑝2∨𝑝1′ ∨𝑝2

′ )

• This is not fundamentally different from Boolean programs, but disjunctions can explode the conjecture set.

• In practice, disjunctions are usual not conjectured eagerly, but in response to proof failures (see Das and Dill method).

Page 33: Software Model Checking with SMT

Invariant search• Given a language for expressing invariants, and a deduction system for

proving them, how do we find a provable inductive invariant that proves a property ?

• Abstract interpretation– Iteratively constructs the strongest provable .– Independent of .

• Constraint-based methods– Set up constraint system defining valid induction proofs– Solve using a constraint solver– For example, abstract using linear inequalities and summation rule.

• Craig interpolation– Generalize the proofs of bounded behaviors

In general, making the space of proofs smaller will make the proofsearch easier.

Page 34: Software Model Checking with SMT

Relevance and abstraction• The key to proving a property with abstraction is to choose a small

space of deductions that are relevant to the property.• How do we choose...

– Predicates for predicate abstraction?– System components for localization?– Disjunctions for Boolean programs?

• Next, we will observe that deductions that are relevant to particular cases tend to be relevant in general. This gives us a methodology of abstraction refinement.

Page 35: Software Model Checking with SMT

Basic refinement framework

• A common paradigm in theorem proving is to let proof search guide counterexample search and vice-versa.

• This occurs in CDCL, for example, where BCP guides model search and model search failure (conflict) generates new deduction (conflict clauses)

ProofSearch

Counterexamplesearch

failure

failure

Page 36: Software Model Checking with SMT

Basic framework for software• Abstraction and refinement are proof systems

– spaces of possible proofs that we search

Abstractor

Refiner

General proof system

IncompleteSpecialized proof systemComplete

prog.

pf. special case cex.

pf. of special case

Refinement = augmenting abstractor’s proof system to replicateproof of special case generated by refiner.Narrow the abstractor’s proof space to relevant facts.

Page 37: Software Model Checking with SMT

Background• Simple program statements (and their Hoare axioms)

{}[]{ ) }

{}x := e{[e/x]}

{}havoc x{8 x }

• A compound stmt is a sequence simple statements 1;...; k

• A CFG (program) is an NFA whose alphabet is compound statements.– The accepting states represent safety failures.

x = 0;while(*) x++;assert x >= 0;

[x<0]

x := x +1

x := 0

Page 38: Software Model Checking with SMT

Hoare logic proofs• Write H(L) for the Hoare logic over logical language L.• A proof of program C in H(L) maps vertices of C to L such that:

– the initial vertex is labeled True– the accepting vertices are labeled False– every edge is a valid Hoare triple.

[x<0]

x := x +1

x := 0

{True} {False}{x ¸ 0}

This proves the failure vertex not reachable, orequivalently, no accepting path can be executed.

Page 39: Software Model Checking with SMT

Path reductiveness• An abstraction is path-reductive if, whenever it fails to prove program C,

it also fails to prove some (finite) path of program C.

Example, H(L) is path-reductive if• L is finite• L closed under disjunction/conjunction

• Path reductiveness allows refinement by proof of paths.• In place of “path”, we could use other program fragments, including

restricted paths (with extra guards), paths with loops, procedure calls...• We will focus on paths for simplicity.

Page 40: Software Model Checking with SMT

Example

x = y = 0;while(*) x++; y++;while(x != 0) x--; y--;assert (y == 0);

x:=0;y:=0

x:=x+1; y:=y+1

[x 0]; x:=x-1; y:=y-1

[x=0]; [y 0]

• Try to prove with predicate abstraction, with predicates {x=0,y=0}• Predicate abstraction with P is Hoare logic over the Boolean

combinations of P

Page 41: Software Model Checking with SMT

{x=0 Æ y=0}

{x0 Æ y0}

{True}

{True}

{True}

{True}

{True}

{x = y}

{x = y}

{x = y}

{x = y}

{x = y}

{False}

{True}

Unprovable path

x = y = 0;

x++; y++;

x++; y++;

[x!=0];x--; y--;

[x!=0];x--; y--;

[x == 0][y != 0]

Cannot prove with PA({x=0,y=0})

Ask refiner to prove it!

Augment P with new predicate x=y.PA can replicate proof.

{x = y Æ x=0}

{x = y Æ x0}

{x = y}

{x = y}

{x = y}

{False}

{True}

Abstraction refinement:• Path unprovable to abstraction• Refiner proves• Abstraction replicates proof

Page 42: Software Model Checking with SMT

Path reductiveness• Path reductive abstractions can be characterized by the path proofs

they can replicate– Predicate abstraction over P replicates all the path proofs over Boolean

combinations of P.– The Boolean program abstraction replicates all the path proofs over the

cubes of P. • For these cases, it is easy to find an augmentation that replicates a

proof (if the proof is QF).• In general, finding the least augmentation might be hard...

But where do the path proofs come from?

Page 43: Software Model Checking with SMT

Refinement methods

• Strongest postcondition (SLAM1)• Weakest precondition (Magic,FSoft,Yogi)• Interpolant methods

– Feasible interpolation (BLAST, IMPACT)– Bounded provers (SATABS)– Constraint-based (ARMC)

Local proof

• There are many technical approaches to this problems.• All can be viewed, however, as a search for a local proof.

Page 44: Software Model Checking with SMT

Interpolation Lemma

• If A Ù B = false, there exists an interpolant A' for (A,B) such that:

A Þ A'A' ^ B = falseA' 2 L(A) \ L(B)

• Example: – A = p Ù q, B = Øq Ù r, A' = q

[Craig,57]

In many logics, an interpolant can be derived in linear

time from a refutaion proofs of A ^ B.

Page 45: Software Model Checking with SMT

Interpolants as Floyd-Hoare proofs

False

x1=y0

True

y1>x1

))

)

1. Each formula implies the next

2. Each is over common symbols of prefix and suffix

3. Begins with true, ends with false

Proving in-line programs

SSAsequence Prover

Interpolation

HoareProof

proof

x=y;

y++;

[x=y]

x1= y0

y1=y0+1

x1=y1

{False}

{x=y}

{True}

{y>x}

x = y

y++

[x == y]

Page 46: Software Model Checking with SMT

Local proofs and interpolants

x=y;

y++;

[y · x]

x1=y0

y1=y0+1

y1·x1

y0 · x1

x1+1 · y1 y1 · x1+1

y1 · y0+1

1 · 0FALSE

x1 · y0

y0+1 · y1

TRUE

x1 · y

x1+1 · y1

FALSE

This is an example of a local proof...

Page 47: Software Model Checking with SMT

Definition of local proof

x1=y0

y1=y0+1

y1·x1

y0

scope of variable = range of frames it occurs in

y1

x1

vocabulary of frame = set of variables “in scope”

{x1,y0}

{x1,y0,y1}

{x1,y1}

x1+1 · y1

x1 · y0

y0+1 · y1 deduction “in scope” here

Local proof: Every deduction written in vocabulary of some frame.

Page 48: Software Model Checking with SMT

Forward local proof

x1=y0

y1=y0+1

y1·x1

{x1,x0}

{x1,y0,y1}

{x1,y1}

Forward local proof: each deduction can be assigned a framesuch that all the deduction arrows go forward.

x1+1 · y1

1 · 0

FALSE

x1 · y0

y0+1 · y1

For a forward local proof, the (conjunction of) assertionscrossing frame boundary is an interpolant.

TRUE

x1 · y

x1+1 · y1

FALSE

Page 49: Software Model Checking with SMT

Reverse local proof

x1=y0

y1=y0+1

y1·x1

{x1,x0}

{x1,y0,y1}

{x1,y1}

Reverse local proof: each deduction can be assigned a framesuch that all the deduction arrows go backward.For a reverse local proof, the negation of assertionscrossing frame boundary is an interpolant.

TRUE

: y0+1 · x1

: y1· x1

FALSE

y0+1 · y1

y0+1 · x1

x1 · y0

1 · 0

FALSE

Page 50: Software Model Checking with SMT

General local proof

x1=3y0

x1 · 2

1 · x1

{x1,y0}

{x1}

{x1}

General local proof: each deduction can be assigned a frame,but deduction arrows can go either way.For a general local proof, the interpolants contain implications.

TRUE

x1·2 ) x1·0

x1 · 0

FALSE

x1 · 0

1 · 0

FALSE

Page 51: Software Model Checking with SMT

Refinement methods

• Strongest postcondition (SLAM1)• Weakest precondition (Magic,FSoft,Yogi)• Interpolant methods

– Feasible interpolation (BLAST, IMPACT)– Bounded provers (SATABS)– Constraint-based (ARMC)

Local proof

Page 52: Software Model Checking with SMT

Refinement with SP• The strongest post-condition of w.r.t. progam , written SP(,), is the

strongest such that {} {}.• The SP exactly characterizes the states reachable via .

False

x1=y0

True

y1>x1

x=y;

y++;

[x=y]

x1= y0

y1=y0+1

x1=y1

{False}

{x=y}

{True}

{y=x+1}

x = y

y++

[y·x]

Refinement with SP: Syntactic SP computation:

{} [] { Æ }

{} x := e {9 v [v/x] Æ x = e[v/x]}

{} havoc x {9 x }

This is viewed as symbolic execution,but there is a simpler view.

Page 53: Software Model Checking with SMT

SP as local proof• Order the variables by their creation in SSA form:

x0 Â y0 Â x1 Â y1 Â • Refinement with SP corresponds to local deduction with these rules:

x = e

[e/x]x max. in

FALSE unsat.

• We encode havoc specially in the SSA:

havoc x x = iwhere i is a

fresh Skolem constant

Think of the i’s as implicitly existentially quantified

Page 54: Software Model Checking with SMT

SP example

y0 = 1

x1=y0

y1=y0+1

y1·x1

{x1,y0}

{x1,y0,y1}

{x1,y1}

Ordering of rewrites ensures forward local proof.The (conjunction of) assertions crossing frame boundaryis an interpolant with i’s existentially quantifed.

TRUE

91 (x1=1 Æ y0 = 1)

FALSE

x1 = 1

y1 = 1+1

y1 · 1

1+1·1

FALSE

91 (x1=1 Æ y1 = 1+1)

x1 = y0

y1 = x0 + 1

We can use quantifier elimination if our logic supports it.

Page 55: Software Model Checking with SMT

Refinement quality• Refinement with SP and WP is incomplete

– May exists a refinement that proves program but we never find one• These are weak proof systems that tend to yield low-quality proofs• Example program:

x = y = 0;while(*) x++; y++;while(x != 0) x--; y--;assert (y == 0);

{x == y}

invariant:

Page 56: Software Model Checking with SMT

{y = 0}

{y = 1}

{y = 2}

{y = 1}

{y = 0}

{False}

{True}

{x = y}

{x = y}

{x = y}

{x = y}

{x = y}

{False}

{True}

Execute the loops twice

This simple proof contains invariants

for both loops

• Predicates diverge as we unwind• A practical method must somehow

prevent this kind of divergence!

x = y = 0;

x++; y++;

x++; y++;

[x!=0];x--; y--;

[x!=0];x--; y--;

[x == 0][y != 0]

Refine with SP (and proof reduction)

Same result with WP!

We need refinement methods that can generate simple proofs!

Page 57: Software Model Checking with SMT

Refinement methods

• Strongest postcondition (SLAM1)• Weakest precondition (Magic,FSoft,Yogi)• Interpolant methods

– Feasible interpolation (BLAST, IMPACT)– Bounded provers (SATABS)– Constraint-based (ARMC)

Local proof

Page 58: Software Model Checking with SMT

Bounded Provers [SATABS]

• Define a (local) proof system– Can contain whatever proof rules you want

• Define a cost metric for proofs– For example, number of distinct predicates after dropping subscripts

• Exhaustive search for lowest cost proof– May restrict to forward or reverse proofs

x = e

[e/x]x max. in

FALSE unsat.

Allow simple arithmetic rewriting.

Page 59: Software Model Checking with SMT

Loop example

x0 = 0y0 = 0

x1=x0+1y1=y0+1

TRUE

x0= 0Æ y0 = 0

...

x1=1 Æ y1 = 1x2=x1+1y2=y1+1

...

x1 = 1y1 = 1

x2 = 2y2 = 2

... ...

cost: 2N

x2=2 Æ y2 = 2

x0 = y0

x1 = y0+1

x1 = y1

x2 = y1+1

x2 = y2

TRUE

x0 = y0

...

x1= y1

cost: 2

x2= y2

Lowest cost proof is simpler, avoids divergence.

Page 60: Software Model Checking with SMT

Lowest-cost proofs• Lowest-cost proof strongly depends on choice of proof rules

– This is a heuristic choice– Rules might include bit vector arithmetic, arrays, etc...– May contain SP or WP (so complete for refuting program paths)

• Search for lowest cost proof may be expensive!– Hope is that lowest-cost proof is short– Require fixed truth value for all atoms (refines restricted case)

• Divergence is still possible when a terminating refinement exists– However, heuristically, will diverge less often than SP or WP.

Page 61: Software Model Checking with SMT

Refinement methods

• Strongest postcondition (SLAM1)• Weakest precondition (Magic,FSoft,Yogi)• Interpolant methods

– Feasible interpolation (BLAST, IMPACT)– Bounded provers (SATABS)– Constraint-based (ARMC)

Local proof

Page 62: Software Model Checking with SMT

Constraint-based interpolants• Farkas’ lemma: If a system of linear inequalities is UNSAT, there is a

refutation proof by summing the inequalities with non-neg. coefficients.• Farkas’ lemma proofs are local proofs!

x0 · 00 · y0

x1·x0+1z1·x1-1

y0+1·y1

y1+1·x1

1 (y0+1·y1)1 (y1+1·x1)

1 (x0 · 0)1 (0 · y0)

x0 · y0

1 (x1·x0+1)0 (z1·x1-1)

x1 · y0

1 · 0

Intermediate sums arethe interpolants!

x0 · y0

x1 · y0

1 · 0

0 · 0

Coefficients can be foundby solving an LP.

Interpolants can becontrolled with additionalconstraints.

.

Page 63: Software Model Checking with SMT

Refinement methods

• Strongest postcondition (SLAM1)• Weakest precondition (Magic,FSoft,Yogi)• Interpolant methods

– Feasible interpolation (BLAST, IMPACT)– Bounded provers (SATABS)– Constraint-based (ARMC)

Local proof

Page 64: Software Model Checking with SMT

Interpolation and SMT• An SMT solver has heuristics for generating simple proofs

– CDCL focuses on relevant decisions and deductions– Theory solvers generate simple theory lemmas

• However, it generates non-local proofs. Feasible interpolation can be seen as factoring a non-local proof into a local proof.

• This allows us to use an SMT solver to generate the simple local proofs we require for refinement.

• Interpolation (factoring into local form) can be done efficiently for certain theories– propositional logic– linear arithmetic (integer or real)– equality, function symbols, arrays

Page 65: Software Model Checking with SMT

Non-local to local• For linear arithmetic, interpolation amounts to putting a Farkas proof in

the right order.

x0 · y0

x1·x0-1

x2· x1-1y0·x2

x0 · y0

x1 · y0-1

0 · -2

0 · 0

x2 · x0-2

x2 · y0-2

0 · -2

Non-local!

Interpolation re-orders thesum to make the proof local.

x1· y0-1

x2· y0-2

0·-2

Page 66: Software Model Checking with SMT

Interpolant quality• We measure the cost or complexity of a local proof by the deductions

produced.• Simple non-local proofs generated by the SMT solver can be far from

optimal when translated to local form, however.

𝑥0≤0𝑥1≤𝑥0+1𝑥2≤ 𝑥1+1𝑥3≤ 𝑥2+1

100≤ 𝑥3

100≤3

Farkas proof Interpolant

𝑥0≤0𝑥1≤1𝑥2≤2𝑥3≤3

A Farkas proof involvingdifferent variables or constraints might yieldsimpler interpolant.

• To produce good quality (simple) interpolants, we may need to modify the theory solvers to search for better proofs.

Page 67: Software Model Checking with SMT

Feasible interpolation and SMT• Think of an interpolant as a proof in interpolated form:

𝐴⊢ 𝐼 𝐵⊢¬ 𝐼𝐴 ,𝐵⊢⊥

reasonin

reasonin

Interpolation is dividing the proof into two parts, one in the vocabulary of and one in the vocabulary of , divided bya single cut on the interpolant .

Page 68: Software Model Checking with SMT

Feasible interpolation and resolution• Propositional resolution has linear-time interpolation

Color a formula red if and green if

𝐴 ,𝐵⊢𝜙1…𝜙𝑘 ,𝜓1…𝜓𝑚 𝐴⊢𝜙1…𝜙𝑘, 𝐼❑ 𝐵⊢¬ 𝐼 ,𝜓1…𝜓𝑚

𝐴⊢ 𝐼❑ 𝐵⊢¬ 𝐼𝐴 ,𝐵⊢⊥

... ... ...

𝐴 ,𝐵⊢⊥The interpolant is a Boolean circuit with the same structure asthe resolution DAG.

Booleancircuit

CDCL produces resolution proofs (conflict clause generation = resolution)

Page 69: Software Model Checking with SMT

Interpolation of theory lemmas

• Extending this to Nelson/Oppen combinations is a bit complex (see McMillan TACAS 2004, Yorsh and Musuvathi CADE 2005).

• Various theory combinations have been implemented in interpolating SMT solvers.

0<0(𝑏<𝑎∨𝑐<𝑏∨𝑎≤𝑐)

Farkas proof...

...theory clause

𝐼 :𝑎≤𝑐

interpolation

Page 70: Software Model Checking with SMT

Interpolating provers• Quite a number of provers are now available that produce interpolants,

typically by constructing a proof in interpolated form.

Prover Theory or proof system local

FOCI QF_AUFIDL, QF_UFLRA yes*

CSISat QF_UFLRA no

MathSAT5 QF_UFLIA, QF_UFLRA no

iPrincess LIA no

SMTInterpol QF_LIA, QF_LRA no

Vampyre superposition + LRA yes*

iZ3 AUFLIA no

*Some of these provers try to produce simpler interpolantsby searching for simple local proofs.

Page 71: Software Model Checking with SMT

Basic Framework• Abstraction and refinement are proof systems

– spaces of possible proofs that we search

Abstractor

Refiner

General proof system

IncompleteSpecialized proof systemComplete

prog.

pf. special case cex.

pf. of special case

An effective refiner produces simple proofs that generalize away fromthe special case and yield simple abstractions.One way to accomplish this is to use an SMT solver and feasible interpolation.

Page 72: Software Model Checking with SMT

Lazy v. Eager Abstraction• We can classify abstractors as eager or lazy based on the extent to

which they test conjectures speculatively.• At the extreme lazy end is lazy abstraction. This method does not

generalize deductions from one execution path to another.• Lazy abstraction (as in BLAST) performs eager deduction using

predicate abstraction along individual execution paths.• Lazy abstraction with interpolants (as in IMPACT) is yet more lazy, as

essentially all deduction is done be the refiner.

IMPACT relies on SMT as its only proof engine.

Page 73: Software Model Checking with SMT

An example

do{ lock(); old = new; if(*){ unlock(); new++; }} while (new != old);

program fragment

L=0

L=1; old=new

[L!=0]

L=0; new++

[new==old]

[new!=old]

control-flow graph

Page 74: Software Model Checking with SMT

1

L=0

T2

[L!=0]T

IMPACT algorithm

L=0

L=1; old=new

[L!=0]

L=0; new++

[new==old]

[new!=old]

control-flow graph

0T

F L=0

Label error state with false, by refining labels on path

[CAV 2006]

Page 75: Software Model Checking with SMT

6[L!=0]T

5

[new!=old]

T

4

L=0; new++

T

3

L=1;old=new

T

IMPACT algorithm

L=0

L=1; old=new

[L!=0]

L=0; new++

[new==old]

[new!=old]

control-flow graph

0

12

L=0[L!=0]F L=0

F L=0

L=0

T

Cover: state 5 is subsumed bystate 1.

Page 76: Software Model Checking with SMT

T

11[L!=0]

T

10

[new!=old]

T

8

T

IMPACT algorithm

L=0

L=1; old=new

[L!=0]

L=0; new++

[new==old]

[new!=old]

control-flow graph

0

12

3

4

5

L=0

L=1;old=new

[L!=0]

L=0; new++

[new!=old]

F L=0

6[L!=0]F L=0

L=0

7

[new==old]

T

old=new

F

old=new

F

T

Another cover. Unwinding is now complete.

9T

Uncovered prefix of ART is now an inductive invariant.

Page 77: Software Model Checking with SMT

Abstract counterexamples• An abstract counterexample is an explanation of why a given proofs

system (abstraction) does not prove a particular case.• An unprovable path looks like this:

• If any conjecture is provable with SMT, this abstract counterexample can be eliminated.

• Conjectures can be strengthened using UNSAT cores.• This is a lazy approach to adding conjectures in predicate abstraction or

especially disjunctions in Boolean programs (Das & Dill).

1 2 3 4 5

usually cubes

...where

Page 78: Software Model Checking with SMT

...in predicate refinement• We can use the abstract counterexample as a restriction in refinement

x=0

x++

x++

x++

[x < 0]

[x=0]

[x=0]

[x=1]

[x=2]

[x 0,1,2]

Restricted path, from PA({x=0,x=1,x=2})

Lowest-cost proof leads to divergence!

Lowest-cost proof without restriction.

{x=3}

{False}

{True}

{0 · x}

{0 · x}

{0 · x}

{False}

Restricting paths can make the refiner’sjob easier. However, it also skews theproof cost metric. This can cause therefiner to miss globally optimal proofs,leading to divergence.

Page 79: Software Model Checking with SMT

Summary• Abstraction and refinement can be thought of as two proof systems:

– Abstractor is general, but incomplete– Refiner is specialized, but complete.– Analogous to BCP/conflict clause generation in CDCL

• The abstractor is eager, within narrowly restricted deduction system.– When proof fails, we must analyze failures to find a special case that fails.– These special case become goals for the refiner.

• Refiners can be viewed as focused local proof systems– The refiner's proof augments the abstractor's deduction system, adding

terms, conjectures, hypotheses, etc.– A good refinement is a simple local proof

Page 80: Software Model Checking with SMT

Summary, cont.• SMT solvers have several important roles in this process.

– Testing and strengthening conjectures (with UNSAT cores)– Refinement though feasible interpolation– Generating counterexamples when refinement fails

• In these roles, we exploit several qualities of modern SMT solvers– Ability to handle the needed theories, such as integers, bit-vectors, arrays.– Efficiency in checking large numbers of conjectures (incrementally)– CDCL and theory heuristics to find simple proofs and small cores

Because of these capabilities, SMT solversare the primary engines of proof in manysoftware model checking tools.