sat, interpolants and software model checking

39
SAT, Interpolants and Software Model Checking Ken McMillan Cadence Berkeley Labs

Upload: bailey

Post on 15-Jan-2016

52 views

Category:

Documents


0 download

DESCRIPTION

SAT, Interpolants and Software Model Checking. Ken McMillan Cadence Berkeley Labs. Applications of SAT solvers. BMC of programs using SAT (e.g., CBMC) SAT solvers in decision procedures Eager approach (e.g., UCLID) Lazy approach (Verifun, ICS, many others) SAT-based image computation - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: SAT, Interpolants and Software Model Checking

SAT, Interpolantsand Software Model Checking

Ken McMillan

Cadence Berkeley Labs

Page 2: SAT, Interpolants and Software Model Checking

Applications of SAT solvers

• BMC of programs using SAT (e.g., CBMC)• SAT solvers in decision procedures

– Eager approach (e.g., UCLID)

– Lazy approach (Verifun, ICS, many others)

• SAT-based image computation– Applied to predicate abstraction (Lahiri, et al)

• ...

We will consider instead the lessons learned from solving SATthat can be applied to software verification.

SAT solvers have been applied in many ways in software verification

Page 3: SAT, Interpolants and Software Model Checking

Outline• SAT solvers

– How do they work

– What general lessons can we learn from the experience

• Software model checking survey– How various methods do or do not embody lessons from SAT

• A modest proposal– An attempt to apply the lessons of SAT to software verification

Page 4: SAT, Interpolants and Software Model Checking

SAT solvers

• Solvers charactized by– Exhaustive BCP

– Conflict-driven learning (resolution)

– Deduction-based decision heuristics

DPLL

DP DLLvariableelimination

backtracksearch

SATO, GRASP,CHAFF,etc

Page 5: SAT, Interpolants and Software Model Checking

Lesson #1: Be Lazy• DP approach

– Eliminate variables by exhaustive resolution

– Extremely eager: deduces all facts about remaining variables

– Essentially quantifier elimination -- explodes.

• DPLL approach– Lazy: only resolves clauses when model search fails

– Resolution use as a form of failure generalization

• Learns general facts from model search failure

Implications:1. Make expensive deductions only when their relevance can be

justified. 2. Don't do quantifier elimination.

Page 6: SAT, Interpolants and Software Model Checking

Lesson #2: Be Eager• In a DPLL solver, we always close deduction under unit resolution (BCP) before

making a decision. – Guides decision making model search– Guides resolution steps in failure generalization– BCP updated after decision making and clause learning

Implications:1. Be eager with inexpensive deduction. 2. Deduce all the cheap facts before trying any expensive ones.3. Let the expensive deduction drive the cheap deduction

Page 7: SAT, Interpolants and Software Model Checking

Lesson #3: Learn from the Past• Facts useful in one particular case are likely to be useful in other cases.• This principle is embodied in

– Clause learning

– Deduction-based decision heuristics (e.g., VSIDS)

Implication: Deduce facts that have been useful in the past.

Page 8: SAT, Interpolants and Software Model Checking

Static Analysis• Compute the least fixed-point of an abstract transformer

– This is the strongest invariant the analysis can provide

• Inexpensive analyses:– value set analysis

– affine equalities, etc.

• These analyses lose information at a merge:

x = y x = z

T

Be eager with inexpensive deductions

Be lazy with expensive deductions X

Learn from the past N/A

Page 9: SAT, Interpolants and Software Model Checking

Predicate abstraction• Abstract transformer:

– strongest Boolean postcondition over given predicates

• Advantage: does not lose information at a merge– join is disjunction

x = y x = z

x=y Ç x=z• Disadvantage:

– Abstract post is very expensive!

– Computes information about predicates with no relevance justification

Be eager with inexpensive deductions X

Be lazy with expensive deductions X

Learn from the past N/A

Page 10: SAT, Interpolants and Software Model Checking

