Top Banner
Proofs and Counterexamples Rupak Majumdar
97

Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure yes no.

Dec 16, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Proofs and Counterexamples

Rupak Majumdar

Page 2: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

In the good old days…

DecisionProcedure

yes

no

Page 3: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Now…

Sooh, short answer: yes with an if, long answer, no with a but. –Reverend Lovejoy

DecisionProcedure

yes

no

Interpolant + , -

ModelPredicate Abstraction

Boolean SAT

Pre-Process

Proof

InvariantGeneration

Page 4: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

It’s the Application!

• Validating large scale software w.r.t. partial specifications

• Rules in documentation–Order of operations & data

access–Resource management –Incomplete, unenforced, wordy

• Violated rules ) bad behavior–System crash or deadlock–Unexpected exceptions–Failed runtime checks

Page 5: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Property: Double Locking

“An attempt to re-acquire an acquired lock or release a released lock will cause a deadlock.”

Calls to lock and unlock must alternate.

lock

lock

unlock

unlock

Page 6: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Example

Example ( ) {1: do{ lock(); old = new;

q = q->next;2: if (q != NULL){3: q->data = new;

unlock(); new ++; }4: } while(new != old);5: unlock (); return;}

Example ( ) {1: do{ lock(); old = new;

q = q->next;2: if (q != NULL){3: q->data = new;

unlock(); new ++; }4: } while(new != old);5: unlock (); return;}

lock

lock

unlock

unlock

Does program Example satisfy the locking spec?

Page 7: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Ok, but what does this have to do with

DecisionProcedure

yes

noDecision

Procedure

yes

no

Interpolant

+ , -

ModelPredicate Abstraction

Boolean SAT

Pre-Process

Proof

InvariantGeneration

vs

Page 8: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Automatic Verification of Programs

Search

Refine

Program

Safe

Trace

Yes

NoPropert

y

[POPL 02]

[POPL 04]

AutomaticTool

Model and analyze program behavior in the language of logic, reduce reasoning about programs to reasoning about logic

Page 9: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

What a program really is…

State Transition

3: unlock(); new++;4:} …

3: unlock(); new++;4:} …

pclockoldnewq

3 5 5 0x133a

pclockoldnewq

4 5 6 0x133a

Example ( ) {1: do{ lock(); old = new;

q = q->next;2: if (q != NULL){3: q->data = new;

unlock(); new ++; }4: } while(new != old);5: unlock (); return;}

Example ( ) {1: do{ lock(); old = new;

q = q->next;2: if (q != NULL){3: q->data = new;

unlock(); new ++; }4: } while(new != old);5: unlock (); return;}

Page 10: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

The Safety Verification Problem

Initial

Error

Is there a path from an initial to an error state ?

Problem: Infinite state graphSolution : Set of states ' logical formula

Safe

Page 11: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Representing States as Formulas

[F]states satisfying F {s | s ²

F }

FFO fmla over prog. vars

[F1] Å [F2] F1 Æ F2

[F1] [ [F2] F1 Ç F2

[F] : F

[F1] µ [F2] F1 implies F2i.e. F1Æ: F2

unsatisfiable

Page 12: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Idea 1: Symbolic Analysis

Initial

Error

Program State Space

1. Given F, and a program operation, describe a formula for the set of successor states

“Strongest postcondition”

2. Iterate the SP, checking at each stage if Error is hit, or if new states are added

Page 13: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Idea 1: Symbolic Analysis

Iterate the SP, checking at each stage if Error is hit, or if new states are added

CurrentReach Æ Error

is unsat

OldReach Ç SP(OldReach) CurrentReach

Problem: Too many details trackedSymbolic Iteration may not terminate

Page 14: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Idea 1’: Symbolic Analysis + AnnotationsAsk programmer for Invariant

CheckInvariant does not hit Error , and

Invariant is closed under SP

Invariant Æ Error is unsat

Invariant Ç SP(Invariant) Invariant

No more iterations: Programmer provides aninductive assertion, just make two queries

Problem: Increased work for the programmer

Page 15: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Idea 2: Predicate Abstraction

Initial

Error

Program State Space

• Abstraction: Predicates on program state– Signs: x > 0– Aliasing: &x &y

• States satisfying the same preds are equivalent– Merged into single abstract state

Abstraction [Graf-Saidi 97]

Page 16: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Example: Predicate Abstraction

For the red region above, the predicate abstraction is the set of “boxes” that cover the red region

For each small box , ask the theorem prover if Æ is satisfiable

Page 17: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

• Search finite state space symbolically• Conservative

– Abstraction safe ) System safe – Too coarse ) spurious

