lect10b.pdf
lect10b.pdf
lect10b.pdf
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Overview<br />
Algorithmic Verification<br />
Comp3153/9153<br />
Lecture 10b<br />
Comp 3153 Ansgar Fehnker<br />
Model checking<br />
Explicit state model checking<br />
� Bottom-up recursive labelling algorithm for CTL<br />
� LTL tableau or automaton-based algorithms<br />
Symbolic model checking<br />
� Efficient algorithm through efficient operations of BDD<br />
representation of sets<br />
SAT-based model checking<br />
� Bounded-model checking uses SAT-solver to show absence<br />
of counterexamples in finite unrolling of the model<br />
SAT-solving<br />
History<br />
Comp 3153 Ansgar Fehnker<br />
� 1st generation (1960s)<br />
� DP, DLL<br />
� 2nd generation (1980s/90s)<br />
� POSIT, Tableau, …<br />
� 3rd generation (mid 1990s)<br />
� SATO, satz, grasp, …<br />
� 4th generation (2000s)<br />
� Chaff, BerkMin, …<br />
� 5th generation?<br />
Comp 3153 Ansgar Fehnker<br />
Vars<br />
100000<br />
10000<br />
1000<br />
100<br />
10<br />
1<br />
1960 1970 1980 1990 2000 2010<br />
Year<br />
Number of variables tackled by SAT-solvers<br />
graphs thanks to Daniel Kroening<br />
Overview<br />
Modelling<br />
� Finite automata<br />
� Büchi automata<br />
� Kripke structures<br />
Specification<br />
� Linear Time Logic<br />
� Computation Tree Logic<br />
� CTL*<br />
Overview<br />
Comp 3153 Ansgar Fehnker<br />
Today: SAT-based model checking<br />
Basic Idea<br />
Comp 3153 Ansgar Fehnker<br />
s 0<br />
s 0<br />
s 1<br />
CTL*<br />
s 1<br />
LTL CTL<br />
Use algorithms that solve (in practice) difficult problems<br />
efficiently.<br />
Transform model checking problem to an problem instance<br />
for that solver.<br />
SAT-solver are such efficient solvers.<br />
SAT Solving and Model Checking<br />
Reminder<br />
Set of initial states and transition relation can be<br />
represented as Boolean functions<br />
SAT-solvers for model checking?<br />
� Bounded Model Checking<br />
� SAT-based Abstraction Refinement<br />
Comp 3153 Ansgar Fehnker<br />
s 2<br />
1
Bounded Model Checking<br />
void f(...) {<br />
...<br />
while(cond) {<br />
Body;<br />
}<br />
Rest;<br />
}<br />
Comp 3153 Ansgar Fehnker<br />
Bounded Model Checking<br />
void f(...) {<br />
...<br />
if(cond) {<br />
Body;<br />
if(cond) {<br />
Body;<br />
while(cond) {<br />
Body;<br />
}<br />
}<br />
}<br />
Rest;<br />
}<br />
Comp 3153 Ansgar Fehnker<br />
Bounded Model Checking<br />
void f(...) {<br />
...<br />
if(cond) {<br />
Body;<br />
if(cond) {<br />
Body;<br />
if(cond) {<br />
Body;<br />
if(cond) {<br />
assert(FALSE);<br />
}<br />
}<br />
}<br />
}<br />
Rest;<br />
}<br />
Comp 3153 Ansgar Fehnker<br />
Rather than checking infinite<br />
loops, check finite unwinding<br />
� Unwind while() loops<br />
Rather than checking infinite<br />
loops, check finite unwinding<br />
� Unwind while() loops<br />
Rather than checking infinite<br />
loops, check finite unwinding<br />
� Unwind while() loops<br />
� Until the bound k is<br />
reached<br />
� Add assertion after last<br />
iteration.<br />
Check whether error is<br />
real or due to<br />
insufficient bound k.<br />
Bounded Model Checking<br />
void f(...) {<br />
...<br />
if(cond) {<br />
Body;<br />
while(cond) {<br />
Body;<br />
}<br />
}<br />
Rest;<br />
}<br />
void f(...) {<br />
...<br />
if(cond) {<br />
Body;<br />
if(cond) {<br />
Body;<br />
if(cond) {<br />
Body;<br />
while(cond) {<br />
Body;<br />
}<br />
}<br />
}<br />
}<br />
Rest;<br />
}<br />
Comp 3153 Ansgar Fehnker<br />
Bounded Model Checking<br />
Comp 3153 Ansgar Fehnker<br />
Rather than checking infinite<br />
loops, check finite unwinding<br />
� Unwind while() loops<br />
Rather than checking infinite<br />
loops, check finite unwinding<br />
� Unwind while() loops<br />
� Until the bound k is<br />
reached<br />
Bounded Model Checking<br />
Basic Idea<br />
� Show absence of counterexamples of length k<br />
� Translate model checking problem to SAT problem<br />
� Use SAT solver to show absence of counterexamples.<br />
� Complete for sufficiently large k<br />
Comp 3153 Ansgar Fehnker<br />
Based on<br />
presentations Daniel<br />
Kroening and Ofer<br />
Shtrichman<br />
2
Bounded Model Checking<br />
Reminder<br />
� Safety properties<br />
� Invariants, deadlocks, reachability, etc.<br />
� Can be checked on finite traces<br />
� “something bad never happens”<br />
� Liveness Properties<br />
� Fairness, response, etc.<br />
� Infinite traces<br />
� “something good will eventually happen”<br />
Safety Properties<br />
Comp 3153 Ansgar Fehnker<br />
Given a Kripke Stucture M=(S, S 0, R, L)<br />
The reachable states in k steps are captured by:<br />
p p p ¬p p<br />
. . .<br />
s0 s1 s2 sk-1 sk Safety Properties<br />
Comp 3153 Ansgar Fehnker<br />
Formulation as SAT problem<br />
� The safety property p is valid up to step k iff Ω(k) is<br />
not satisfiable:<br />
p p p ¬p p<br />
. . .<br />
s0 s1 s2 sk-1 sk Comp 3153 Ansgar Fehnker<br />
Safety Properties<br />
Typical property: G p<br />
Bounded check: Is a state reachable within k steps,<br />
which satisfies ¬p ?<br />
p p p ¬p p<br />
. . .<br />
s0 s1 s2 sk-1 sk Counterexample for safety properties are finite paths<br />
Safety Properties<br />
Comp 3153 Ansgar Fehnker<br />
Given a Kripke Stucture M=(S, S 0, R, L)<br />
The property p fails in one of the states 1..k if<br />
p p p ¬p p<br />
. . .<br />
s0 s1 s2 sk-1 sk Safety Properties<br />
Comp 3153 Ansgar Fehnker<br />
Example: a two-bit counter<br />
00<br />
11<br />
01 10<br />
The property holds within 2 steps if Ω(k) is unsatisfiable<br />
Comp 3153 Ansgar Fehnker<br />
Initial state: I 0= ¬ l ∧ ¬ r<br />
Transition: R: l’ = (l ≠ r) ∧<br />
r’ = ¬ r<br />
Property: G (¬l ∨ ¬r).<br />
3
Liveness Properties<br />
Typical property: F p<br />
Bounded check: Is there a path of length k, that<br />
ends in a loop, such that never p ?<br />
¬p ¬p ¬p ¬p ¬p<br />
. . .<br />
s0 s1 s2 sk-1 sk Counterexamples for liveness properties end in a loop<br />
Comp 3153 Ansgar Fehnker<br />
Liveness Properties<br />
Given a Kripke Stucture M=(S, S 0, R, L)<br />
The property p never holds in the states 1..k if<br />
¬p ¬p ¬p ¬p ¬p<br />
. . .<br />
s0 s1 s2 sk-1 sk Comp 3153 Ansgar Fehnker<br />
Liveness Properties<br />
Formulation as SAT problem<br />
� The liveness property Fp is valid up to cycle k iff<br />
Ω(k) is unsatisfiable:<br />
Comp 3153 Ansgar Fehnker<br />
Liveness Properties<br />
Given a Kripke Stucture M=(S, S 0, R, L)<br />
The reachable states in k steps are captured by:<br />
¬p ¬p ¬p ¬p ¬p<br />
. . .<br />
s0 s1 s2 sk-1 sk Comp 3153 Ansgar Fehnker<br />
Liveness Properties<br />
Given a Kripke Stucture M=(S, S 0, R, L)<br />
The path ends in a loop if<br />
¬p ¬p ¬p ¬p ¬p<br />
. . .<br />
s0 s1 s2 sk-1 sk Comp 3153 Ansgar Fehnker<br />
Liveness Properties<br />
Example: another bit counter<br />
00<br />
11<br />
Transition: R: l’ = (l ≠ r) ∧<br />
01 10<br />
r’ = ¬ r<br />
Property: F (l ∧ r).<br />
The property holds within 2 steps if Ω(k) is unsatisfiable<br />
Comp 3153 Ansgar Fehnker<br />
Initial state: I 0= ¬ l ∧ ¬ r<br />
4
LTL<br />
Checking an arbitrary formula φ<br />
LTL<br />
1. Build Buechi Automaton for ¬ φ<br />
2. Compose A x A ¬ φ<br />
3. Check if L(A x A ¬ φ ) is empty<br />
Bounded check: Is there a path of length k, that ends<br />
in a loop with an accepting state?<br />
Comp 3153 Ansgar Fehnker<br />
Given Buechi Automaton A= 〈Σ, Q, Q 0,δ, F〉<br />
LTL<br />
The reachable states in k steps are captured by:<br />
F<br />
. . .<br />
s0 s1 s2 sk-1 sk Comp 3153 Ansgar Fehnker<br />
Formulation as SAT problem<br />
� The LTL formula formula φ is valid up to cycle k iff<br />
Ω(k) for Buechi automaton A x A ¬ φ is not<br />
satisfiable:<br />
Comp 3153 Ansgar Fehnker<br />
LTL<br />
Given Buechi Automaton A= 〈Σ, Q, Q 0,δ, F〉<br />
LTL<br />
Check fairness condition GF f<br />
L(A) is non-empty if a witness exists<br />
Witness ends in a loop with some state satisfying f<br />
F<br />
. . .<br />
s0 s1 s2 sk-1 sk Comp 3153 Ansgar Fehnker<br />
Given Buechi Automaton 〈Σ, Q, Q 0,δ, F〉<br />
Path ends in a loop, with accepting state<br />
F<br />
. . .<br />
s0 s1 s2 sk-1 sk Comp 3153 Ansgar Fehnker<br />
Bounded Model Checking<br />
Safety<br />
� Check if counterexample of length k exists<br />
Liveness<br />
LTL<br />
� Check if counterexample of length k exists that ends<br />
in loop<br />
� Check if accepting run of length k exists in Buechi<br />
automaton of the negation<br />
Comp 3153 Ansgar Fehnker<br />
5
Bounded Model Checking<br />
BMC-loop<br />
Resources<br />
exceeded<br />
k++<br />
no<br />
k = 0<br />
BMC(M,φ,k)<br />
k ⊤ CT ?<br />
Comp 3153 Ansgar Fehnker<br />
yes<br />
Bounded Model Checking<br />
Completeness Threshold<br />
� Diameter D(M) = longest shortest path between<br />
any two reachable states.<br />
� Recurrence Diameter RD(M) = longest loop-free<br />
path between any two reachable states.<br />
� The initialized versions: DI(M) and RDI(M)<br />
start from an initial state<br />
Comp 3153 Ansgar Fehnker<br />
Bounded Model Checking<br />
Intermediate Summary<br />
� Show absence of counterexamples of length k<br />
� Bounded model checking problem can be<br />
formulated as SAT problem<br />
� Only complete for sufficiently large k<br />
� For Safety, Liveness and LTL<br />
� Also for ACTL or ECTL<br />
Either A or E<br />
path quantifiers<br />
only<br />
Comp 3153 Ansgar Fehnker<br />
Bounded Model Checking<br />
Completeness Threshold<br />
� For every finite model M and LTL property φ there<br />
exists k s.t.<br />
� The Completeness Threshold (CT) is the minimal<br />
such k<br />
� Clearly if M|≠ φ then CT = 0<br />
� Computing CT is a model checking problem by itself<br />
Comp 3153 Ansgar Fehnker<br />
Bounded Model Checking<br />
Completeness Threshold<br />
� DI(M) is an upper bound for safety properties<br />
� RDI(M) +1 is an upper bound for liveness properties<br />
� Completeness threshold for general LTL is unknown<br />
� However, in practice the CT is of little interest. Too<br />
hard to compute, and too large.<br />
Comp 3153 Ansgar Fehnker<br />
Tuning SAT for BMC<br />
Common heuristics for general CNF formula<br />
� Most Frequent in unsatisfied clauses (DLCS)<br />
� Satisfies the most clauses (DLIS)<br />
� Satisfies the most shortest clauses (MOM, JW)<br />
� Conflict Driven (VSIDS)<br />
⇒ Local sets of variables are satisfied in arbitrary order.<br />
Static ordering, taking structure of Ω(k) into account, often better<br />
Comp 3153 Ansgar Fehnker<br />
Based on<br />
presentations Daniel<br />
Kroening and Ofer<br />
Shtrichman<br />
6
Tuning SAT for BMC<br />
Replicating Clauses<br />
� If x 3=1, y 7 = 0, z 5 = 1 leads to a conflict, then so<br />
will x 2=1, y 6 = 0, z 4 = 1<br />
� Therefore, we can also add:<br />
(¬x 2 ∨ y 6 ∨ ¬z 4) ∧ … ∧ (¬x 0 ∨ y 4 ∨ ¬z 2) and...<br />
(¬x 4 ∨ y 8 ∨ ¬z 6) ∧ … ∧ (¬x k-4 ∨ y k ∨ ¬z k-2)<br />
Comp 3153 Ansgar Fehnker<br />
Bounded Model Checking<br />
Summary<br />
� BMC is available e.g. in NuSMV<br />
� SAT-based BMC can solve instance that BDD<br />
symbolic model checkers cannot.<br />
� And vice versa<br />
� BMC with SAT for finding shallow errors.<br />
� BDD-based procedures for proving their absence.<br />
� BMC and BDD model checkers used as<br />
complementary methods<br />
Comp 3153 Ansgar Fehnker<br />
Tuning SAT for BMC<br />
Reusing Clauses<br />
� Most clauses in Ω(k+1), except encoding of the<br />
property, last transition, are also in Ω(k)<br />
� Reuse conflict clause C of Ω(k), if possible, when<br />
solving Ω(k+1),<br />
Comp 3153 Ansgar Fehnker<br />
7