PA with CEGAR loop

Model checkabstraction T#

Choose initial T#

Can extend Cexfrom T# to T?

Add predicatesto T#

true, done

Cex

yes, Cex

no

• Choose predicates to refute cex's– Generalizes failures

– Some relevance justification

• Still performs expensive deduction without justification– strongest Boolean postcondition

• Fails to learn from past– Start fresh each iteration

– Forgets expensive deductions

Be eager with inexpensive deductions X

Be lazy with expensive deductions X+

Learn from the past X

Page 11: SAT, Interpolants and Software Model Checking

Boolean Programs• Abstract transformer

– Weaker than predicate abstraction

– Evaluates predicates independently -- loses correlations

{T} x=y; {x=0 , y=0}

Predicate abstraction

{T} x=y; {T}

Boolean programs

• Advantages– Computes less expensive information eagerly

– Disadvantages

– Still computes expensive information without justification

– Still uses CEGAR loop

Be eager with inexpensive deductions X

Be lazy with expensive deductions X++

Learn from the past X

Page 12: SAT, Interpolants and Software Model Checking

Lazy Predicate Abstraction• Unwind the program CFG into a tree

– Refine paths as needed to refute errors

ERR!

x=y

x=y

y=0

Add predicates along pathto allow refutation of error

• Refinement is local to an error path• Search continues after refinement

– Do not start fresh -- no big CEGAR loop

• Previously useful predicates applied to new vertices

Page 13: SAT, Interpolants and Software Model Checking

Lazy Predicate Abstraction

ERR!

x=y

x=y

y=0

Add predicates along pathto allow refutation of error

• Refinement is local to an error path• Search continues after refinement

– Do not start fresh -- no big CEGAR loop

• Previously useful predicates applied to new vertices

Be eager with inexpensive deductions X

Be lazy with expensive deductions -

Learn from the past

Page 14: SAT, Interpolants and Software Model Checking

SAT-based BMC

• Inherits all the properties of SAT• Deduction limited to propositional logic

– Cannot directly infer facts like x · y– Inexpensive deduction limited to BCP

ProgramLoop

UnwindingConvert toBit Level

SAT

Be eager with inexpensive deductions --

Be lazy with expensive deductions

Learn from the past

Page 15: SAT, Interpolants and Software Model Checking

SAT-based with Static Analysis

• Allows richer class of inexpensive deductions

• Inexpensive deductions not updated after decisions and clause learning– Coupling could be tighter

– Perhaps using lazy decision procedures?

ProgramLoop

UnwindingConvert toBit Level

SATStatic

Analysis

x=y; x=z;

x=z

decision

Be eager with inexpensive deductions -

Be lazy with expensive deductions

Learn from the past

Page 16: SAT, Interpolants and Software Model Checking

Lazy abstraction and interpolants• A way to apply the lessons of SAT to lazy abstraction• Keep the advantages of lazy abstraction...

– Local refinement (be lazy)

– No "big loop" as in CEGAR (learn from the past)

• ...while avoiding the disadvantages of predicate abstraction...– no eager image computation

• ...and propagating inexpensive deductions eagerly– as in static analysis

Page 17: SAT, Interpolants and Software Model Checking

Interpolation Lemma• Notation: L() is the set of FO formulas over the symbols of • 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

• Interpolants from proofs– in certain quantifier-free theories, we can obtain an interpolant for a

pair A,B from a refutation in linear time. [McMillan 05]

– in particular, we can have linear arithmetic,uninterpreted functions, and restricted use of arrays

(Craig,57)

Page 18: SAT, Interpolants and Software Model Checking

Interpolants for sequences• Let A1...An be a sequence of formulas

• A sequence A’0...A’n is an interpolant for A1...An when

– A’0 = True

– A’i-1 Æ Ai ) A’i, for i = 1..n

– An = False

– and finally, A’i 2 L (A1...Ai) Å L(Ai+1...An)

A1 A2 A3 Ak...

