software verification using predicate abstraction and iterative refinement: part 1

36
© 2006 Carnegie Mellon University Software Verification using Predicate Abstraction and Iterative Refinement: Part 1 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki November 28, 2011

Upload: oya

Post on 21-Jan-2016

49 views

Category:

Documents


0 download

DESCRIPTION

Software Verification using Predicate Abstraction and Iterative Refinement: Part 1. 15-414 Bug Catching: Automated Program Verification and Testing Sagar Chaki November 28, 2011. Outline. Overview of Model Checking Creating Models from C Code: Predicate Abstraction - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

© 2006 Carnegie Mellon University

Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

15-414 Bug Catching: Automated Program Verification and Testing

Sagar ChakiNovember 28, 2011

Page 2: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

2Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Outline

Overview of Model Checking

Creating Models from C Code: Predicate Abstraction

Eliminating spurious behaviors from the model: Abstraction Refinement

Concluding remarks : research directions, tools etc.

Page 3: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

3Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Model Checking

Algorithm for answering queries about behaviors of state machines

• Given a state machine M and a query does M ² ?

Standard formulation:

• M is a Kripke structure

• is a temporal logic formula

— Computational Tree Logic (CTL)

— Linear Temporal Logic (LTL)

Discovered independently by Clarke & Emerson and Queille & Sifakis in the early 1980’s

Page 4: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

4Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Scalability of Model Checking

Explicit statespace exploration: early 1980s

• Tens of thousands of states

Symbolic statespace exploration: millions of states

• Binary Decision Diagrams (BDD) : early 1990’s

• Bounded Model Checking: late 1990’s

— Based on propositional satisfiability (SAT) technology

Abstraction and compositional reasoning

• 10120 to effectively infinite statespaces (particularly for software)

Page 5: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

5Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Models of C Code

if (x) {

y = x;

} else {

y = x + 1;

}

assert (y);

Program: Syntax Control Flow Graph

y = x + 1

if (x)

y = x

no yes

assert (y)

Model: Semantics

x=1 y=0

x=1 y=1

x=0 y=0

x=0 y=0

x=0 y=1

x=1 y=0

Infinite State

Page 6: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

6Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Existential Abstraction

Partition concrete statespace into abstract states

• Each abstract state S corresponds to a set of concrete states s

• We write (s) to mean the abstract state corresponding to s

• We define (S) = { s | S = (s) }

Fix the transitions existentially

• S ! S’ , 9 s 2 (S) . 9 s’ 2 (S’) . s ! s’

