Back to Program Verification Index | Previous: (y-14) Bounded Model Checking | Next: (y-16) Abstractions and ARG

Mental Model for Assert Statements

FeaturePre-Post PairAssert Statements
LocationExit onlyAnywhere in code
ScopeGlobal (Full path)Local (Specific point)
GranularityCoarseFine-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 P is reached and is false, the program is considered erroneous at that exact location.
  • Translation to CFG: In a Control-Flow Graph, an assert P becomes 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 expr is evaluated when the statement is reached.
  • Behavior: If true, the execution continues. If false, 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;
  1. Assume: Filters the world so we only care about .
  2. 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:

  1. Success: (Path continues).
  2. 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

  1. Assert Statements specify local correctness properties.
  2. CFGs model asserts as branches to special Error Locations.
  3. Error Configuration: A pair where is an error location.
  4. Abstract Error Configuration: A pair where is an error location and is satisfiable.
  5. Safety: Proving a program is safe means proving that its error locations are unreachable.

Self-Check

  1. What does an assert P statement mean operationally, and how is it different from assume P?
  1. How is an assert expr translated into a CFG?
  1. What does “program safety” reduce to in this framework?
  1. Why are local assertions more expressive than a single pre/post specification?
  1. In the example assume x > 0; x := x - 1; assert x >= 0;, why is the assert 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