counterexample

Abstract

Idea 2: Predicate Abstraction

Page 18: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

1. Feasible ) BUG

Abstract Counterexamples:

Analyze counterexamplesto check feasibility

Idea 3: Counterexample Analysis

Get satisfying assignmentfrom decision procedure: test demonstrating bug

Page 19: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

1. Feasible ) BUG2. Infeasible ) What

predicates distinguish states across cut?

3. Build refined abstraction

Abstract Counterexamples:

Analyze counterexamplesto check feasibility

Idea 3: Counterexample Analysis

Page 20: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Idea 3: Counterex.-Guided Refinement

Abstract

Refine

• Add predicates to rule out spurious trace

• Repeat reachability– Till safe or real trace is found– Or go on refining forever

[Kurshan et al. 93][Clarke et al. 00][Ball-Rajamani 01]

Page 21: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

safe

Abstract

Refine

Idea 3: Counterex.-Guided Refinement

• Add predicates to rule out spurious trace

• Repeat reachability– Till safe or real trace is found– Or go on refining forever

Page 22: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Problem: Abstraction is Expensive

Reachable

Problem#abstract states =

2#predicates

Exponential Thm. Prover queries

ObserveFraction of state space reachable#Preds ~ 100’s, #States ~ 2100 ,#Reach ~ 1000’s

Page 23: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Solution1: Only Abstract Reachable States

SolutionBuild abstraction on-the-

fly,during search

Problem#abstract states =

2#predicates

Exponential Thm. Prover queries

Page 24: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

SolutionBuild abstraction on-the-

fly,during search

Problem#abstract states =

2#predicates

Exponential Thm. Prover queries

Solution1: Only Abstract Reachable States

Page 25: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

SolutionBuild abstraction on-the-

fly,during search

Problem#abstract states =

2#predicates

Exponential Thm. Prover queries

Solution1: Only Abstract Reachable States

Page 26: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Safe

SolutionBuild abstraction on-the-

fly,during search

Problem#abstract states =

2#predicates

Exponential Thm. Prover queries

Solution1: Only Abstract Reachable States

Page 27: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Key Idea: Reachability Tree

5

1

2

3

4

3

Unroll Abstraction1. Pick tree-node (=abs. state)2. Add children (=abs.

successors)3. On re-visiting abs. state, cut-

offCounterexample

Analysis- Learn new predicates locally- Rebuild subtree with new

predicates

“Lazy Abstraction”

Initial

[HenzingerJhalaM.Sutre02]

Page 28: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Build-and-Search

Predicates: LOCK

: LOCK

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

1

1

Reachability Tree

Page 29: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Build-and-Search

Predicates: LOCK

: LOCK

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

1

1

lock()old = newq=q->next LOCK2

2

Reachability Tree

Page 30: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Build-and-Search

Predicates: LOCK

: LOCK

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

1

1

LOCK2

2

LOCK

[q!=NULL]

3

3

Reachability Tree

Page 31: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Build-and-Search

Predicates: LOCK

: LOCK

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

1

1

LOCK2

2

LOCK3

3

q->data = newunlock()new++

4

4

: LOCK

Reachability Tree

Page 32: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Build-and-Search

Predicates: LOCK

: LOCK

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

1

1

LOCK2

2

LOCK3

3

4

4

: LOCK

: LOCK

[new==old]

55

Reachability Tree

Page 33: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Build-and-Search

Predicates: LOCK

: LOCK

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

1

1

LOCK2

2

LOCK3

3

4

4

: LOCK

: LOCK55

unlock()

: LOCK