A'1 A'2 A'3 A'k-1...True False) ) ) )

In other words, the interpolant is a structured

refutation of A1...An

Page 19: SAT, Interpolants and Software Model Checking

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

Path refinement procedure

SSAsequence Prover

Interpolation

PathRefinement

proof structuredproof

x=y;

y++;

[x=y]

x1= y0

y1=y0+1

x1y1

Page 20: SAT, Interpolants and Software Model Checking

Lazy abstraction -- 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 21: SAT, Interpolants and Software Model Checking

1

L=0

T2

[L!=0]T

Unwinding the CFG

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

Page 22: SAT, Interpolants and Software Model Checking

6[L!=0]T

5

[new!=old]

T

4

L=0; new++

T

3

L=1;old=new

T

Unwinding the CFG

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

Covering: state 5 is subsumed bystate 1.

Page 23: SAT, Interpolants and Software Model Checking

T

11[L!=0]

T

10

[new!=old]

T

8

T

Unwinding the CFG

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

Page 24: SAT, Interpolants and Software Model Checking

Covering step• If (x) ) (y)...

– add covering arc x B y

– remove all z B w for w descendant of y

x· y x=y

X

We restict covers to be descending in a suitable total order on vertices.This prevents covering from diverging.

Page 25: SAT, Interpolants and Software Model Checking

Refinement step• Label an error vertex False by refining the path to that vertex with an interpolant for that path.

• By refining with interpolants, we avoid predicate image computation.

T

T

TT

T

T

T

x = 0

[x=y] [xy]

y++

[y=0]

y=2

x=0

y=0

y0

F

X

Refinement may remove covers

Page 26: SAT, Interpolants and Software Model Checking

Forced cover• Try to refine a sub-path to force a cover

– show that path from nearest common ancestor of x,y proves (x) at y

T

T

TT

T

T

T

x = 0

[x=y] [xy]

y++

[y=0]

y=2

x=0

y=0

y0

F

refine this path

y0

Forced cover allow us to efficiently handle nested control structure

Page 27: SAT, Interpolants and Software Model Checking

T

[x=z] [xz]

y=1 y=2

y2{1,2}

[y=1Æ xz]

Incremental static analysis• Update static analysis of unwinding incrementally

– Static analysis can prevent many interpolant-based refinements

– Interpolant-based refinements can refine static analysis

T

T

TT

T

T

T

x = 0

[x=y] [xy]

y++

[y=0]

y=2

x=0

y=0

y0

F

y=2

from valueset analysis

x=z

x=z

F

refine thispath

y=2

value setrefined

Page 28: SAT, Interpolants and Software Model Checking

Applying the lessons from SAT• Be lazy with epensive deductions

– All path refinements justified

– No eager predicate image computation

• Be eager with inexpensive deductions– Static anlalysis updated after all changes

– Refinement and static analysis interact

• Learn from the past– Refinements incremental – no “big CEGAR loop”

– Re-use of historically useful facts by forced covering

Page 29: SAT, Interpolants and Software Model Checking

Experiments• Windows device driver benchmarks from BLAST benchmark suite

– programs flattened to "simple goto programs"

• Compare performance against BLAST, a lazy predicate abstraction tool• No static analysis.

name source

LOC

SGP

LOC

BLAST

(s)

IMPACT

(s)

BLAST

IMPACT

kbfiltr 12K 2.3K 26.3 3.15 8.3

diskperf 14K 3.9K 102 20.0 5.1

cdaudio 44K 6.3K 310 19.1 16.2

floppy 18K 8.7K 455 17.8 25.6

parclass 138K 8.8K 5511 26.2 210

parport 61K 13K 8084 37.1 224

Almost all BLAST time spent in predicate image operation.

Page 30: SAT, Interpolants and Software Model Checking

The Saga Continues• After these results, Ranjit Jhala modified BLAST

– vertices inherit predicates from their parents, reducing refinements– fewer refinements allows more predicate localization

