Back to Program Verification Index | Previous: (y-14) Bounded Model Checking | Next: (y-16) Abstractions and ARG
Mental Model for Assert Statements
| Feature | Pre-Post Pair | Assert Statements |
|---|---|---|
| Location | Exit only | Anywhere in code |
| Scope | Global (Full path) | Local (Specific point) |
| Granularity | Coarse | Fine-grained |
- Internal Correctness: Instead of checking a “Pre-Post” pair at the very end, Assert statements let us specify correctness anywhere in the code.
- Immediate Error: If an
assert Pis reached and is false, the program is considered erroneous at that exact location. - Translation to CFG: In a Control-Flow Graph, an
assert Pbecomes a fork: one path where holds (Normal) and one where holds (Error). - Error Locations: We verification tools look for a path from the initial location to a special Error Location () created by these asserts.
The assert Statement

In Boogie and Boostan, assert expr; is a fundamental building block.
- Evaluation: The expression
expris evaluated when the statement is reached. - Behavior: If
true, the execution continues. Iffalse, the program is Incorrect.
Program Safety
A program is considered safe if all reachable error states are false (i.e., they are unreachable). Formally, for every error location , if is an abstract configuration reachable from the initial state, then .
Example: Assert vs Assume
assume x > 0;
x := x - 1;
assert x >= 0;- Assume: Filters the world so we only care about .
- Assert: Checks if the promise holds after the decrement.
CFG with Error Locations

When we translate a program with asserts into a Control-Flow Graph (CFG), we add Error Locations.
Translation of assert expr;

For a location , an assert expr; creates two outgoing transitions:
- Success: (Path continues).
- Failure: (Leads to an error).
A Program is Safe if NO path exists from the start to ANY error location.
💡 Intuition: Correctness as Reachability
Imagine a program as a building.
- Pre/Post-conditions: You only care if the person exited through the right door.
- Assert Statements: You placed “security cameras” (asserts) in every room. If the person is caught doing something wrong in any room, the whole visit is considered a failure.
- Verification: The verifier acts as a security guard, proving that there is no possible path a visitor can take to trigger any of the cameras.
Summary
- Assert Statements specify local correctness properties.
- CFGs model asserts as branches to special Error Locations.
- Error Configuration: A pair where is an error location.
- Abstract Error Configuration: A pair where is an error location and is satisfiable.
- Safety: Proving a program is safe means proving that its error locations are unreachable.
Self-Check
- What does an
assert Pstatement mean operationally, and how is it different fromassume P?
Answer
assert Pis a check at this exact program point: if is false the program is considered incorrect.assume Pis a constraint: paths where is false simply disappear, no error is raised. Asserts produce bugs; assumes filter the state space.
- How is an
assert exprtranslated into a CFG?
Answer
The source location gains two outgoing edges: an
assume expredge to the successor for the success case, and anassume !expredge to a dedicated error location for the failure case. Reaching in any execution constitutes an assertion failure.
- What does “program safety” reduce to in this framework?
Answer
Safety means no path of the CFG from the initial location reaches any error location. Equivalently, every abstract configuration reachable from the initial state must have equivalent to
false. Verification becomes a graph reachability question with logical conditions on edges.
- Why are local assertions more expressive than a single pre/post specification?
Answer
A pre/post pair only checks the overall input-output relationship at the exit point. Asserts let you specify local invariants at any program point (loop heads, just after a critical assignment, before a dangerous operation). This catches bugs at the exact point they manifest, rather than letting them propagate to the final state.
- In the example
assume x > 0; x := x - 1; assert x >= 0;, why is the assert safe?
Answer
The
assume x > 0filters to states where (integer domain). Afterx := x - 1, the new is at least . The assert therefore holds along every surviving path, so the error location is unreachable and the fragment is safe.
Back to Program Verification Index | Previous: (y-14) Bounded Model Checking | Next: (y-16) Abstractions and ARG | (y) Return to Notes | (y) Return to Home