Reachability Tree

Page 34: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Analyze Counterexample

Predicates: LOCK

: LOCK

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

1

1

LOCK2

2

LOCK3

3

4

4

: LOCK

: LOCK55

: LOCK

Reachability Tree

lock()old = newq=q->next

[q!=NULL]

q->data = newunlock()new++

[new==old]

unlock()

Page 35: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Analyze Counterexample

Predicates: LOCK

: LOCK

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

1

1

LOCK2

2

LOCK3

3

4

4

: LOCK

: LOCK55

: LOCK

[new==old]

new++

old = new

Inconsistent

new == oldReachability Tree

Page 36: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Repeat Build-and-Search

Predicates: LOCK, new==old

: LOCK

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

1

1

Reachability Tree

Page 37: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Repeat Build-and-Search

Predicates: LOCK, new==old

: LOCK

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

1

1

LOCK , new==old

2

2

lock()old = newq=q->next

Reachability Tree

Page 38: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Repeat Build-and-Search

Predicates: LOCK, new==old

: LOCK

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

1

1

LOCK , new==old

2

2

LOCK , new==old

3

3

4

4

q->data = newunlock()new++

: LOCK , : new = old

Reachability Tree

Page 39: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Repeat Build-and-Search

Predicates: LOCK, new==old

: LOCK

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

1

1

LOCK , new==old

2

2

LOCK , new==old

3

3

4

4

: LOCK , : new = old

[new==old]

Reachability Tree

Page 40: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Repeat Build-and-Search

Predicates: LOCK, new==old

: LOCK

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

1

1

LOCK , new==old

2

2

LOCK , new==old

3

3

4

4

: LOCK , : new = old

: LOCK, : new == old

1

[new!=old]

4

Reachability Tree

Page 41: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Repeat Build-and-Search

Predicates: LOCK, new==old

: LOCK

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

1

1

2

2

3

3

4

4

1

4

LOCK , new=old

4

4

: LOCK , new==old

55

SAFE

Reachability Tree

LOCK , new==old

LOCK , new==old

: LOCK , : new = old

: LOCK, : new == old

Page 42: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

BLAST

Abstract

Refine

C Program

Safe

Trace

Yes

NoPropert

y

[HenzingerJhalaM.Sutre02]

Page 43: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Scaling BLAST

Abstract

Refine

C Program

Safe

Trace

Yes

NoPropert

y

To find: 1. Which predicates to track? 2.Where to track them?

Key Problem: Find good predicates

Page 44: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Tracking lock not enough

#Predicates grows with program size

Problem:p1,…,pn needed for verification

Exponential reachable abstract states

while(1){1: if (p1) lock() ; if (p1) unlock() ; …2: if (p2) lock() ; if (p2) unlock() ; … n: if (pn) lock() ; if (pn) unlock() ;}

while(1){1: if (p1) lock() ; if (p1) unlock() ; …2: if (p2) lock() ; if (p2) unlock() ; … n: if (pn) lock() ; if (pn) unlock() ;}

TF

T

Page 45: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

#Predicates grows with program size

Problem:p1,…,pn needed for verification

Exponential reachable abstract states

while(1){1: if (p1) lock() ; if (p1) unlock() ; …2: if (p2) lock() ; if (p2) unlock() ; … n: if (pn) lock() ; if (pn) unlock() ;}

while(1){1: if (p1) lock() ; if (p1) unlock() ; …2: if (p2) lock() ; if (p2) unlock() ; … n: if (pn) lock() ; if (pn) unlock() ;}

: LOCK

: LOCK, p1

p1p2

p1: p2 : p1 p2 : p1: p2

LOCK, p1 : LOCK, : p1

: LOCK, : p1

2n Abstract States

: LOCK

Page 46: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Predicates useful locally

while(1){1: if (p1) lock() ; if (p1) unlock() ; …2: if (p2) lock() ; if (p2) unlock() ; … n: if (pn) lock() ; if (pn) unlock() ;}

while(1){1: if (p1) lock() ; if (p1) unlock() ; …2: if (p2) lock() ; if (p2) unlock() ; … n: if (pn) lock() ; if (pn) unlock() ;}

