


























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



























Model Checking
Stavros Tripakis University of California, Berkeley
Stavros Tripakis (UC Berkeley) EE 244, Fall 2016 Model Checking 1 / 68
Given: the implementation: a transition system (Kripke structure) M = (AP, S, S 0 , L, R) the specification: a temporal logic (LTL or CTL) formula φ check where M satisfies φ:
? |= φ
If φ is LTL: every execution trace of M must satisfy φ. If φ is CTL: every initial state of M must satisfy φ.
For finite-state M , the question can be answered fully automatically!
Clarke, Emerson, and Sifakis won the ACM Turing Award in 2007, for their role in developing Model-Checking into a highly effective verification technology that is widely adopted in the hardware and software industries.
Stavros Tripakis (UC Berkeley) EE 244, Fall 2016 Model Checking 3 / 68
Suppose φ is of the form
Gψ or AGψ
where ψ is a propositional formula (boolean expression on atomic propositions).
E.g., G(p ∨ q), G(p → q), · · ·
Then ψ is invariant: it must hold at all reachable states.
Examples: “Whenever train is at intersection the gate must be lowered” “If the autopilot is off then the pilot must not believe it is on”
Given transition system (P, S, S 0 , L, R).
A state s ∈ S is called reachable if there exists a finite path (in the transition system) reaching that state:
s 0 −→ s 1 −→ · · · −→ sk, such that k ≥ 0 and sk = s.
The path is formed by initial state s 0 ∈ S 0 , and transitions (si, si+1) ∈ R, for i = 0, ..., k − 1. Why would some states be unreachable? E.g., a counter modulo 10, represented in 4 bits. Stavros Tripakis (UC Berkeley) EE 244, Fall 2016 Model Checking 7 / 68
We have implicitly assumed that our system is deadlock-free.
Deadlock: a state with no successors:
s is a deadlock iff @s′^ : s −→ s′
Are deadlocks problematic for checking invariants? Why? Only infinite paths count for the verification of a property such as Gp. If the system deadlocks after every time it violates p, then, formally speaking, it satisfies Gp!
How can we check that a given system is deadlock-free?
Use reachability analysis!
Generate all reachable states ... ... while at the same time checking that each of them is “OK”, i.e., I (^) it is not a deadlock state I (^) it does not violate an invariant I (^) ...
Stavros Tripakis (UC Berkeley) EE 244, Fall 2016 Model Checking 9 / 68
Enumerative (also called “explicit state”). I (^) These are basically search algorithms on directed graphs.
Symbolic
I (^) Bounded model-checking using SAT/SMT solvers. I (^) Symbolic reachability.
Quiz: Does the algorithm terminate? Yes, if state space is finite. Does it visit all reachable states? Yes: if s is reachable, then either s ∈ S 0 , or s is the immediate successor of some s′, which is itself reachable. In the first case, s is inserted into V because of the main loop. In the second case, assuming (by induction) that s′^ is inserted to V , s will also be inserted to V by loop in lines 3-6. Does it visit any unreachable states? No: following the “inverse” of the argument above, if s is inserted into V , either this is done because of the main loop, or because of the loop in lines 3-6. In the first case, s must be in S 0 , so it’s an initial state, so it’s reachable. In the second case, s must be successor of some s′, which by induction must be itself in V , therefore reachable. What is the complexity of the algorithm? O(n + m) where n is number of nodes/states and m is number of edges/transitions in the graph. Every node and edge are visited at most once. Stavros Tripakis (UC Berkeley) EE 244, Fall 2016 Model Checking 13 / 68
Every search algorithm on finite graphs can be used for reachability analysis: DFS: depth-first search BFS: breadth-first search Best-first search: I (^) every state is assigned a “value” (using some heuristic value function, e.g., how “close” we are likely to be to the goal – in our case a “bad” state) and then next state to explore is the one with the highest value. A*: classic search technique in artificial intelligence. ...
Every search algorithm on finite graphs can be used for reachability analysis: DFS, BFS, A*, ...
Most of these have been tried by researchers in verification. Basic complexity is the same for all: need to store all reachable states I (^) in the “worst case” from the algorithmic point of view I (^) but in fact “best case” from the verification point of view, since we are trying to prove that our system is correct! ⇒ all reachable states must be correct State explosion: the number of reachable states is too large
Stavros Tripakis (UC Berkeley) EE 244, Fall 2016 Model Checking 15 / 68
How many states does a chip with 100 flip-flops have? I (^2100) (potentially reachable) states. I (^) That is 1267650600228229401496703205376 states. I (^) Even if each state costs 1 bit to store, this still makes 2100 −^60 −^3 = 2^37 = 137, 438 , 953 , 472 exabytes ... I (^) Even if only 321 states are reachable, this still makes 2100 −^5 = 2^95 states. How many states does a piece of concurrent software have? Assume n asynchronous processes (e.g., threads), with k states each. I (^) kn^ (potentially reachable) states. What if the processes also communicate with queues? Consider a single queue of size (i.e., can hold messages), and m possible types of messages. I (^) m`^ (potentially reachable) states for just one queue.
Stavros Tripakis (UC Berkeley) EE 244, Fall 2016 Model Checking 19 / 68
Motivation: attack the state explosion problem.
A seminal paper: Symbolic model checking: 1020 states and beyond. [Burch et al., 1990].
1020 is less than 267 , so still not quite enough for modern circuits.
Nevertheless: a great leap forward at that time.
Key idea: Instead of reasoning about individual states, reason about sets of states.
How do we represent a set of states?
Symbolic representation: Set = predicate.
Set of states = predicate on state variables.
Stavros Tripakis (UC Berkeley) EE 244, Fall 2016 Model Checking 21 / 68
Examples:
(^1) Assume 3 state variables, p, q, r, of type boolean.
S 1 : p ∨ q = {pqr, pqr, pqr, pqr, pqr, pqr}
(^2) Assume 3 state variables, x, i, b, of types real, integer, boolean.
S 2 : x > 0 ∧ (b → i ≥ 0)
How many states are in S 2?
Kripke structure: (P, S, S 0 , L, R)
Symbolic representation:
(P, Init, Trans)
where P = {x 1 , x 2 , ..., xn}: set of (boolean) state variables, also taken to be the atomic propositions.^1 Predicate Init(~x) on vector ~x = (x 1 , ..., xn) represents the set S 0 of initial states. Predicate Trans(~x, ~x′) represents the transition relation R. Basis of the language of NuSMV. (^1) this is done for simplicity, the two could be separated Stavros Tripakis (UC Berkeley) EE 244, Fall 2016 Model Checking 25 / 68
MODULE inverter(input) VAR output : boolean; INIT output = FALSE TRANS next(output) = !input | next(output) = output
What is the Kripke structure defined by this NuSMV program?
What about P and L?
Represent this symbolically.
Stavros Tripakis (UC Berkeley) EE 244, Fall 2016 Model Checking 27 / 68
Main idea: Start with set of initial states S 0. Compute S 1 := S 0 ∪ {all 1-step successors of S 0 }. Compute S 2 := S 1 ∪ {all 1-step successors of S 1 }. ... Until Sk+1 = Sk. Sk contains all reachable states.
Stavros Tripakis (UC Berkeley) EE 244, Fall 2016 Model Checking 31 / 68
Given a set of states represented as a predicate φ(~x).
We want to compute a new predicate φ′, representing the set of all 1-step successors of states in φ(~x).
Successors can be computed by a predicate transformer :
succ
φ(~x)
∃~x : φ(~x) ∧ Trans(~x, ~x′)
[~x′^ ; ~x] I (^) ∃~x : φ(~x) ∧ Trans(~x, ~x′): successors of states in φ I (^) [~x′^ ; ~x]: renames variables so that resulting predicate is over current state variables
Example:
φ = 0 ≤ x ≤ 5 Trans = x ≤ x′^ ≤ x + 1 succ(φ) = (∃x : 0 ≤ x ≤ 5 ∧ x ≤ x′^ ≤ x + 1)[x′^ ; x] = (∃x : 0 ≤ x ≤ 5 ∧ 0 ≤ x′^ ≤ 5 + 1)[x′^ ; x] = (0 ≤ x′^ ≤ 6)[x′^ ; x] = 0 ≤ x ≤ 6 Stavros Tripakis (UC Berkeley) EE 244, Fall 2016 Model Checking 33 / 68
succ
φ(~x)
∃~x : φ(~x) ∧ Trans(~x, ~x′)
[~x′^ ; ~x]
How to do quantifier elimination automatically?
In the case of propositional logic, quantifier elimination is simple. Suppose x is a boolean variable:
∃x : φ ⇔ φ[x ; 0] ∨ φ[x ; 1]
1: Reachable := Init; 2: terminate := false; 3: error := false; 4: repeat 5: tmp := Reachable ∨ succ(Reachable); 6: if tmp ⇔ Reachable then 7: terminate := true; 8: else 9: Reachable := tmp; 10: end if 11: if SAT(Reachable ∧ Bad ) then 12: error := true; 13: end if 14: until terminate or error 15: return (Reachable,error); Stavros Tripakis (UC Berkeley) EE 244, Fall 2016 Model Checking 37 / 68
Let’s check this system symbolically! We want to check that all reachable states satisfy p ∨ q. In temporal logic parlance:
CTL: AG(p ∨ q) LTL: G(p ∨ q)
For finite-state systems, boolean variables can be used to encode state. All predicates then become boolean expressions. Efficient data structures for boolean expressions: I (^) BDDs (Binary Decision Diagrams) [Bryant, 1992] (paper available in bcourses - follow link from lectures web page) Efficient algorithms for implementing logical operations (conjunction, disjunction, satisfiability check, ...) on BDDs. Note: logical operations correspond to set-theoretic operations: I (^) Conjunction: intersection I (^) Disjunction: union I (^) Satisfiability check: emptiness check I (^) ...
Stavros Tripakis (UC Berkeley) EE 244, Fall 2016 Model Checking 39 / 68
Can you guess which boolean expression this BDD represents?
x 4
x 3 (x 2 + x 2 x 1 ) + x 3 (x 2 x 1 + x 2 )