Section 3.30

Model checking

Definition

Model checking is an automatic verification method that decides whether a model of a system, usually one with finitely many states, satisfies a property. The model is a transition system: its states, its initial states and the allowed steps between states. The property is usually written in a temporal logic, a logic for statements about how states follow one another over time, as in “every request is eventually granted”. A model checker examines every execution of the model and confirms the property or returns a counterexample that violates it.

The idea

Concurrent and reactive systems fail in executions that tests rarely produce: one particular interleaving of two threads, or a message lost at one particular moment. Two threads of 10 steps each can interleave in 20!/(10!⋅10!)=184,75620! / (10! \cdot 10!) = 184{,}756 orders, where n!n! is the product 1⋅2⋅…⋅n1 \cdot 2 \cdot \dots \cdot n, and a test run sees one of them. Model checking replaces sampling with exhaustive search. If the model has finitely many states, an algorithm §14.1 can visit every reachable state §3.21 and, for properties about infinite executions, every reachable cycle. Edmund Clarke and Allen Emerson, and independently Jean-Pierre Queille and Joseph Sifakis, introduced the method in the early 1980s. Clarke, Emerson and Sifakis received the 2007 Turing Award for it.

The obstacle is state explosion §3.26. A global state is a combination of one local state for every component, so the number of global states is the product of the numbers of local states. Ten processes with 4 local states each have up to 410=1,048,5764^{10} = 1{,}048{,}576 global states. Model checkers therefore apply reductions, which explore a smaller model that gives the same verdict. The catch is that “the same verdict” depends on the property. Exploring only one order of two steps is safe when the property cannot see the order and wrong when it can, so each reduction comes with a theorem that names the properties it preserves.

How it works

A model checker takes three inputs.

The search depends on the property.

  1. An invariant 𝐆p\mathbf{G}\,p, the simplest safety property §1.11, holds when no reachable state violates pp. The checker searches the reachable states as described in the Reachability entry; a breadth-first search §14.18 returns a shortest path to a violating state as the counterexample.

  2. A general LTL formula, including a liveness property §1.12 such as 𝐆(request→𝐅grant)\mathbf{G}(\mathrm{request} \rightarrow \mathbf{F}\,\mathrm{grant}), “every request is eventually followed by a grant”. The checker builds a Büchi automaton for the negation of the formula: a machine that reads an infinite sequence of states and accepts it when its run passes through an accepting state infinitely often. This automaton accepts exactly the executions that violate the formula. The checker combines the automaton with the model and searches for a reachable cycle through an accepting state. The counterexample is a lasso: a finite path followed by a cycle that repeats forever, for example a request after which the system loops without ever granting it.

  3. A CTL formula. The checker computes, from the innermost subformula outward, the set of states in which each subformula holds. The set for 𝐄𝐅q\mathbf{EF}\,q, for example, contains the states from which some path reaches qq; it is computed by repeatedly adding predecessors until nothing changes.

Explicit-state checkers store each visited state. Symbolic checkers represent sets of states by formulas, such as binary decision diagrams (compact graphs that encode a true-or-false function of many bits), or pass the question to a satisfiability solver, as bounded model checking §3.29 does. A run ends with the property confirmed for the model, with a counterexample, or out of time or memory, which proves nothing.

The main reductions are these.

Worked example

A dependence that a reduction must respect. Threads A and B each increment a shared variable xx, which starts at 0, in two steps. Step A1 reads xx into a private register of A, and step A2 writes that register plus 1 back to xx; steps B1 and B2 do the same for B. Each thread’s two steps stay in order, so there are 4!/(2!⋅2!)=64! / (2! \cdot 2!) = 6 interleavings. In A1 A2 B1 B2 and in B1 B2 A1 A2, the second thread reads the value 1 and xx ends at 2. In the other four, for example A1 B1 A2 B2, both threads read 0, both write 1, and xx ends at 1: an update is lost. The property “when both threads have finished, x=2x = 2” is therefore violated. A1 and B1 are independent, since both only read xx, so a partial-order reduction may explore just one of their two orders. A2 and B1 are dependent, since one writes xx and the other reads it, so both of their orders must be explored. A reduction that wrongly treated every pair as independent and explored only A1 A2 B1 B2 would report that the property holds.

An order the property can see. Thread A sets xx from 0 to 1, and thread B sets yy from 0 to 1. The two actions are independent: both orders end in the state x=1,y=1x = 1, y = 1. For the property “finally x=1x = 1 and y=1y = 1” one order suffices. For 𝐆(y=1→x=1)\mathbf{G}(y = 1 \rightarrow x = 1), “yy never becomes 1 before xx does”, the order is everything. A then B passes through (x,y)=(1,0)(x, y) = (1, 0) and satisfies the property, while B then A passes through (0,1)(0, 1) and violates it. Both actions change an atomic proposition of this property, so partial-order reduction may not drop either order.

