Back to Program Verification Index | Previous: (y-13) Predicate Transformers | Next: (y-15) Correctness via Assert Statements

Mental Model for BMC and Synthesis

  • Bounded Model Checking (BMC): Don’t try to prove everything. Just check “Is there a bug in the first steps?”
  • Bug Hunter: BMC is the fastest way to find shallow bugs in programs with large state spaces.
  • Loop Unrolling: We “unroll” the loop times and convert it into a single (very large) logic formula for the SMT solver.
  • Invariant Synthesis: Instead of guessing a loop invariant, we create a Template (e.g., ) and use the solver to find the coefficients .

Bounded Model Checking (BMC)

BMC is an Incomplete verification technique. It is highly effective at finding bugs but cannot generally prove that a program is safe for all possible inputs if it contains loops with unknown bounds.

1. Loop Unrolling for steps

To check for bugs in a program with a loop, we “unroll” the loop times:

  • A while (B) { body } becomes a nested structure of if (B) { body } statements.
  • After the -th iteration, we add an assume !B statement. This tells the solver to only consider executions that terminate within steps.
  • If the solver finds a counterexample, it has found a real bug that occurs within iterations.

2. Single Static Assignment (SSA) Form

To turn a sequence of statements (a path) into a single SMT formula, we use SSA form:

  • Every time a variable x is assigned, we create a new version of that variable (x1, x2, x3...).
  • Example:
    • Path: x := 1; x := x + 1; assume x > 2;
    • SSA Formula:
  • This formula is sent to an SMT solver like Z3. If it is Satisfiable, the path is feasible and the bug is real.

💡 Intuition: Flashlight vs. Floodlight

  • Inductive Invariants (Floodlight): Proving an invariant is like turning on a floodlight. It illuminates the entire state space at once, showing that no part of the “safe” area can ever lead to the “error” area. It is powerful but can be hard to find.
  • BMC (Flashlight): BMC is like a flashlight. You can point it down a specific path to a depth of steps. It shows you everything in that beam with perfect clarity (no need for invariants!), but it cannot see anything outside the beam or beyond the -th step.

Constraint-Based Invariant Synthesis

Finding loop invariants is the hardest part of verification. Synthesis tries to automate it.

1. The Template

We assume the invariant has a certain shape (a “Template”). Example: (where are unknown constants).

2. The Constraints

We generate three types of constraints based on the Hoare While Rule:

  • Precondition:
  • Inductivity:
  • Postcondition:

3. Solving

We use an SMT solver (specifically one that handles Horn Clauses) to find values for that satisfy all these conditions simultaneously.


The Verifier Hierarchy

TechniqueGoalEffortCompleteness
BMCFind BugsLowIncomplete
CEGARProof/BugHighComplete (for finite state)
Trace AbstractionProof/BugHighComplete (for finite state)
SynthesisFind InvariantsHighComplete (if template is correct)

Summary

  1. BMC is a powerful bug-finding technique that unrolls loops to a fixed depth .
  2. BMC is fast but cannot prove safety if the loop runs more than times.
  3. Invariant Synthesis uses math to “calculate” the reason a program is safe.
  4. Templates provide a structure for the solver to find the missing logic.
  5. SMT Solvers are the underlying engine for both BMC and Synthesis.

Self-Check

  1. Why is BMC called “incomplete,” and when is it still useful?
  1. Convert the path x := 1; x := x + 1; assume x > 2 into SSA form and write the resulting SMT formula.
  1. What three verification conditions does constraint-based invariant synthesis generate, and what role do they play?
  1. What is a template in invariant synthesis, and what does the solver do with it?
  1. Compare BMC and inductive-invariant proofs using the flashlight versus floodlight metaphor.

Back to Program Verification Index | Previous: (y-13) Predicate Transformers | Next: (y-15) Correctness via Assert Statements | (y) Return to Notes | (y) Return to Home