Definition
Bounded model checking (BMC) is an automatic verification method that decides whether a model of a system has an execution of at most steps, starting in an initial state, that violates a stated property. BMC writes this question as one logical formula that is satisfiable, meaning that some values of its variables make it true, exactly when such an execution exists, and a program called a solver searches for such values. Values found describe a counterexample, the violating execution; if none exist, no violation occurs within steps.
The idea
Many defects appear within a few steps of the start: a counter that wraps around on its eighth increment, or a protocol that accepts a message one step too early. Model checking §3.30 in full settles a property for executions of every length, which needs the set of all reachable states §3.21, and that set is often too large to compute; this is the problem of state explosion §3.26. Bounded model checking gives up the claim about every length. In return it gives an exact, automatic answer about every execution up to the bound, including every choice of input along the way. Armin Biere, Alessandro Cimatti, Edmund Clarke and Yunshan Zhu introduced the method in 1999. They used a solver for the Boolean satisfiability problem (SAT), which asks whether true-or-false values can be given to variables so that a formula becomes true.
The core idea is to unroll time. Make one copy of the system’s variables for each moment . Write one constraint saying that copy 0 is an initial state, one constraint per step saying that copy follows from copy by an allowed step, and one constraint saying that the property fails at some moment. Every solution of the whole formula is then a violating execution, so a solver that finds solutions finds bugs. The picture is a maze: instead of walking its corridors, the method writes the whole route of moves as a puzzle with unknowns and asks whether any way of filling them in ends in the forbidden room. The puzzle says nothing about routes longer than moves.
How it works
Bounded model checking needs three inputs.
A transition system. Its state is the values of all its variables. A formula is true exactly when is an initial state, and a formula is true exactly when state can follow state in one step. An input that the environment supplies at a step becomes a variable that the solver may choose freely, so every allowed input value is covered.
A property , true in the good states. Bounded model checking is mainly used for safety properties §1.11, which say that something bad never happens; a violation of one shows up in a finite execution.
A bound and its unit. For a transition system the unit is one step.
The check runs as follows.
Make copies of the state variables, one for each moment.
Build the formula: is an initial state, each follows for from 0 to , and fails in at least one of .
Translate the formula into the solver’s language. For hardware, every bit becomes a true-or-false variable and a SAT solver decides the formula. For software, integers become fixed-width bit vectors, so that wrap-around and overflow are modeled exactly, and an SMT solver §3.28 (satisfiability modulo theories solver, a SAT solver extended with such arithmetic) decides it.
Read the verdict. Satisfiable: the solver’s values for form a counterexample. Unsatisfiable: no execution of the model violates within steps. Unknown, because the solver timed out or ran out of memory: no conclusion either way.
Usually repeat with until a counterexample appears or the time budget ends. The first bound that gives a counterexample is the length of the shortest violating execution.
For a program, the unit of the bound is usually the number of loop iterations. The tool unrolls each loop times: it copies the loop body times, each copy guarded by the loop condition. It then rewrites the code in static single assignment §3.38 (SSA) form, in which every variable is assigned exactly once, so that each assignment becomes an equation. CBMC (C Bounded Model Checker) is a widely used tool of this kind. After the last copy, the tool must say what happens to executions that would run the loop again. An unwinding assertion asks the solver whether the loop condition can still be true at that point; if it can, the tool reports that the bound is too small. An unwinding assumption silently discards those executions, so a clean result then covers only executions that leave every loop within iterations. Other units in use are the depth of recursive calls and the number of switches between threads.
Worked example
A missed and a found violation. A 3-bit counter holds a whole number from 0 to 7. It starts at 0, and each step sets to , the remainder of after division by 8. The property is . Write for the value of at moment . With the formula is where means and and means or; the remainder is left out because no value reaches 8. The equations force to be 0, 1, 2, 3, 4. None of them is 5, so the formula is unsatisfiable: no violation within 4 steps. With the equations also force , the formula is satisfiable, and the counterexample is the execution 0, 1, 2, 3, 4, 5. The answer at was true, and it still did not show that the property holds.
Why every moment is checked. With the forced values are 0, 1, 2, 3, 4, 5, 6. A formula that asked only whether the last value is 5 would be unsatisfiable, although the execution passed through 5 at moment 5. The disjunction, the chain of ors over all moments from 0 to , catches the visit.
The solver chooses the inputs. Now let each step set to , where the environment supplies , either 1 or 2, afresh at every step. With , , is 1 or 2, and is 2, 3 or 4, so no value is 5 and the formula is unsatisfiable. With , can be 3, 4, 5 or 6, and the solver returns one choice that reaches 5, for example , which gives the execution 0, 1, 3, 5. A tester would have had to guess that input sequence.
Turning a bounded answer into a proof. Let each step add 2 instead: becomes , starting at 0, and the property is again . The executions visit 0, 2, 4, 6, 0, 2 and so on, so every bound gives unsatisfiable, and the question is when the check may stop. Two arguments end it.
Completeness §3.8 threshold. The tool asks for an execution of 4 steps from an initial state whose 5 states are all different. The only execution is 0, 2, 4, 6, 0, which repeats 0, so the answer is unsatisfiable. A shortest route to any state never repeats a state, so every reachable state is reached within 3 steps, and the check of moments 0 to 3 has examined all of them.
Induction. Plain induction asks whether some state that satisfies the property can step to a state that violates it, without requiring the first state to be reachable. The solver says yes: 3 steps to 5. The state 3 is unreachable, but plain induction has failed. The 4-step version asks for four consecutive states that all satisfy , followed by the value 5. Each value has exactly one predecessor here, so the four states before 5 must be 5, 7, 1, 3, and the first of them violates the property; the answer is unsatisfiable. Together with the bounded check of moments 0 to 3, which sees 0, 2, 4, 6, this 4-step induction proves in every reachable state. The stronger property “ is even” is preserved by every step and implies , so plain induction succeeds for it at once.
Stated precisely
Let , and be as above, and let be copies of the state variables. Write for and, for or and for not; a large or joins all its terms in the same way. Bounded model checking to depth asks whether is satisfiable.
Assume that every state has at least one successor. Then is satisfiable exactly when some execution that starts in an initial state reaches a state violating within at most steps. In the notation of the Reachability entry, where is the set of states reachable within steps, unsatisfiable means that every state in satisfies . The assumption matters. If an execution can stop, for example in a program’s exit state or in a fault state, then a bad state reached at step 2 that has no successor is missed by , because the formula demands three steps. Tools avoid this by giving each final state a step to itself, or by checking each depth with alone.
An unsatisfiable extends to every reachable state in two cases.
Completeness threshold. Let be the smallest number such that every reachable state is reachable within steps. If , then contains every reachable state, so holds in all of them. A tool can rarely compute directly, but it can bound it: if no execution of steps from an initial state has all its states different, then .
-induction. Suppose that is unsatisfiable (the base case) and that is unsatisfiable for every , initial or not (the induction step). Then holds in every reachable state. The first states of any execution satisfy by the base case, and, by induction on the position, every later state is preceded by states that satisfy , so the induction step forbids it to violate . Adding the requirement that are all different makes the induction step succeed for some on every system with finitely many states whose reachable states all satisfy . Replacing by a stronger property that holds in every initial state and is preserved by every step, an inductive invariant §19.2.4, lets plain induction succeed.
Every conclusion above holds only under four conditions.
The solver returned unsatisfiable; unknown proves nothing.
The formula encodes , and exactly, including fixed-width arithmetic.
The model contains every behavior of the environment that the claim covers: every input value, every failure and every interleaving of threads.
For a program, every unwinding assertion held; otherwise the result covers only executions within the loop bounds.
Limits and common mistakes
A larger bound is more evidence, not a proof. Without a completeness threshold or an induction argument, a clean result at says nothing about step 1001. The formula grows in proportion to , but the solver’s running time can grow exponentially with it, so deep bounds are often out of reach.
Contradictory assumptions make every check pass. Constraints on the environment, such as assume(x > 5) together with assume(x < 3), can leave no execution at all, and with no execution there is no counterexample. Check that the assumptions admit executions, for example by asking the tool for one execution that reaches the checked statement.
The unit of the bound must be stated. Ten loop iterations are not ten instructions, and a loop that normally runs 64 times is not covered by a bound below 64.
A liveness property §1.12, which says that something good eventually happens, needs a different shape of counterexample. A violation of “every request is eventually answered” is an infinite execution. Bounded model checking finds it only as a lasso: a finite execution whose last state equals an earlier one, so that the loop between them can repeat forever without the answer. Finding no lasso within steps proves nothing about the liveness property.
A counterexample is real for the model, not automatically for the system. If the model lets an input take a value that the hardware never produces, the counterexample may be impossible in practice; check it against the real system.
Questions answered
What does no counterexample up to depth k establish?
No counterexample up to depth establishes that no execution of the model that starts in an initial state and takes at most steps reaches a state that violates the checked property. Three conditions must hold for even that bounded claim. The solver answered unsatisfiable, not unknown or timeout §9.34. The formula checked the property at every moment from 0 to , not only at moment , and it handled executions that stop early. The model, its assumptions about the environment and, for a program, its loop bounds admit every behavior the claim is about; if unwinding assumptions cut off longer runs of a loop, those runs were never examined.
It establishes nothing about step or later. The bounded result becomes a proof for all executions only with an extra argument. Either is at least a completeness threshold, for example because no execution of steps from an initial state has all its states different, or an induction proof such as -induction succeeds. Without one of these, a deeper search is more evidence, not a proof.
Related entries: Reachability (§3.21), SMT solver (§3.28), Model checking (§3.30), State explosion (§3.26), Safety property (§1.11). Further reading: [228].