Lect6A ModelChecking
Lect6A ModelChecking
1
Approaches to Verification
2
Model Checking
3
Safety and Liveness
• Safety properties
– Invariants, deadlocks, reachability, etc.
– Can be checked on finite traces
– “something bad never happens”
• Liveness Properties
– Fairness, response, etc.
– Infinite traces
– “something good will eventually happen”
4
Model Checking Process
[ Adapted from www.lix.polytechnique.fr/comete/seminar/1-ModelChecking.ppt]
Model
(System Requirements) Answer:
Model
Yes, if model satisfies
Checker specification
Specification M╞ φ
Counterexample, otherwise
(System Property)
N1 T1 N2 T2
T1 S0 C1 S1 || T2 S0 C2 S1
C1 N1 S0 C2 N2 S0
6
Mutual Exclusion Example
Model
(System Requirements)
•Initially both processes are in the Non-critical state and the semaphore is available --- N1 N2 S0
N1 T1 N2 T2
T1 S0 C1 S1 || T2 S0 C2 S1
C1 N1 S0 C2 N2 S0
N1N2S0
T1N2S0 N1T2S0
7
C1T2S1 T1C2S1
Mutual Exclusion Example
Specification
(System Property)
K ╞ AG EF (N1 N2 S0)
Kripke structure CTL (Computation Tree Logic)
M╞ φ
8
Mutual Exclusion Example
Model N1N2S0
(System Requirements)
T1N2S0 N1T2S0
C1T2S1 T1C2S1
K ╞ AG EF (N1 N2 S0) 9
Mutual Exclusion Example
Answer: Yes
A Proof: For All possible behaviors
N1N2S0
T1N2S0 N1T2S0
C1T2S1 T1C2S1
10
Mutual Exclusion Example
N1N2S0
T1N2S0 N1T2S0
C1T2S1 T1C2S1
N1N2S0
T1N2S0 N1T2S0
11
C1T2S1 T1C2S1
Mutual Exclusion Example
N1N2S0
T1N2S0 N1T2S0
C1T2S1 T1C2S1
N1N2S0
T1N2S0 N1T2S0
12
C1T2S1 T1C2S1
Mutual Exclusion Example
Specification – Desirable Property
K ╞ AG EF (N1 N2 S0)
⌐
13
Mutual Exclusion Example
Answer: No N1N2S0
Counterexample
T1N2S0 N1T2S0
C1T2S1 T1C2S1
N1N2S0
T1N2S0 N1T2S0
14
C1T2S1 T1C2S1
Defining Models
Model
(System Requirements)
Kripke Structure
16
Defining Specifications
Specification
(System Property)
• Temporal Logic
– Express properties of event orderings in time
– e.g. “Always” when a packet is sent it will “Eventually” be received
17
Branching Temporal Logic (BTL)
Computation Tree Logic (CTL) Syntax http://www.cs.ucl.ac.uk/staff/J.Bowen/GS03/w3_l1_ctl_notes.pdf
ϕ ::= ⊤ | ⊥ | p | ¬ φ | φ ∧ ψ | φ ∨ ψ | φ → ψ | AX φ | EX φ |
AF φ | EF φ | AG φ | EG φ | A[φU ψ] | E[φU ψ]
R (‘‘Release’’)
EX φ true in current state if formula φ is true in at least one of the next states
E φUψ true in current state if formula φ is true until ψ becomes true in some path beginning
in current state that satisfies the formula φ
EF φ true in current state if there exists some state in some path beginning in current state
that satisfies the formula φ
EG φ true in current state if every state in some path beginning in current state that
satisfies the formula φ
AX φ true in current state if formula φ is true in every one of the next states
A φUψ true in current state if formula φ is true until ψ becomes true in every path beginning
in current state that satisfies the formula φ
AF φ true in current state if there exists some state in every path beginning in current state
that satisfies the formula φ
AG φ true in current state if every state in every path beginning in current state satisfies the
formula φ 18
Branching Temporal Logic (BTL)
Computation Tree Logic (CTL) Semantics
M,s |= ⊤
M,s |≠ ⊥
M,s |= p iff p ∈ L(s)
M,s |= ¬ϕ iff M,s |≠ ϕ
M,s |= ϕ ∧ ψ iff M,s |= ϕ and M,s |= ψ
M,s |= ϕ ∨ ψ iff M,s |= ϕ or M,s |= ψ
19
Branching Temporal Logic (BTL)
Computation Tree Logic (CTL) Semantics
M |= p if M, s0 |= p
20
Branching Temporal Logic (BTL)
Equivalences between CTL formulas
AXϕ ≡ ¬EX¬ϕ
AGϕ ≡ ¬EF¬ϕ
AFϕ ≡ ¬EG¬ϕ
EFϕ ≡ E[⊤Uϕ]
Therefore, only three operators are required to express all the remaining:
EX,EG,EU (this is called an adequate set of operators).
21
Branching Temporal Logic (BTL)
Specification patterns
Two example of requirements patterns:
23
Issues
Temporal logic: (heavy) can be hard to work with
Translations of requirements models to the input language of model checking
engines often not straightforward.
If no bugs are detected, does this mean that we have achieved verification, or just
got too crude a model or property?
Number of states typically grows exponentially in the number of processes:
cannot be efficiently checked, due to state space explosion
Counter-examples: do not mean anything to the stakeholders; need to be translated
back into the original modeling language.
Deals only with state-oriented behavioral requirements models
24
Appendix: Microwave Oven Example
Model http://pi.informatik.uni-siegen.de/niere/lehre/SS04/SeminarFinal/6_sun/Folien.pdf
M = (S, S0, R, L)
• S = (S1, S2, S3, S4)
• S1 is the initial state
• R = ({S1, S2} {S2, S1}, {S1, S4}, {S4, S2}, {S2, S3}, {S3, S2}, {S3, S3}
• L (S1) = {¬close, ¬ start, ¬ cooking}
L (S2) = {close, ¬ start, ¬ cooking}
L (S3) = {close, start, cooking}
L (S4) = {¬close, start, ¬ cooking}
Specification
1. AG (start AF cooking)
25
Appendix: Microwave Oven Example
M = (S, S0, R, L)
http://pi.informatik.uni-siegen.de/niere/lehre/SS04/SeminarFinal/6_sun/Folien.pdf
• S = (S1, S2, S3, S4)
• S1 is the initial state
• R = ({S1, S2} {S2, S1}, {S1, S4}, {S4, S2}, {S2, S3}, {S3, S2}, {S3, S3}
• L (S1) = {¬close, ¬ start, ¬ cooking}
L (S2) = {close, ¬ start, ¬ cooking}
L (S3) = {close, start, cooking}
L (S4) = {¬close, start, ¬ cooking}
1. AG (start AF cooking)
1) Change formal to ¬EF (start ∧ EG ¬ cooking))
2) From simple partial formulas to the more complicated formulas, until all of the
formulas are true.
• S (start) = {S3, S4}
• S (¬cooking) = {S1, S2, S4}
• S (EG ¬ cooking) = {S1, S2, S4} (all conditions lie on a path)
• S (start ∧ EG ¬ cooking) = {S4}
• S (EF (start Ù EG ¬ cooking)) = {S1, S2, S3, S4} (can be followed with S4)
• S (¬ (EF (start ∧ EG ¬ cooking))) = {}