Nikolaj Bjørner |
In collaboration with Arie Gurfinkel, Ken McMillan, Andrey Rybalchenko VTSA Summer School, 2014 nbjorner@microsoft.com |
Reduce Program Analysis to Constraint Solving
Program Semantics | Hoare Logic [20, 24, 29, 37] | |||
Existential Fixedpoint Logic [13] | ||||
Constrained Horn Clauses | ||||
Proof rules [26] | ||||
Note: Specialized algorithms are used to solve Horn clauses.
Constrained Horn Clause:
Abbreviations:
UNSAT | SAT |
---|---|
Produce a | Produce an explicit model, or |
resolution proof | proof that there is no resolution proof |
Focus of CLP | Aim of our efforts |
What about procedure calls?
l0: if (unknown(x) > 0) goto :error
l0(x) <- true.
error <- l0(x), unknown(x) > 0.
unknown(x) := 0;
l0 := true;
error := false;
Proper semantics obtained by quantifying over all loose models.
which is equivalent to:
More generally, proper semantics is for:
When there is a canonical interpretation for background
theory (arithmetic without division), proper semantics coincides
with satisfiability modulo theories , e.g,:
Compare to constraint handling rules in logic programming.
Option 1: use BDDs to represent tables.
Option 2: build tables from ternary bit-vectors.
Option 3,4,..: Use hash tables, B-trees, bit-maps
Unfold
Fold
New Definition
Rewriting, such as rewriting equalites
[1,3, tautology]
[2,3]
[simplify 5, subsumed 3]
Goal:
Subsumption:
are state variables.
is a monome (a conjunction of literals).
is a clause (a disjunction of literals).
Convention: is a monome over variables , is a renaming of the same monome to variables .
repeat until ∞
Candidate If for some , , then add to .
Unfold If , then set .
repeat until ∞
Unreachable For , if , return Unreachable.
Reachable If , return Reachable.
repeat until ∞
repeat until ∞
Conflict Let : given a candidate model and clause , such that
Leaf If , and is unsatisfiable,
then add to .
repeat until ∞
Decide Add to if , .
Pssst: I am replacing by greek letters.
Conflict Let : given a candidate model and clause , such that , if , then conjoin to , for .
Conflict Let : given a candidate model and a formula , such that , , then conjoin to , for .
Recall predicate transformer for McCarthy91:
Decide now spawns two children.
Decide If and there are consistent such that and , then add , to .
We also have to take DAG unfolding into acount.
Base Mark if or if there is a consistent
such that and .
Close Mark if all children are marked.
Reachable If is marked, return Reachable.
Decide and Conflict pushing a goal over
Reachable If is satisfiable, then return Reachable.
Decide For for , add to if:
- .
- .
-
- is disjoint from for every .
Decide For for , add to if:
- .
- .
-
- is disjoint from for every .
Close For for , if is satisfiable, but is unsatsifiable,
then update , where .
f(y) {
int x, lock = 0;
do {
lock = 1;
y = x;
if (*) {
lock = 0;
y = y + 1;
}
}
while( x != y);
if (lock != 1)
error();
}
Maintain the following data-structures:
Initially:
Region Abstraction | Transition Abstraction |
---|---|
The abstraction is unsatisfiable. A core selects clauses corresponding to the literals: . We check if the symbolic execution of the path is feasible. It is not:
Extract a condition on to cut the path.
The new abstraction is:
Region Abstraction | Transition Abstraction |
---|---|
The system remains unsatisfiable with core
Notice that the core is smaller, it uses the invariant associated with and does not symbolically execute .
The transition is refined in a similar way.
Region Abstraction | Transition Abstraction |
---|---|
The state invariants are used by the symbolic simulator. They are added to the path condition during simulation.
The system remains unsatisfiable with core
Split :
Region Abstraction | Transition Abstraction |
---|---|
The transition to is still feasible. Simulation produces the core:
So we can conclude that . The resulting abstraction is satisfiable.
Region Abstraction | Transition Abstraction |
---|---|
The abstraction that is reachable from is also a satisfying interpretation for the original set of Horn clauses. That is, the following interpretation satisfies the Horn clauses:
The abstractions corresponds to procedure summaries. The following properties are used to prune search:
Symbolic execution re-uses must summaries to avoid exploring procedures. summaries are used to establish inductive properties.
|
|
|
must summary is used to fast forward for a feasible path to where a summary gets inferred to rule out the query.
Horn formulation:
Initial region abstraction:
It checks:
The SMASH algorithm is about exploiting a particular symbolic execution to simplify weakest pre-conditions. Yogi uses weakest pre-conditions to refine the propositional abstraction.
Corral is a newer symbolic Software Model checking system by Akash Lal, Shaz Qadeer. It uses incremental inlining of procedure calls and relies on Houdini to establish inductiveness.