: LOCK

: LOCK , p1

LOCK , p1

: LOCK, : p1

: LOCK , : p1

2n Abstract States

p1

p2

pn

: LOCK : LOCK: LOCK

LOCK , p2 : LOCK , : p2

: LOCK

Solution: Use predicates only where needed

Page 47: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Predicates: LOCK, new==old

Refinement

Main Questions

: LOCK

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

1

1

2

2

3

3

4

4

1

4

LOCK , new=old

4

4

: LOCK , new==old

55

SAFE

LOCK , new==old

LOCK , new==old

: LOCK , : new = old

: LOCK, : new == old

Q. How to find good predicates ?Where to track each predicate?

Page 48: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Counterexample Traceslock()old = newq=q->next

[q!=NULL]

q->data = newunlock()new++

[new==old]

unlock()

Trace SSA Trace

lock1 = 1

old1 = new0

q1 = q0->next

assume(q1 != NULL)

(q1 -> data)1 = new0

lock2 = 0

new1 = new0 +1

assume(new1=old1)

assert(lock2=1)

Trace FeasibilityFormula

Thm: Trace is feasible , TF is satisfiable

lock1 = 1 Æ

old1 = new0 Æ

q1 = q0->next Æ

q1 != NULL Æ

(q1 -> data)1 = new0 Æ

lock2 = 0 Æ

new1 = new0 +1 Æ

new1=old1

Page 49: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Predicates: old=new, new=new+1, new=old

Proof of Unsatisfiability

old1 = new0 new1 = new0 + 1

new1 = old1+1 new1 = old1

;

Proof of Unsatisfiability

lock1 = 1 Æ

old1 = new0 Æ

q1 = q0->next Æ

q1 != NULL Æ

(q1 -> data)1 = new0 Æ

lock2 = 0 Æ

new1 = new0 +1 Æ

new1=old1

Trace FeasibilityFormula

Add: old=new

[HenzingerJhalaM.Sutre02]

Page 50: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Decision Procedure Must Produce Proofs

DecisionProcedure

yes

no

Boolean SAT

Sat asgn

Proof

Proofs important in other applications as well:e.g., Proof carrying code [Necula97,HenzingerJhalaM.NeculaSutreWeimer02]

Page 51: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Counterexample Traces: Take 2

1: x = ctr2: ctr = ctr + 13: y = ctr 4: assume(x = i-1)

5: assume(y i)

y = x +1

1: x = ctr;2: ctr = ctr + 1;3: y = ctr;4: if (x = i-1){5: if (y != i){

ERROR: }

}

1: x = ctr;2: ctr = ctr + 1;3: y = ctr;4: if (x = i-1){5: if (y != i){

ERROR: }

}

Page 52: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Trace Formulas

1: x = ctr

2: ctr = ctr+1

3: y = ctr

4: assume(x=i-1)

5: assume(yi)

Trace SSA Trace

x1 = ctr0

Æ ctr1 = ctr0+ 1

Æ y1 = ctr1

Æ x1 = i0 - 1

Æ y1 i0

1: x1 = ctr0

2: ctr1 = ctr0+1

3: y1 = ctr1

4: assume(x1=i0-1)

5: assume(y1i0)

Trace FeasibilityFormula

Page 53: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Proof of Unsatisfiability

Trace Formula

x1 = ctr0

Æ ctr1 = ctr0 + 1

Æ y1 = ctr1

Æ x1 = i0 - 1

Æ y1 i0

x1 = ctr0 x1 = i0 -1

ctr0 = i0-1 ctr1= ctr0+1

ctr1 = i0 y1= ctr1

y1= i0 y1 i0

;

Proof of Unsatisfiability

Page 54: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

The Present State…

1: x = ctr

2: ctr = ctr + 1

3: y = ctr

4: assume(x = i-1)

5: assume(y i)

Trace

… is all the information the executing program has here

1. … after executing trace past (prefix)

2. … knows present values of variables

3. … makes trace future (suffix) infeasible

State…

At pc4, which predicate on present state shows infeasibility of future ?

