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 ofif (B) { body }statements. - After the -th iteration, we add an
assume !Bstatement. 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
xis assigned, we create a new version of that variable (x1, x2, x3...). - Example:
- Path:
x := 1; x := x + 1; assume x > 2; - SSA Formula:
- Path:
- 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
| Technique | Goal | Effort | Completeness |
|---|---|---|---|
| BMC | Find Bugs | Low | Incomplete |
| CEGAR | Proof/Bug | High | Complete (for finite state) |
| Trace Abstraction | Proof/Bug | High | Complete (for finite state) |
| Synthesis | Find Invariants | High | Complete (if template is correct) |
Summary
- BMC is a powerful bug-finding technique that unrolls loops to a fixed depth .
- BMC is fast but cannot prove safety if the loop runs more than times.
- Invariant Synthesis uses math to “calculate” the reason a program is safe.
- Templates provide a structure for the solver to find the missing logic.
- SMT Solvers are the underlying engine for both BMC and Synthesis.
Self-Check
- Why is BMC called “incomplete,” and when is it still useful?
Answer
BMC only checks executions up to a fixed unrolling depth . If no counterexample is found within steps, there could still be a bug at depth , so BMC cannot prove unbounded safety. It is still useful as a fast bug-finder: any counterexample it returns is a real bug, and most shallow bugs surface at small .
- Convert the path
x := 1; x := x + 1; assume x > 2into SSA form and write the resulting SMT formula.
Answer
Rename each assignment to a fresh version: , then , then the constraint . The conjunction is sent to the solver. If satisfiable, the path is feasible; here , so the formula is unsatisfiable and this path is infeasible.
- What three verification conditions does constraint-based invariant synthesis generate, and what role do they play?
Answer
Precondition implication , inductivity , and postcondition . These exactly mirror the three obligations of the Hoare while rule: that the invariant holds on entry, is preserved by one iteration, and is strong enough at exit to imply .
- What is a template in invariant synthesis, and what does the solver do with it?
Answer
A template is a parameterized formula like with unknown coefficients. The synthesis problem becomes finding numeric values for those coefficients that make all three verification conditions valid. A Horn-clause SMT solver searches for such values; if it finds them, the instantiated template is a valid loop invariant.
- Compare BMC and inductive-invariant proofs using the flashlight versus floodlight metaphor.
Answer
BMC is a flashlight pointed down one path of length : it shows that beam in perfect detail without needing invariants, but anything outside the beam or beyond depth is dark. An inductive invariant is a floodlight: it covers the entire reachable state space at once, proving safety unboundedly, but constructing it (finding the invariant) is the hard part.
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