Automatic Abstraction in SMT-Based Unbounded Software Model Checking
description
Transcript of Automatic Abstraction in SMT-Based Unbounded Software Model Checking
© Anvesh KomuravelliSpacer
Automatic Abstraction in SMT-Based Unbounded Software Model Checking
Anvesh KomuravelliCarnegie Mellon University
Joint work with Arie Gurfinkel, Sagar Chaki and Edmund Clarke
© Anvesh KomuravelliSpacer 2
The Problem
Program P+ Assertions
Automatic analysis for
assertion failures
Safe
Unsafe
Unknown
Software Model Checking
+ Proof
+ Counterexample
+ Partial Proof
reach(P) error(P)
Is it empty?
© Anvesh KomuravelliSpacer 3
reach(P) error(P)
Over-approximation Driven (OD)
© Anvesh KomuravelliSpacer 4
reach(P) error(P)
Over-approximation driven (OD)
© Anvesh KomuravelliSpacer 5
Over-approximation driven (OD)
Key Idea CEGAR based on Predicate Abstraction
Symbolic Method
BDDs for fixed point computation,SMT for new predicates
Tools SLAM, BLAST, SDV, etc.
© Anvesh KomuravelliSpacer 6
reach(P)
Under-approximation Driven (UD)
error(P)
© Anvesh KomuravelliSpacer 7
Under-approximation driven (UD)
reach(P) error(P)
© Anvesh KomuravelliSpacer 8
Under-approximation driven (UD)
Key Idea BMC based Approach
Symbolic Method SMT
Tools IMPACT, UFO, etc.
© Anvesh KomuravelliSpacer 9
Key Recent Advancements
2003 Interpolation for Hardware Model Checking McMillan
2006 IMPACT (Path Interpolants) McMillan
2009 Path Interpolants for Hardware Model Checking Grumberg et al.
2010 IC3 (Different way of computing Interpolants, Hardware) Bradley
2011 WOLVERINE (Bit-level Implementation of IMPACT) Kroening et al.
2012 UFO (DAG Interpolation method, Predicate Abstraction + Interpolation) Gurfinkel et al.
2012 VINTA (Abstract Interpretation + Interpolation) Gurfinkel et al.
2011 FunFrog (Interprocedural) Sharygina et al.
2012 μZ (Horn clause solver based on GPDR) Bjorner et al.
2012 Duality (Horn clause solver based on Interpolation) McMillan, Rybalchenko
2012 WHALE (Interprocedural) Gurfinkel et al.
© Anvesh KomuravelliSpacer 10
reach(P) error(P)
Our Strategy
Under-approx. Abstract Under-approx.
© Anvesh KomuravelliSpacer 11
reach(P) error(P)
Our Strategy
Under-approx. Abstract Under-approx. Refine
© Anvesh KomuravelliSpacer 12
error(P)reach(P)
Our Strategy
Under-approx. Abstract Under-approx. Refine Abstract
© Anvesh KomuravelliSpacer 13
error(P)reach(P)
Our Strategy
And so on …
© Anvesh KomuravelliSpacer 14
error(P)reach(P)
reach(P) is covered
Our Strategy
Abstractions guide the SMT solver to look for general proofs
© Anvesh KomuravelliSpacer 15
It’s based on UD
…
…
……
Under-approximations
Abstract
© Anvesh KomuravelliSpacer 16
It’s based on UD
…
…
……
Under-approximations
Abstract
need not be monotonic
© Anvesh KomuravelliSpacer 17
Spacer is based on UD
…
…
……
Under-approximations
Abstract
non-trivial abstraction
© Anvesh KomuravelliSpacer 18
SpacerProgram
Under-Approximate
Check Safety Feasible?Feasible?
Abstract Refine
Proof-Based Abstraction CEGARNo No
Yes Yes
Safety Proof Counterexample
© Anvesh KomuravelliSpacer 19
Why Abstraction?
x = y = z = w = 0;while (*) {
x = *; y = *;assume (0 ≤ y ≤ 100x);if (y > 10w && z ≥ 100x) {
y = −y;}t = 1;w += t; z += 10t;
}assert (0 ≤ y)
only way to fail the assertion
© Anvesh KomuravelliSpacer 20
UD Reasoning
x = y = z = w = 0;while (*) {
x = *; y = *;assume (0 ≤ y ≤ 100x);if (y > 10w && z ≥ 100x) {
y = −y;}t = 1;w += t; z += 10t;
}assert (0 ≤ y)
1st Iteration:w = 0, z = 0
y ≤ 100x
© Anvesh KomuravelliSpacer 21
UD Reasoning
x = y = z = w = 0;while (*) {
x = *; y = *;assume (0 ≤ y ≤ 100x);if (y > 10w && z ≥ 100x) {
y = −y;}t = 1;w += t; z += 10t;
}assert (0 ≤ y)
2nd Iteration:w = 1, z =10
y ≤ 100x
© Anvesh KomuravelliSpacer 22
UD Reasoning
x = y = z = w = 0;while (*) {
x = *; y = *;assume (0 ≤ y ≤ 100x);if (y > 10w && z ≥ 100x) {
y = −y;}t = 1;w += t; z += 10t;
}assert (0 ≤ y)
3rd Iteration:w = 2, z = 20
y ≤ 100x
And so on…
© Anvesh KomuravelliSpacer 23
But …
x = y = z = w = 0;while (*) {
x = *; y = *;assume (0 ≤ y ≤ 100x);if (y > 10w && z ≥ 100x) {
y = −y;}t = 1;w += t; z += 10t;
}assert (0 ≤ y)
The value ‘1’ doesn’t matter!
© Anvesh KomuravelliSpacer 24
But …
x = y = z = w = 0;while (*) {
x = *; y = *;assume (0 ≤ y ≤ 100x);if (y > 10w && z ≥ 100x) {
y = −y;}t = *;w += t; z += 10t;
}assert (0 ≤ y)
© Anvesh KomuravelliSpacer 25
UD Reasoning on the Abstraction
x = y = z = w = 0;while (*) {
x = *; y = *;assume (0 ≤ y ≤ 100x);if (y > 10w && z ≥ 100x) {
y = −y;}t = *;w += t; z += 10t;
}assert (0 ≤ y)
2nd Iteration
w = t, z = 10t
z = 10w
All Iterations
Resolve t away
y ≤ 100x
Redundant
© Anvesh KomuravelliSpacer 26
Original Example
x = y = z = w = 0;while (*) {
if (*) {x++; y += 100;}else if (*)
if (x ≥ 4) {x++; y++;}else if (y > 10w && z ≥ 100x) {
y = −y;}t = 1;w += t; z += 10t;
}assert (!(x ≥ 4 && y ≤ 2))
Source: Automatically Refining Abstract Interpretations, Gulavani, Chakraborty, Nori and Rajamani, TACAS ‘08.
μZ (SMT-Based Model Checker,part of Z3)
Cannot solve in an hour
Spacer (our tool)
Finds a proof in a min.
Solves an abstraction in < 1 sec.
t = *;
© Anvesh KomuravelliSpacer 27
What’s the magic?
Focused Proofs
Abstractions guide the SMT solver to look for certain kind of proofs Avoid proofs specific to an under-approximation
How to obtain abstractions?
From proofs of under-approximations! (Proof-Based Abstraction) Hope: What’s sufficient for the under-approximation is sufficient in general Downside: If abstraction is too coarse, need to refine (CEGAR)
© Anvesh KomuravelliSpacer 28
SpacerProgram
Under-Approximate
Check Safety Feasible?Feasible?
Abstract Refine
Proof-Based Abstraction CEGARNo No
Yes Yes
Safety Proof Counterexample
© Anvesh KomuravelliSpacer 29
Schematic Example
init_stmt;c = 0;
while (*) {// invar_1, invar_2// invar_3, invar_4assume (c < k1);if (*) {
v1 = e1; v2 = e2;} else {
v3 = e3; v4 = e4;}v5 = e5; v6 = e6;c += 1;
}
assert (safe);
Add Counters
Under-approximate Solve
Loop Invariants
© Anvesh KomuravelliSpacer 30
Schematic Example
Under-approximate Solve Feasible?
init_stmt;c = 0;assume (invar_1, invar_2);while (*) {
// invar_1, invar_2// invar_3, invar_4assume (c < k1);if (*) {
v1 = e1; v2 = e2;} else {
v3 = e3; v4 = e4;}v5 = e5; v6 = e6;c += 1;assume (invar_1, invar_2);
}
assert (safe);
Unbounded!
Specific to under-approx.
Treat as guessedunbounded invariants.
Essentially like Houdini [FL’01].
Extract UnboundedInvariants
Strengthenwith
Invariants
[FL’01] Houdini, an annotationassistant for ESC/Java,C. Flanagan and K.R.M. Leino, 2001
© Anvesh KomuravelliSpacer 31
init_stmt;c = 0;assume (invar_1, invar_2);while (*) {
// invar_1, invar_2
if (*) {v1 = e1; v2 = e2;
} else {v3 = e3; v4 = e4;
}v5 = e5; v6 = e6;c += 1;assume (invar_1, invar_2);
}
assert (safe);
Does not provethe assertion
Schematic Example
Under-approximate Solve Feasible? NO
© Anvesh KomuravelliSpacer 32
init_stmt;c = 0;assume (invar_1, invar_2);while (*) {
// invar_1, invar_2// invar_3, invar_4assume (c < k1);if (*) {
v1 = e1; v2 = e2;} else {
v3 = e3; v4 = e4;}v5 = e5; v6 = e6;c += 1;assume (invar_1, invar_2);
}
assert (safe);
Redundantfor the proof
Schematic Example
Under-approximate Solve Feasible? NO Abstract
© Anvesh KomuravelliSpacer 33
Schematic Example
Under-approximate Solve Feasible? NO Abstract
init_stmt;c = 0;assume (invar_1, invar_2);while (*) {
// invar_1, invar_2// invar_3, invar_4assume (c < k1);if (*) {
v1 = e1; v2 = *;} else {
v3 = e3; v4 = *;}v5 = e5; v6 = *;c += 1;assume (invar_1, invar_2);
}
assert (safe);
Proof-BasedAbstraction
© Anvesh KomuravelliSpacer 34
init_stmt;c = 0;assume (invar_1, invar_2);while (*) {
assume (c < k2);if (*) {
v1 = e1; v2 = *;} else {
v3 = e3; v4 = *;}v5 = e5; v6 = *;c += 1;assume (invar_1, invar_2);
}
assert (safe);
Concretize
k2 > k1
Schematic Example
Under-approximate Solve
AbstractCounterexample!
Feasible?
Concrete controlpath is infeasible
NO Refine
© Anvesh KomuravelliSpacer 35
Schematic Example
Under-approximate Solve Feasible? NO Refine
init_stmt;c = 0;assume (invar_1, invar_2);while (*) {
assume (c < k2);if (*) {
v1 = e1; v2 = e2;} else {
v3 = e3; v4 = e4;}v5 = e5; v6 = *;c += 1;assume (invar_1, invar_2);
}
assert (safe);
CEGAR
© Anvesh KomuravelliSpacer 36
init_stmt;c = 0;assume (invar_1, invar_2);while (*) {
// invar_5// invar_6assume (c < k2);if (*) {
v1 = e1; v2 = e2;} else {
v3 = e3; v4 = e4;}v5 = e5; v6 = *;c += 1;assume (invar_1, invar_2);
}
assert (safe);
Unbounded
Schematic Example
Under-approximate Solve Feasible? YES
Invariants
© Anvesh KomuravelliSpacer 37
SpacerProgram
Under-Approximate
Check Safety Feasible?Feasible?
Abstract Refine
Proof-Based Abstraction CEGARNo No
Yes Yes
Safety Proof Counterexample
© Anvesh KomuravelliSpacer 38
Detailed Example
x = y = z = w = 0;
while (*) {
if:: x++; y += 100;:: (x ≥ 4) -> x++; y++;:: (y > 10w && z ≥ 100x) -> y = −y;fiw++; z += 10;
}
assert (!(x ≥ 4 && y ≤ 2));
if (nd ()) {x++; y += 100;}else if (nd () && x ≥ 4) {x++; y++;}else if (y > 10w && z ≥ 100x) {y = −y;}else assume (0);
non-deterministic choice(e.g. as in Promela)
C-like
© Anvesh KomuravelliSpacer 39
Detailed Example
x = y = z = w = 0;c = 0;
while (*) {// (y > 10w) => (z < 100x), z ≤ 100x,// x ≤ 2, c ≤ 0 => x ≤ 0, c ≤ 1 => x ≤ 1assume (c < 2);if:: x++; y += 100;:: (x ≥ 4) -> x++; y++;:: (y > 10w && z ≥ 100x) -> y = −y;fiw++; z += 10;c += 1;
}
assert (!(x ≥ 4 && y ≤ 2));
Add Counters
Under-approximate Solve
Loop Invariants
© Anvesh KomuravelliSpacer 40
Detailed Example
x = y = z = w = 0;c = 0;
while (*) {// (y > 10w) => (z < 100x), z ≤ 100x,// x ≤ 2, c ≤ 0 => x ≤ 0, c ≤ 1 => x ≤ 1assume (c < 2);if:: x++; y += 100;:: (x ≥ 4) -> x++; y++;:: (y > 10w && z ≥ 100x) -> y = −y;fiw++; z += 10;c += 1;
}
assert (!(x ≥ 4 && y ≤ 2));
Inductive Invariant
Under-approximate Solve
Safe
© Anvesh KomuravelliSpacer 41
Detailed Example
x = y = z = w = 0;c = 0;assume (y > 10w => z < 100x, z ≤ 100x);while (*) {
// (y > 10w) => (z < 100x), z ≤ 100x,// x ≤ 2, c ≤ 0 => x ≤ 0, c ≤ 1 => x ≤ 1assume (c < 2);if:: x++; y += 100;:: (x ≥ 4) -> x++; y++;:: (y > 10w && z ≥ 100x) -> y = −y;fiw++; z += 10;c += 1;assume (y > 10w => z < 100x, z ≤ 100x);
}
assert (!(x ≥ 4 && y ≤ 2));
Under-approximate Solve Feasible?
Preserved!Specific to under-approx.
Depend on counter
Extract UnboundedInvariants
Strengthenwith
Invariants
© Anvesh KomuravelliSpacer 42
Detailed Example
x = y = z = w = 0;c = 0;assume (y > 10w => z < 100x, z ≤ 100x);while (*) {
// (y > 10w) => (z < 100x), z ≤ 100x,
if:: x++; y += 100;:: (x ≥ 4) -> x++; y++;:: (y > 10w && z ≥ 100x) -> y = −y;fiw++; z += 10;c += 1;assume (y > 10w => z < 100x, z ≤ 100x);
}
assert (!(x ≥ 4 && y ≤ 2));
Under-approximate Solve Feasible? NO
Does not provethe assertion
© Anvesh KomuravelliSpacer 43
Detailed Example
x = y = z = w = 0;c = 0;assume (y > 10w => z < 100x, z ≤ 100x);while (*) {
// (y > 10w) => (z < 100x), z ≤ 100x,// x ≤ 2, c ≤ 0 => x ≤ 0, c ≤ 1 => x ≤ 1assume (c < 2);if:: x++; y += 100;:: (x ≥ 4) -> x++; y++;:: (y > 10w && z ≥ 100x) -> y = −y;fiw++; z += 10;c += 1;assume (y > 10w => z < 100x, z ≤ 100x);
}
assert (!(x ≥ 4 && y ≤ 2));
Under-approximate Solve Feasible? NO Abstract
Redundant
© Anvesh KomuravelliSpacer 44
Detailed Example
x = y = z = w = 0;c = 0;assume (y > 10w => z < 100x, z ≤ 100x);while (*) {
// (y > 10w) => (z < 100x), z ≤ 100x,// x ≤ 2, c ≤ 0 => x ≤ 0, c ≤ 1 => x ≤ 1assume (c < 2);if:: x++; y = *;:: (x ≥ 4) -> x++; y = *;:: (y > 10w && z ≥ 100x) -> y = *;fiw = *; z = *;c += 1;assume (y > 10w => z < 100x, z ≤ 100x);
}
assert (!(x ≥ 4 && y ≤ 2));
Under-approximate Solve Feasible? NO Abstract
Fails Enlarge error
© Anvesh KomuravelliSpacer 45
Detailed Example
x = y = z = w = 0;c = 0;assume (y > 10w => z < 100x, z ≤ 100x);while (*) {
// (y > 10w) => (z < 100x), z ≤ 100x,// x ≤ 2, c ≤ 0 => x ≤ 0, c ≤ 1 => x ≤ 1assume (c < 2);if:: x++; y = *;:: (x ≥ 4) -> x++; y = *;:: (y > 10w && z ≥ 100x) -> y = *;fiw = *; z = *;c += 1;assume (y > 10w => z < 100x, z ≤ 100x);
}
assert (!(x ≥ 4));
Under-approximate Solve Feasible? NO Abstract
© Anvesh KomuravelliSpacer 46
Detailed Example
x = y = z = w = 0;c = 0;assume (y > 10w => z < 100x, z ≤ 100x);while (*) {
assume (c < 4);if:: x++; y = *;:: (x ≥ 4) -> x++; y = *;:: (y > 10w && z ≥ 100x) -> y = *;fiw = *; z = *;c += 1;assume (y > 10w => z < 100x, z ≤ 100x);
}
assert (!(x ≥ 4));
Under-approximate Solve
Counterexample!
Increment x to 4Choose y arbitrarily
Feasible?
Concrete controlpath is infeasible
NO Refine
Concretize
© Anvesh KomuravelliSpacer 47
Detailed Example
x = y = z = w = 0;c = 0;assume (y > 10w => z < 100x, z ≤ 100x);while (*) {
assume (c < 4);if:: x++; y += 100;:: (x ≥ 4) -> x++; y++;:: (y > 10w && z ≥ 100x) -> y = −y;fiw = *; z = *;c += 1;assume (y > 10w => z < 100x, z ≤ 100x);
}
assert (!(x ≥ 4 && y ≤ 2));
Under-approximate Solve Feasible? NO Refine
© Anvesh KomuravelliSpacer 48
Detailed Example
x = y = z = w = 0;c = 0;assume (y > 10w => z < 100x, z ≤ 100x);while (*) {
// (y > 10w) => (z < 100x), z ≤ 100x// y > 0, (x > 0) => (y ≥ 100)assume (c < 4);if:: x++; y += 100;:: (x ≥ 4) -> x++; y++;:: (y > 10w && z ≥ 100x) -> y = −y;fiw = *; z = *;c += 1;assume (y > 10w => z < 100x, z ≤ 100x);
}
assert (!(x ≥ 4 && y ≤ 2));
Under-approximate Solve Feasible? YES
Inductive Invariant
Safe
Unbounded
© Anvesh KomuravelliSpacer 49
Implementation Details – Unbounded Invariants
Pre-Lemmas Post-LemmasConcrete Counters
Goal Find maximal such that
© Anvesh KomuravelliSpacer 50
Implementation Details – Unbounded Invariants
UNSAT
SAT with true
SAT?
Repeat until fixed point
© Anvesh KomuravelliSpacer 51
Implementation Details – Unbounded Invariants
Maximal subset of true post-lemmasMinimal number of bi’s to be set to falseFixed point Iteration:
Introduce Assumption
variables
© Anvesh KomuravelliSpacer 52
Implementation Details – Unbounded Invariants
Iteration 1
✔
✗
Iteration 2
✗
disableddisabled
© Anvesh KomuravelliSpacer 53
Implementation Details – Abstraction
Introduce Assumption
variables
© Anvesh KomuravelliSpacer 54
Implementation Details – Abstraction
Are all lemmas necessary?
© Anvesh KomuravelliSpacer 55
Implementation Details – Abstraction
Introduce Assumption variables for
lemmas
© Anvesh KomuravelliSpacer 56
Spacer ToolProgram
Under-Approximate
Check Safety Feasible?Feasible?
Abstract Refine
Proof-Based Abstraction CEGARNo No
Yes Yes
Safety Proof Counterexample
© Anvesh KomuravelliSpacer 57
Spacer ToolProgram
Under-Approximate
Check Safety Feasible?Feasible?
Abstract Refine
Proof-Based Abstraction CEGARNo No
Yes Yes
Safety Proof Counterexample
μZ Horn-Clause Solver(part of Z3)
© Anvesh KomuravelliSpacer 58
Spacer ToolProgram
Under-Approximate
Check Safety Feasible?Feasible?
Abstract Refine
Proof-Based Abstraction CEGARNo No
Yes Yes
Safety Proof Counterexample
Horn-Clause Encoding
μZ Horn-Clause Solver(part of Z3)
© Anvesh KomuravelliSpacer 59
Spacer Tool
C Program
Preprocessing UFO Frontend (based on LLVM)Simplification, Large Block Encoding, etc.
Horn Clause Encoding Implemented using UFO Frontend
© Anvesh KomuravelliSpacer 60
Results on SV-COMP’13 Benchmarks
0 50 100 1500
50
100
150
UNSAFE Benchmarks
μZ (secs)
Spac
er (s
ecs)
Abstraction did not helpfor UNSAFE
ALSO,not a challenging pool
of benchmarks
© Anvesh KomuravelliSpacer 61
Results on SV-COMP’13 Benchmarks
0 100 200 300 400 500 600 700 800 9000
100
200
300
400
500
600
700
800
900
SAFE Benchmarks
μZ (secs)
Spac
er (s
ecs)
© Anvesh KomuravelliSpacer 62
Results on SV-COMP’13 Benchmarks
0 100 200 300 400 500 600 700 800 9000
100
200
300
400
500
600
700
800
900
SAFE Benchmarks
μZ (secs)
Spac
er (s
ecs)
~1 min.Not very meaningful
to compare
© Anvesh KomuravelliSpacer 63
Results on SV-COMP’13 Benchmarks
0 100 200 300 400 500 600 700 800 9000
100
200
300
400
500
600
700
800
900
SAFE Benchmarks
μZ (secs)
Spac
er (s
ecs)
< 5 min.Mixed
Results
© Anvesh KomuravelliSpacer 64
Results on SV-COMP’13 Benchmarks
0 100 200 300 400 500 600 700 800 9000
100
200
300
400
500
600
700
800
900
SAFE Benchmarks
μZ (secs)
Spac
er (s
ecs)
Advantage!
© Anvesh KomuravelliSpacer 65
Results on SV-COMP’13 Benchmarks
0 100 200 300 400 500 600 700 800 9000
100
200
300
400
500
600
700
800
900
SAFE Benchmarks
μZ (secs)
Spac
er (s
ecs)
Advantage!
Time-out
Mem-out
© Anvesh KomuravelliSpacer 66
Conclusion
Focused Proofs
Abstractions guide the SMT solver to look for certain kind of proofs Avoid proofs specific to an under-approximation
How to obtain abstractions?
From proofs of under-approximations! (Proof-Based Abstraction) Hope: What’s sufficient for the under-approximation is sufficient in general Downside: If abstraction is too coarse, need to refine (CEGAR)
A framework for automated abstraction in SMT-based Software Model Checking Implementation using an existing SMT-based model checker with practical
advantage
Contributions
© Anvesh KomuravelliSpacer 67
Conclusion (contd…)
Post-pruning of Proofs during Abstraction (Local vs. Global Proofs) Non-monotonic abstractions Major role of invariants (exploit the generality of proofs of under-approximations
Visit spacer.bitbucket.org todownload tool and detailed slides!
Why does PBA work?
© Anvesh KomuravelliSpacer 68
On-going and Future Work
Observation: Fixed granularity of abstraction – at the program levelObservation: Restricted space of abstractions
Questions: When/How to abstract/refine?
Observation: Proofs too dependent on counter constraints (i.e. underapprox.)
Question: How to use counters only when needed? In general, how to minimize the use of a given set of assumptions?
Observation: Abstraction is done offline, after obtaining a proof of an under-approximation.
Question: How does an on-the-fly abstraction work? When each transition is treated as a recursion-free procedure, it is similar to summarizing procedures on-the-fly. Also, how to handle recursion?
© Anvesh KomuravelliSpacer 69
Read our CAV’13 paper for details…
Questions?
© Anvesh KomuravelliSpacer 70
Extra Slides
© Anvesh KomuravelliSpacer 71
SMT-Based Model Checking
init
error
CFG Loop-Free Unrolling
Possibility 1 : UNSAFE
Possibility 2 : SAFE
Path Interpolants (McMillan ‘06)
Discharge Verification Condition on SMT solver
© Anvesh KomuravelliSpacer 72
SMT-Based Model Checking
init
error
CFG
Further Unrolling
Possibility 1 : UNSAFE
Possibility 2 : SAFE
DAG Interpolants [AGC’12]
Continue Until Convergence
Discharge Verification Condition on SMT solver
[AGC’12] : From Under-approximations to Over-approximations and Back,Albarghouthi, Gurfinkel and Chechik, TACAS ‘12