• Impact also made more eager, using value set analysis

name source

LOC

SGP

LOC

BLAST

(s)

IMPACT

(s)

BLAST

IMPACT

kbfiltr 12K 2.3K 11.9 0.35 34

diskperf 14K 3.9K 117 2.37 49

cdaudio 44K 6.3K 202 1.51 134

floppy 18K 8.7K 164 4.09 41

parclass 138K 8.8K 463 3.84 121

parport 61K 13K 324 6.47 50

Page 31: SAT, Interpolants and Software Model Checking

Conclusions• Caveats

– Comparing different implementations is dangerous

– More and better software model checking benchmarks are needed

• Tentative conclusions– For control-dominated codes, predicate abstraction is too "eager“

• better to be more lazy about expensive deductions

– Propagate inexpensive deductions can produce substantial speedup

• roughly one order of magnitude for Windows examples

– Perhaps by applying the lessons of SAT, we can obtain the same kind of rapid performance improvements obtained in that area

• Note 2-3 orders of magnitude speedup in lazy model checking in 6 months!

Page 32: SAT, Interpolants and Software Model Checking

Future work• Procedure summaries

– Many similar subgraphs in unwinding due to procedure expansions

– Cannot handle recursion

– Can we use interpolants to compute approximate procedure summaries?

• Quantified interpolants– Can be used to generate program invariants with quantifiers

– Works for simple examples, but need to prevent number of quantifiers from increasing without bound

• Richer theories– In this work, all program variables modeled by integers

– Need an interpolating prover for bit vector theory

• Concurrency...

Page 33: SAT, Interpolants and Software Model Checking

Unwinding the CFG• An unwinding is a tree with an embedding in the CFG

L=0

L=1; old=new

[L!=0]

L=0; new++

[new==old]

[new!=old]

8

0

12

3

4

L=0

L=1;old=new

[L!=0]

L=0; new++

Mv

Me

Page 34: SAT, Interpolants and Software Model Checking

Expansion• Every non-leaf vertex of the unwinding must be fully expanded...

L=00

1

L=0

Mv

Me

If this is not a leaf...

...and this exists... ...then this exists.

...but we allow unexpanded leaves (i.e., we are building afinite prefix of the infinite unwinding)

Page 35: SAT, Interpolants and Software Model Checking

Labeled unwinding• A labeled unwinding is equiped with...

– a lableing function : V ! L(S)

– a covering relation B µ V £ V

0

12

3

4

5

L=0

L=1;old=new

[L!=0]

L=0; new++

[new!=old]

6[L!=0]

7

[new==old]

T

F L=0

F L=0

L=0

T

T

These two nodes are covered.

(have a ancestor at the tail of a covering arc)

...

...

Page 36: SAT, Interpolants and Software Model Checking

Well-labeled unwinding• An unwinding is well-labeled when...

– () = True

– every edge is a valid Hoare triple

– if x B y then y not covered

0

12

3

4

5

L=0

L=1;old=new

[L!=0]

L=0; new++

[new!=old]

6[L!=0]

7

[new==old]

T

F L=0

F L=0

L=0

T

T

Page 37: SAT, Interpolants and Software Model Checking

Safe and complete• An unwinding is

– safe if every error vertex is labeled False– complete if every nonterminal leaf is covered

T

10[L!=0]

T

9

[new!=old]

T

8

T

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

... ...

Theorem: A CFG with a safe complete unwinding is safe.

9T

Page 38: SAT, Interpolants and Software Model Checking

Unwinding steps• Three basic operations:

– Expand a nonterminal leaf

– Cover: add a covering arc

– Refine: strengthen labels along a path so error vertex labeled False

Page 39: SAT, Interpolants and Software Model Checking

Overall algorithm1. Do as much covering as possible

2. If a leaf can't be covered, try forced covering

3. If the leaf still can't be covered, expand it

4. Label all error states False by refining with an interpolant

5. Continue until unwinding is safe and complete