Page 55: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

What Predicate is needed ?

Trace

1: x = ctr

2: ctr = ctr + 1

3: y = ctr

4: assume(x = i-1)

5: assume(y i)

Trace Formula (TF)

x1 = ctr0

Æ ctr1 = ctr0 +1

Æ y1 = ctr1

Æ x1 = i0 - 1

Æ y1 i0

Page 56: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

What Predicate is needed ?

Trace

1: x = ctr

2: ctr = ctr + 1

3: y = ctr

4: assume(x = i-1)

5: assume(y i)

Trace Formula (TF)

x1 = ctr0

Æ ctr1 = ctr0+ 1

Æ y1 = ctr1

Æ x1 = i0 - 1

Æ y1 i0

1. … after executing trace prefix

Relevant Information

… implied by TF prefix

Predicate …

Page 57: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

1: x = ctr

2: ctr = ctr + 1

3: y = ctr

4: assume(x = i-1)

5: assume(y i)

1. … after executing trace prefix

2. … has present values of variables

What Predicate is needed ?

Trace Trace Formula (TF)

x1 = ctr0

Æ ctr1 = ctr0+ 1

Æ y1 = ctr1

Æ x1 = i0 - 1

Æ y1 i0

… implied by TF prefix

… on common variables

Predicate …

x1

x1

Relevant Information

y1

y1

Page 58: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

1: x = ctr

2: ctr = ctr + 1

3: y = ctr

4: assume(x = i-1)

5: assume(y i)

What Predicate is needed ?

Trace Trace Formula (TF)

x1 = ctr0

Æ ctr1 = ctr0+ 1

Æ y1 = ctr1

Æ x1 = i0 - 1

Æ y1 i0Predicate …

1. … after executing trace prefix

2. … has present values of variables

3. … makes trace suffix infeasible

… implied by TF prefix

… on common variables

… & TF suffix is unsatisfiable

Relevant Information

Page 59: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Interpolant = Predicate !

-

+Interpolat

e

Trace Formula

x1 = ctr0

Æ ctr1 = ctr0+ 1

Æ y1 = ctr1

Æ x1 = i0 - 1

Æ y1 i0

y1 = x1 + 1

Predicate …

… implied by TF prefix

… on common variables

… & TF suffix is unsatisfiable

Craig Interpolant[Craig 57]

Computable from Proof of Unsat

1: x = ctr

2: ctr = ctr + 1

3: y = ctr

4: assume(x = i-1)

5: assume(y i)

Trace

Predicate at 4:y= x+1

Page 60: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Another interpretation …

-

+Interpolat

e

Trace Formula

x1 = ctr0

Æ ctr1 = ctr0+ 1

Æ y1 = ctr1

Æ x1 = i0 - 1

Æ y1 i0

y1 = x1 + 1

Unsat = Empty Intersection = Trace Infeasible

Predicate at 4:y= x+1-

+

After execprefix

Canexecsuffix

Interpolant = Overapproximation of states after prefix

that cannot execute suffix

Page 61: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Predicates: LOCK, new==old

Refinement

Main Questions

: LOCK

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

1

1

2

2

3

3

4

4

1

4

LOCK , new=old

4

4

: LOCK , new==old

55

SAFE

LOCK , new==old

LOCK , new==old

: LOCK , : new = old

: LOCK, : new == old

Q. How to find good predicates ?Where to track each predicate?

Q: How to compute interpolants?(And do they always exist?)

Page 62: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Another Proof of Unsatisfiability

x1– ctr0=0 x1-i0 +1=0

ctr0-i0+1=0 ctr1- ctr0-1=0

ctr1-i0 =0 y1-ctr1=0

y1-i0=0 y1-i0 0

0 0

Rewritten Proof

£ 1£ (-1)

£ 1

£ 1

£ 1

x1 = ctr0 x1 = i0 -1

ctr0 = i0-1 ctr1= ctr0+1

ctr1 = i0 y1= ctr1

y1= i0 y1 i0

;

Proof of Unsatisfiability

Page 63: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Interpolant from Rewritten Proof ?

