Model Checking 3
Model Checking 3
Checking
Natasha Sharygina
Carnegie Mellon University
Outline
1
What we have learned so far
Model Checking Basic Concepts:
• Diagnostic counterexamples
2
Today’s Lecture
Hypothesis
3
Application of Model Checking to
Hardware Verification
- Procedural or OO design
4
Model Checking Software
(code verification)
Re-design 1. Design/Implementation/Testing
Code
Limitations:
Model Property
• Final (expensive) stage in the
program development
Error OUT of
track M/T
10
5
Model Checking Software
(design verification)
Code
4. Code Generation (last stage)
Re-design
Design Testing
Model Tool 1. Executable Design Specifications
• Abstraction from low-level to
high-level operations
Formal Property
Model
2. Modeling/Property Specification
• Finite-state model extraction
Re-design
Design Testing
Model Tool
Advantages:
• Applied earlier in the design
cycle (Earlier bug detection)
Formal Property • Direct translation of informal
Model
program into formal syntax (no
simplifications)
6
State-of-the-art Software Model Checking
13
CEGAR
Initial
Verification
Abstraction
No error
or bug found
Actual Concurrent
Model
Boolean
Program Program Checker
Property
holds
Counterexample
Simulation
Abstraction refinement Refinement successful
Simulator
Bug found
[Kurshan et al. ’93]
[Ball, Rajamani ’00]
[Clarke et al. ’00] Spurious counterexample 14
7
Major Software Model Checkers
• BLAST (Berkeley)
• CBMC (CMU) 15
Class Presentations
16
8
SPIN: LTL Model Checking
17
LTL Formulae
AGFp in CTL*
• Fairness:
( ◊p)→ϕ A((GF p) → ϕ) in CTL*
Can’t express it in CTL
18
9
LTL Model Checking
19
A ⊆ B ⇔ A∩ B = 0
20
10
Buchi Automata
21
Buchi Automata
22
11
Buchi Automata
S = { s0, s1, s2 }
I = { s0 }
a b true
s0 s1 s2
F = { s2 }
Buchi Automata
24
12
Buchi Automata
• Some properties:
– Not all non-deterministic Buchi automata have an
equivalent deterministic Buchi automata
– Not all Buchi automata correspond to an LTL
formula
– Every LTL formula corresponds to a Buchi
automaton
– Set of Buchi automata closed under
complemention, union, intersection, and
composition
25
Buchi Automata
What LTL formula does this Buchi automaton
corresponds to (if any)?
a b true
s0 s1 s2
aUb
26
13
LTL Model Checking
27
• Composition:
– At each step alternate transitions from the system
and the Buchi automaton
• Emptiness:
– To have an accepted trace:
• There must be a cycle
• The cycle must contain an accepting state
28
14
LTL Model Checking
• Cycle detection
– Nested DFS
• Start a second DFS
• Match the start state in the second DFS
– Cycle!
• Second DFS needs to be started at each state?
– Accepting states only will suffice
• Each second DFS is independent
– If started in post-order states need to be visited at most
once in the second DFS searches
29
30
15
LTL Model Checking
procedure DFS2(s, seed)
visited2 = visited2 ∪ {s}
for each successor s’ of s
if s’ = seed then
return “Cycle Detect”;
end if
if s’ ∉ visited2 then
DFS2(s’, seed)
end if
end for
end procedure
31
References
• http://spinroot.com/
• Design and Validation of Computer Protocols by Gerard
Holzmann
• The Spin Model Checker by Gerard Holzmann
• An automata-theoretic approach to automatic program
verification, by Moshe Y. Vardi, and Pierre Wolper
• An analysis of bitstate hashing, by G.J. Holzmann
• An Improvement in Formal Verification, by G.J. Holzmann
and D. Peled
• Simple on-the-fly automatic verification of linear temporal
logic, by Rob Gerth, Doron Peled, Moshe Vardi, and Pierre
Wolper
• A Minimized automaton representation of reachable states,
by A. Puri and G.J. Holzmann
32
16
SPIN: The Promela Language
• Process Algebra
– An algebraic approach to the study of concurrent
processes. Its tools are algebraical languages for the
specification of processes and the formulation of
statements about them, together with calculi for the
verification of these statements. [Van Glabbeek,
1987]
• Describes the system in a way similar to a
programming language
33
Promela
34
17
An Example
mtype = { NONCRITICAL, TRYING, CRITICAL };
show mtype state[2];
proctype process(int id) {
beginning:
NC
noncritical:
state[id] = NONCRITICAL;
if
:: goto noncritical;
:: true;
fi;
trying: T
state[id] = TRYING;
if
:: goto trying;
:: true;
fi;
critical:
state[id] = CRITICAL; C
if
:: goto critical;
:: true;
fi;
goto beginning;}
init { run process(0); run process(1); }
35
An Example
mtype = { NONCRITICAL, TRYING, CRITICAL };
show mtype state[2];
proctype process(int id) {
beginning:
NC
noncritical:
state[id] = NONCRITICAL;
if
:: goto noncritical;
:: true;
fi;
trying: T
state[id] = TRYING;
if
:: goto trying;
:: true;
fi;
critical:
state[id] = CRITICAL; C
if
:: goto critical;
:: true;
fi;
goto beginning;}
init { run process(0); run process(1); }
40
18
Enabled Statements
43
Other constructs
• Do loops
do
:: count = count + 1;
:: count = count - 1;
:: (count == 0) -> break
od
44
19
Other constructs
• Do loops
• Communication over channels
proctype sender(chan out)
{
int x;
if
::x=0;
::x=1;
fi
out ! x;
}
45
Other constructs
• Do loops
• Communication over channels
• Assertions
proctype receiver(chan in)
{
int value;
out ? value;
assert(value == 0 || value == 1)
}
46
20
Other constructs
• Do loops
• Communication over channels
• Assertions
• Atomic Steps
int value;
proctype increment()
{ atomic {
x = value;
x = x + 1;
value = x;
} }
47
Mutual Exclusion
• Peterson’s solution to the mutual exclusion
problem
flag0=1
turn=0 flag0=0
flag1 == 0 || turn == 1
Critical
Section
57
21
Mutual Exclusion in SPIN
bool turn;
bool flag[2];
proctype mutex0() {
again:
flag[0] = 1;
flag0=1
turn = 0;
(flag[1] == 0 || turn == 0);
/* critical section */
turn=0 flag0=0
flag[0] = 0;
flag1 == 0 || turn == 1
goto again;
} flag1 != 0 && turn != 1
Critical
Section
66
Mutual Exclusion
Active process:
bool turn, flag[2];
in SPIN
automatically creates instances of processes
flag[_pid] = 0;
goto again;
}
67
22
Mutual Exclusion in SPIN
bool turn, flag[2];
ncrit:
byte ncrit;
Counts the number of
Process in the critical section
active [2] proctype user()
{
assert(_pid == 0 || __pid == 1);
again:
flag[_pid] = 1;
turn = _pid;
(flag[1 - _pid] == 0 || turn == 1 - _pid);
ncrit++;
assert(ncrit == 1); /* critical section */
ncrit--;
assert:
flag[_pid] = 0;
Checks that there are always
goto again;
at most one process in the
}
critical section
68
[] (critial[0] || critical[1])
active [2] proctype user()
{
[] <> (critical[0])
assert(_pid == 0 || __pid == 1);
[] <> (critical[1])
again:
flag[_pid] = 1;
[] (critical[0] ->
turn = _pid;
(critial[0] U
(flag[1 - _pid] == 0 || turn == 1 - _pid);
(!critical[0] &&
((!critical[0] &&
critical[_pid] = 1;
!critical[1]) U critical[1]))))
/* critical section */
[] (critical[1] ->
critical[_pid] = 0;
(critial[1] U
(!critical[1] &&
flag[_pid] = 0;
((!critical[1] &&
goto again;
!critical[0]) U critical[0]))))
}
69
23