• S ! S’ ( 9 s 2 (S) . 9 s’ 2 (S’) . s ! s’

Existential Abstraction is conservative [ClarkeGrumbergLong94]

• If a ACTL* property holds on the abstraction, it also holds on the program

• LTL is a subset of ACTL*

• However, the converse is not true: a property that fails on the abstraction may still hold on the program

• Existential abstraction can be viewed as a form of abstract interpretation

Strong & sometimes not computable

Weak: computable

Page 7: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

7Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Example of Existential Abstraction

2

1

3

6

5

4

9

7

10

8

Concrete State

Concrete Transition

Abstract State

Abstract Transition

Abstractly and Concretely Unreachable

Abstractly Reachable but

Concretely Unreachable

Concrete Initial State

Abstract Initial State

Page 8: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

8Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Example of Existential Abstraction

p

Concrete State

Concrete Transition

Abstract State

Abstract Transition

Abstractly and Concretely Unreachable

Abstractly Reachable but

Concretely Unreachable

G(: p)G(: p)

Page 9: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

9Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Predicate Abstraction

y = x + 1

if (x)

y = x

no yes

assert (y)

Partition the statespace based on values of a finite set of predicates on program variables

Page 10: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

10Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Predicate Abstraction

y = x + 1

if (x)

y = x

no yes

assert (y)

P ( y == 0 )

:P

States where y 0

P

States where y = 0

ERROR

= G(: ERROR) = G(: ERROR)

Page 11: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

11Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Predicate Abstraction

y = x + 1

if (x)

y = x

no yes

assert (y)

P ( y == 0 )

:P

States where y 0

P

States where y = 0

ERROR

Call SAT Checker

Page 12: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

12Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Predicate Abstraction

y = x + 1

if (x)

y = x

no yes

assert (y)

P ( y == 0 )

:P

States where y 0

x=0 y=1

x=0 y=1

SAT Checker Query:

y 0

x = 0

x’ = x

y’ = y

y’ 0

SAT Checker Answer:

SAT and here’s a solution

x=0, y=1, x’=0, y’=1

Page 13: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

13Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Predicate Abstraction

y = x + 1

if (x)

y = x

no yes

assert (y)

P ( y == 0 )

:P

States where y 0

x=1 y=1

x=1 y=1

SAT Checker Query:

y 0

x 0

x’ = x

y’ = y

y’ 0

SAT Checker Answer:

SAT and here’s a solution

x=1, y=1, x’=1, y’=1

Page 14: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

14Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Predicate Abstraction

y = x + 1

if (x)

y = x

no yes

assert (y)

P ( y == 0 )

:P

States where y 0

x=1 y=1

x=1 y=2

SAT Checker Query:

y 0

x’ = x

y’ = x+1

y’ 0

SAT Checker Answer:

SAT and here’s a solution

x=1, y=1, x’=1, y’=2

Page 15: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

15Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Predicate Abstraction

y = x + 1

if (x)

y = x

no yes

assert (y)

P ( y == 0 )

:P

States where y 0

x=1 y=1

x=1 y=1

SAT Checker Query:

y 0

x’ = x

y’ = x

y’ 0

SAT Checker Answer:

SAT and here’s a solution

x=1, y=1, x’=1, y’=1

Page 16: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

16Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Predicate Abstraction

y = x + 1

if (x)

y = x

no yes

assert (y)

P ( y == 0 )

:P

States where y 0

P

States where y = 0

ERROR

No predicates about x

Page 17: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

17Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Imprecision due to Predicate Abstraction

Counterexamples generated by model checking the abstract model may be spurious, i.e., not concretely realizable

Need to refine the abstraction iteratively by changing the set of predicates

Can infer new set of predicates by analyzing the spurious counterexample

• Lot of research in doing this effectively

• Counterexample Guided Abstraction Refinement (CEGAR)

• A.K.A. Iterative Abstraction Refinement

• A.K.A. Iterative Refinement

Page 18: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

18Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Model Checking

y = x + 1

if (x)

y = x

no yes

assert (y)

P ( y == 0 )

: P P

ERROR

= G(: ERROR)

Page 19: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

19Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Model Checking

y = x + 1

if (x)

y = x

no yes

assert (y)

P ( y == 0 )

: P P

ERROR

= G(: ERROR)

Page 20: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

20Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Model Checking

if (x)

y = x

yes

assert (y)

P ( y == 0 )

: P P

ERROR

Page 21: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

21Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Counterexample Validation

if (x)

y = x

yes

assert (y)

• Simulate counterexample symbolically

• Call SAT Checker to determine if

the post-condition is satisfiable

• In our case, Counterexample is spurious

• New set of predicates {x==0,y==0}

Page 22: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

22Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Counterexample Validation

if (x)

y = x

yes

assert (y)

SAT Checker Query:

x 0

y’ = x

y’ = 0

SAT Checker Answer:

UNSAT and here’s an UNSAT core

{x 0 , y’ = x , y’ = 0}

• Used to derive new predicate (x=0)

• Different heuristics used in practice

Page 23: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

23Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Predicate Abstraction: 2nd Iteration

y = x + 1

if (x)

y = x

no yes

assert (y)

P ( x == 0 ) Q ( y == 0 )

:P :Q

x 0 y 0

:P Q P :Q P Q

X = 0 y = 0

Page 24: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

24Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Predicate Abstraction: 2nd Iteration

y = x + 1

if (x)

y = x

no yes

assert (y)

P ( x == 0 ) Q ( y == 0 )

:P :Q

x 0 y 0

ERROR

:P Q P :Q P Q

X = 0 y = 0

ERROR

Page 25: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

25Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Predicate Abstraction: 2nd Iteration

y = x + 1

if (x)

y = x

no yes

assert (y)

P ( x == 0 ) Q ( y == 0 )

x 0 y 0

ERROR

X = 0 y = 0

ERROR

:P :Q :P Q P :Q P Q

Page 26: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

26Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Predicate Abstraction: 2nd Iteration

y = x + 1

if (x)

y = x

no yes

assert (y)

P ( x == 0 ) Q ( y == 0 )

x 0 y 0

ERROR

X = 0 y = 0

ERROR

:P :Q :P Q P :Q P Q

Page 27: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

27Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Predicate Abstraction: 2nd Iteration

y = x + 1

if (x)

y = x

no yes

assert (y)

x 0 y 0

ERROR

X = 0 y = 0

ERROR

P ( x == 0 ) Q ( y == 0 )

:P :Q :P Q P :Q P Q

Page 28: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

28Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Predicate Abstraction: 2nd Iteration

y = x + 1

if (x)

y = x

no yes

assert (y) ERRORERROR

x 0 y 0

X = 0 y = 0P ( x == 0 ) Q ( y == 0 )

:P :Q :P Q P :Q P Q

Page 29: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

29Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Model Checking: 2nd Iteration

y = x + 1

if (x)

y = x

no yes

assert (y) ERRORERROR

= G(: ERROR)

SUCCESS

P ( x == 0 ) Q ( y == 0 )

:P :Q :P Q P :Q P Q

Page 30: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

30Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Iterative Refinement: Summary

Choose an initial set of predicate, and proceed iteratively as follows:

1. Abstraction: Construct an abstract model M of the program using the predicate abstraction

2. Verification: Model check M. If model checking succeeds, exit with success. Otherwise, get counterexample CE.

3. Validation: Check CE for validity. If CE is valid, exit with failure.

4. Refinement: Otherwise, update the set of predicates and repeat from Step 1.

Page 31: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

31Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Iterative Refinement

Software Model Checking, SLAM

Project, Microsoft, Ball & Rajamani

Counterexample-guided Abstraction

Refinement for Symbolic Model

Checking, Clarke et al., CMU

Localization Reduction, Kurshan,

Bell LabsPredicate

AbstractionModel Checking

Predicate Refinement

Counterexample Valid?

Abstract Model

Candidate Counter-example

Better Predicates

Program

Initial Predicates

No

No

Yes

Yes

System OK

Problem Found

SAT Checker

Page 32: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

32Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Predicate Abstraction: Optimizations

1. Construct transitions on-the-fly

2. Different set of predicates at different control locations

3. Avoid exponential number of theorem-prover calls

y = x + 1

if (x)

y = x

no yes

assert (y)

P ( x == 0 )

P ( x == 0 )P ( x == 0 )

Q ( y == 0 )

Page 33: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

33Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Research Areas

Finding “good” predicates

• Technically as hard as finding “good” loop invariants

• Complexity is linear in LOC but exponential in number of predicates

Combining with static analysis

• Alias analysis, invariant detection, constant propagation

• Inexpensive, and may make subsequent model checking more efficient

Bounded model checking

Page 34: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

34Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Software Model Checking Tools

Iterative Refinement

• SLAM, BLAST, MAGIC, Copper, SATABS, …

Bounded Model Checking

• CBMC, …

Others

• Engines: MOPED, BEBOP, BOPPO, …

• Java: Java PathFiner, Bandera, BOGOR, …

• C: CMC, CPAChecker, …

Next lecture

Following lecture

Page 35: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1

35Software VerificationSagar Chaki, March 16, 2011

© 2006 Carnegie Mellon University

Bibliography

Existential Abstraction: Edmund M. Clarke, Orna Grumberg, David E. Long: Model Checking and Abstraction. ACM Trans. Program. Lang. Syst. 16(5): 1512-1542 (1994)

Predicate Abstraction: Construction of abstract state graphs with PVS, S. Graf, H. Saidi, Proceedings of Computer Aided Verification (CAV), 1997

Abstraction Refinement for C: Automatically Validating Temporal Safety Properties of Interfaces, T. Ball, S. Rajamani, Proceedings of the SPIN Workshop, 2001

Software Model Checking Technology Transfer: SLAM and Static Driver Verifier: Technology Transfer of Formal Methods inside Microsoft, T. Ball, B. Cook, V. Levin, S. Rajamani, Proceedings of Intergrated Formal Methods, 2004

Page 36: Software Verification using Predicate Abstraction and Iterative Refinement: Part 1