Trace Formula

x1 = ctr0

Æ ctr1 = ctr0 + 1

Æ y1 = ctr1

Æ x1 = i0 - 1

Æ y1 i0

x1– ctr0=0 x1-i0 +1=0

ctr0-i0+1=0 ctr1- ctr0-1=0

ctr1-i0 =0 y1-ctr1=0

y1-i0=0 y1-i0 0

0 0

Rewritten Proof

£ 1£ (-1)

£ 1

£ 1

£ 1

Interpolate

Page 64: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Interpolant from Rewritten Proof ?

Trace Formula

x1 = ctr0

Æ ctr1 = ctr0 + 1

Æ y1 = ctr1

Æ x1 = i0 - 1

Æ y1 i0

x1– ctr0=0

ctr1- ctr0-1=0

y1-ctr1=0

Interpolant !

£ (-1)

£ 1

£ 1

Interpolatey1-x1-1=0y1=x1+1

Page 65: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Building Predicate Maps

Trace Trace Formula

x1 = ctr0

Æ ctr1 = ctr0+ 1

Æ y1 = ctr1

Æ x1 = i0 - 1

Æ y1 i0• Cut + Interpolate at each point

• Pred. Map: pci Interpolant from cut i

-

+x1 = ctr0

Predicate Map 2: x= ctr

1: x = ctr

2: ctr = ctr + 1

3: y = ctr

4: assume(x = i-1)

5: assume(y i)

Interpolate

Page 66: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Building Predicate Maps

Trace Trace Formula

x1 = ctr0

Æ ctr1 = ctr0+ 1

Æ y1 = ctr1

Æ x1 = i0 - 1

Æ y1 i0

-

+

1: x = ctr

2: ctr = ctr + 1

3: y = ctr

4: assume(x = i-1)

5: assume(y i)

Predicate Map 2: x = ctr3: x= ctr-1

x1= ctr1-1Interpola

te

• Cut + Interpolate at each point

• Pred. Map: pci Interpolant from cut i

Page 67: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Building Predicate Maps

Trace Trace Formula

x1 = ctr0

Æ ctr1 = ctr0+ 1

Æ y1 = ctr1

Æ x1 = i0 - 1

Æ y1 i0

1: x = ctr

2: ctr = ctr + 1

3: y = ctr

4: assume(x = i-1)

5: assume(y i)

Predicate Map 2: x = ctr3: x= ctr - 14: y= x + 1

y1= x1+1

-

+Interpola

te

• Cut + Interpolate at each point

• Pred. Map: pci Interpolant from cut i

Page 68: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Building Predicate Maps

Trace Trace Formula

x1 = ctr0

Æ ctr1 = ctr0+ 1

Æ y1 = ctr1

Æ x1 = i0 - 1

Æ y1 i0

1: x = ctr

2: ctr = ctr + 1

3: y = ctr

4: assume(x = i-1)

5: assume(y i)

Predicate Map 2: x = ctr3: x= ctr - 14: y= x + 15: y = i

y1= i0

-

+Interpola

te

• Cut + Interpolate at each point

• Pred. Map: pci Interpolant from cut i

Page 69: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Local Predicate Use

Predicate Map 2: x = ctr3: x= ctr - 14: y= x + 15: y = i

Use predicates needed at location

• #Preds. grows with program size

• #Preds per location small

Local Predicate use

Ex: 2n states

Global Predicate use

Ex: 2n states

Verification scales …

Page 70: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

pc1: x1 = 3

pc2: assume (x1>0)

pc3: x3 = f1(x1)pc4: y2 = y1

pc5: y3 = f2(y2)

pc6: z2 = z1+1

pc7: z3 = 2*z2

pc8: return z3

pc9: return y3

pc10: x4 = x3+1

pc11: x5 = f3(x4)pc12: assume(w1<5)

pc13: return w1

pc14: assume x4>5

pc15: assume (x1=x3+2)

Traces with Procedure Calls

Trace Formula

i

Trace

i

pc1: x1 = 3

pc2: assume (x1>0)

pc3: x3 = f1(x1)pc4: y2 = y1