A symmetry the property must share. Three identical processes are each idle, waiting or critical, so the system has 33=273^3 = 27 global states. Merging states that differ only by which process is which leaves one state for each way of splitting the 3 processes among the 3 conditions: 5!/(3!⋅2!)=105! / (3! \cdot 2!) = 10 states. The property “at most one process is critical” does not depend on which process is which, so the 10-state model gives the right verdict for it. The property “process 1 is never critical” does depend on it: the merged state “one process critical” does not say which one, so the reduced model cannot decide this property.

Stated precisely

A Kripke structure is M=(S,I,R,L)M = (S, I, R, L). SS is the set of states, I⊆SI \subseteq S the set of initial states, R⊆S×SR \subseteq S \times S the transition relation, in which every state has at least one successor, and L(s)L(s) the set of atomic propositions true in state ss. A path is an infinite sequence s0s1s2…s_0 s_1 s_2 \dots with s0∈Is_0 \in I and (si,si+1)∈R(s_i, s_{i+1}) \in R for every ii. For an LTL formula φ\varphi, M⊨φM \models \varphi (MM satisfies φ\varphi) means that every path of MM satisfies φ\varphi.

A reduction replaces MM by a smaller structure M′M'. It preserves φ\varphi when M⊨φM \models \varphi holds exactly when M′⊨φM' \models \varphi holds. It is sound in one direction when M′⊨φM' \models \varphi implies M⊨φM \models \varphi. The standard results are these.

  1. Cone of influence preserves every property that mentions only kept variables, because a deleted variable never feeds a kept one.

  2. Bisimulation minimization preserves every formula of CTL*, the logic that contains both LTL and CTL.

  3. Symmetry reduction under a group GG of renumberings of the components preserves every CTL* formula whose atomic propositions are unchanged by every renumbering in GG.

  4. Partial-order reduction preserves every LTL formula that does not use 𝐗\mathbf{X}, provided the set ample(s)\mathrm{ample}(s) of actions explored in each state ss meets four conditions. (C0) It is empty only when no action is enabled in ss. (C1) On every path of the full model that starts in ss, no action that depends on an action in ample(s)\mathrm{ample}(s) runs before some action of ample(s)\mathrm{ample}(s) has run. (C2) If ample(s)\mathrm{ample}(s) leaves out some enabled action, every action in it is invisible: it changes no atomic proposition of the formula. (C3) No cycle of the reduced model contains a state in which some action is enabled but never chosen for the ample set of any state on the cycle. Formulas with 𝐗\mathbf{X} are excluded because the reduced model may take fewer invisible steps between two visible ones than the full model, and only 𝐗\mathbf{X} can tell such executions apart.

  5. Abstraction as described above, with an abstract step wherever some merged concrete states have a step, is sound in one direction for universal properties: every LTL formula, and every CTL formula that uses only the quantifier 𝐀\mathbf{A} and applies negation only to atomic propositions. The concrete states merged into one abstract state must agree on every atomic proposition of the formula. An abstract counterexample may be spurious, meaning that no concrete execution follows it; counterexample-guided abstraction refinement §15.13 checks it against MM and makes the abstraction finer when it is spurious.

Limits and common mistakes

A verdict is about the model. Whether the code behaves like the model is a separate claim, treated in the Refinement §3.32 entry. A model that leaves out a failure, such as a lost message, cannot find the bugs that failure causes.

A property can hold vacuously. 𝐆(request→𝐅grant)\mathbf{G}(\mathrm{request} \rightarrow \mathbf{F}\,\mathrm{grant}) holds in a model in which no request is ever made. Check that the condition that triggers the property is reachable.

Fairness assumptions cut both ways. Too strong, they hide real starvation §9.18, in which a process waits forever; too weak, they produce counterexamples in which the scheduler behaves in a way no real scheduler does.

A one-way abstraction transfers only a pass, and only for universal properties. “Some path can still reach a reset” is not preserved, because the abstract model has paths that no concrete execution follows.

Unbounded data, such as integers, queues and heaps, gives infinitely many states. A checker then works on a bounded instance, such as 3 processes and a queue of length 2, or on an abstraction, and the verdict covers only that instance or abstraction.

Running out of time or memory is not a pass. Some tools offer approximate search modes that may skip states to save memory; a clean result in such a mode is a partial search, not a proof.

Reductions can be combined only if each one still meets its conditions in the combined model, and the combined result covers only properties that every reduction involved preserves.

Questions answered

Which reductions preserve the property being checked?

A reduction preserves the property being checked only when a theorem covers both that reduction and that class of property, and the theorem’s conditions hold for the property’s own atomic propositions, the basic facts it mentions. A smaller graph, or agreement with the full model on a few examples, does not show that a reduction is correct. The standard cases are these.

A reduction valid for a property about final values can therefore be invalid for a property about order, about eventual progress or about one named component.

Related entries: Reachability (§3.21), State explosion (§3.26), Refinement (§3.32), Bounded model checking (§3.29), Liveness property (§1.12), Counterexample-guided abstraction refinement (CEGAR) (§15.13). Further reading: [226, 227].