pc5: y3 = f2(y2)pc6: z2 = z1+1

pc7: z3 = 2*z2

pc8: return z3

pc9: return y3

pc10: x4 = x3+1

pc11: x5 = f3(x4)pc12: assume(w1<5)

pc13: return w1

pc14: assume x4>5

pc15: assume(x1=x3+2)

Page 71: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Interprocedural Analysis

Trace Formula

i

Trace

iRequire at each point i:

Scoped predicatesYES: Variables visible at iNO: Caller’s local variables

Find predicate needed at point

i

YES

NO

NO

Page 72: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Problems with Cutting

Trace Formula

i

Trace

i

-

+

Caller variables common to - and +

• Unsuitable interpolant: not well-scoped

Page 73: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Scoped Cuts

Trace Formula

i

Call begins

Trace

i

Page 74: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Scoped Cuts

-+

Trace Formula

i

Call begins

Trace

i

Predicate at pci = Interpolant from cut i

Page 75: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Common Variables

Formals

Current locals

Trace Formula

Predicate at pci = Interpolant from i-cut

i

Trace

i-+

Common Variables

Formals

Well-scoped

Page 76: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Question: When Do Interpolants Exist?• Craig’s Theorem guarantees

existence for first order logic

• But we are interpreting formulas over theories (arithmetic, theories of data structures)

Page 77: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

The Good News

• Interpolants always exist for recursively enumerable theories

– The proof is a simple application of compactness

• So: interpolants exist for Presburger arithmetic, sets with cardinality constraints, theory of lists, (quantifier-free) theory of arrays, multisets, …

Page 78: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

The Bad News

• “The proof is a simple application of compactness”

– May be algorithmically inefficient

– Daunting engineering task to construct interpolating decision procedure for each individual theory

Page 79: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

An Alternate Path: Reduction

• Want to compile formulas in a new theory to formulas in an old theory such that interpolation in the old theory imply interpolation in the new theory

• T reduces to R: can compile formulas in theory T to formulas in theory R– And use decision procedures for R to answer decision questions for T

• Technically: Given theories T and R, with Rµ T, a reduction is a computable map from T formulas to R formulas such that for any T-formula :

– and () are T-equivalent– is T-satisfiable iff () is R-satisfiable

Page 80: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Example: Theory of Sets

Theory of sets reduces to theory of equality with uninterpreted functions

x = y 8 e. e2 x , e2 yx=; 8 e.e xx=U 8 e.e2 xx={e} e2 x Æ 8 e’.e’2 x ) e = e’x=y[ z 8 e.e2 x, e2 y Ç e2 zx=yÅ z 8 e.e2 x, e2 y Æ e2 z

Page 81: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Reduction and Interpolation

- and + in Theory T

- and + in Theory R

Interpolant inTheory R as well as T

Quantifier-free interpolant

Reduction from T to R

Interpolate in R

Eliminate quantifiers in T or R

Page 82: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Reduction Theorem

• Interpolants for the theory of arrays, sets, and multisets can be computed by reduction to the combination theory of linear arithmetic and equality with uninterpreted functions

– We already have interpolating decision procedures for this latter theory

[KapurM.Zarba06]

Page 83: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Lazy Abstraction

Abstract

Refine

C Program

Safe

Trace

Yes

NoPropert

y

Refine TraceFeas

FormulaThm Pvr

Proof of Unsat

Pred. MapPC Preds.

Ctrex.Trace

Interpolate

Solution: Localize pred. use, find where preds. needed

Problem: #Preds grows w/ Program Size

Page 84: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

So far …Lazy Abstraction

• Predicates:– Abstract infinite program states

• Counterexample-guided Refinement:– Find predicates tailored to prog,

property1. Abstraction : Expensive

Reachability Tree

2. Refinement : Find predicates, use locations Proof of unsat of TF + Interpolation

Page 85: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

What the “decision procedure” must provide

DecisionProcedure

yes

no

Interpolant + , -

Boolean SAT

Sat asgn

Proof

Page 86: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Predicates: LOCK, new==old

Refinement

: LOCK

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

Example ( ) {1: do{ lock(); old = new; q = q->next;2: if (q != NULL){3: q->data = new; unlock(); new ++; }4:}while(new != old);5: unlock ();}

1

1

2

2

3

3

4

4

1

4

LOCK , new=old

4

4

: LOCK , new==old

55

SAFE

LOCK , new==old

LOCK , new==old

: LOCK , : new = old

: LOCK, : new == old

So how well does all this work?

Quite well, if the program and property are control-dominated

Not so well when data is involved…

Page 87: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Refinement Failure: Unrolling Loops

x = 0; y = 50;

while ( x<100 ) {

if ( x>=50 ) y = y+1;

x = x+1;

}

assert( y==100 );

• counterexample:x=0; y=50; x>=100; y==100refinement: x==0

• counterexample:x=0; y=50; x<100; x=x+1; x>=100; y==100refinement: x==1

• counterexample:x=0; y=50; x<100; x=x+1; x<100; x=x+1;

x>=100; y==100refinement: x==2

• ...

Page 88: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Refinement Failure: Unfolding Arrays

for (i=0; i<n; i++) {

a[i]=i;

}

for (j=0; j<n; j++) {

assert( a[j]==j );

}

• counterexample:i=0; i<n; a[i]=i; i++; i>=n;

j=0; j<n; a[j]!=jrefinement: a[0]==0

• counterexample:i=0; i<n; a[i]=i; i++; i<n; a[i]=i; i++; i>=n;

j=0; j<n; a[j]==j; j++; j<n; a[j]!=jrefinement: a[1]==1

• ...

Page 89: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

What went Wrong?

• Consider all unrolled counterexamples at once– Convergence of abstraction discovery

• Inspect families of counterexamples of unbounded length – Justification for unbounded universal

quantification

• Looking at one counterexample path at a time is too weak

[JhalaMcMillan05,JhalaMcMillan06]

Page 90: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Path Programs• Treat counterexamples as programs

– “Close” the loopsA

B

C

B

D

stmt1

stmt2

stmt3

stmt4

A

B C

D

stmt1stmt2

stmt3stmt4

counterexample pathpath program,contains loops, etc

[BeyerHenzingerM.Rybalchenko07]

Page 91: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Meaning of Path Programs

Path program ´ (Possibly unbounded) sets of counterexamples:

• Unbounded counterexamples

• Property-determined fragment of original program– Can be analyzed independently to find good

abstractions

Page 92: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Path Invariants

• Invariant for path programs ´ path invariant

• Abstraction refinement using path invariants

– Elimination of all counterexamples within path program

– Justification for unbounded quantification

Page 93: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Invariant Generation

• Given a path program, with a designated error location, find an invariant that demonstrates error is not reachable– Can scale: Reduced obligation to program

fragment– Outer model checking loop integrates path

invariants into program invariant

• Can use any technique• We use constraint-based invariant

generation [SankaranarayananSipmaManna04,BeyerHenzingerM.Rybalchenko07]

Page 94: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

What we need

DecisionProcedure

yes

no

Interpolant + , -

Model

Boolean SAT

Pre-Process

Proof

InvariantGeneration

Page 95: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Summary• Traditional distinctions between theorem proving, model

checking, and dataflow analysis are getting blurred

• Is Blast a state space exploration engine with a theorem proving subroutine?

• A theorem prover with a model checking tactic?• An abstract interpreter with a rich and variable domain?

• It is all of the above, and none of the above– The distinctions are mostly of historical interest– New algorithms are re-shaping the way we think about, and build, tools

Page 96: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

More generally…

• What does it take to get verified software?– Blast is a small part in the whole process– How can we make the programmer’s job

easier, through a combination of • Language support• Process support• Tool support• Debugging and visualization support?

– How can we write software so that it is verifiable?

Page 97: Proofs and Counterexamples Rupak Majumdar. In the good old days… Decision Procedure  yes no.

Acknowledgments

Dirk BeyerTom HenzingerRanjit JhalaDeepak KapurKen McMillanAndrey RybalchenkoGregoire SutreCalogero Zarba