Back to Program Verification Index | Previous: (y-18) Trace Abstraction and Floyd-Hoare Automata

Mental Model for Invariant Synthesis

  • Automating the Guesswork: Finding the right loop invariant is the hardest part of verification. Invariant Synthesis turns this creative task into a Search problem that a computer can solve.
  • Template-Based Search: We define the “shape” of our invariant (e.g., ) and let the solver find the coefficients .
  • From Hoare to Horn: We translate the Hoare proof rules into mathematical constraints called Horn Clauses.
  • The Engine of Proofs: Synthesis is how modern verifiers generate the “reasons” why code is safe, even when no human provided them.

The Problem of Invariants

To prove a loop while B { body } safe, we need an invariant such that:

  1. Initial Entry:
  2. Inductivity:
  3. Safety Exit:

If is missing, we can’t build a proof. Synthesis finds for us.


1. Templates

A template is a formula with Unknown Parameters (placeholders).

  • Linear Template: (where are parameters to find).
  • Interval Template:

The solver’s goal is to find concrete values for these parameters that make the Hoare rules work for all possible program executions.


2. Horn Clauses

A Constrained Horn Clause (CHC) is a formula of the form:

  • is a pure theory formula (e.g., ).
  • are Uninterpreted Predicates (the unknown invariants).

Example: Horn Clauses for a Loop

For a loop while B { body }, the requirements are encoded as:

  1. Entry:
  2. Inductivity:
  3. Safety:

Verification tools convert the entire program into a set of CHCs and use specialized SMT solvers like Spacer (part of Z3) or Eldarica to find the solution.


💡 Intuition: Connecting the Dots

Imagine you have two points (Initial and Error) and you need to build a “wall” (Invariant) that separates them.

  • BMC checks if you can walk around the wall’s current edges.
  • Abstraction tries to build the wall from a fixed set of bricks.
  • Synthesis calculates the exact mathematical equation of the wall that perfectly splits the space into “Safe” and “Dangerous.”

The Verifier Hierarchy (Review)

TechniqueGoalEffortBest For
BMCFind BugsLowRapid debugging
CEGARProof/BugHighUnknown predicates
Trace AbstractionProof/BugHighLarge CFGs
SynthesisFind InvariantsHighMathematical/Numerical loops

Summary

  1. Invariant Synthesis automates the most difficult task in program verification.
  2. Templates restrict the search space to specific shapes of invariants.
  3. Horn Clauses provide the formal language for expressing invariant constraints.
  4. SMT Solvers use advanced algorithms to find solutions to these constraints.
  5. Verification is complete when we have a mathematical reason () for why no error can occur.

Self-Check

  1. What three obligations must a loop invariant satisfy for a while loop with guard , precondition , and postcondition ?
  1. What is a template, and what is the solver searching for?
  1. Give the general form of a constrained Horn clause and identify its components.
  1. Write the three Horn clauses generated for a generic loop while B { body }.
  1. Which SMT tools are designed to solve Horn-clause systems, and why does verification use them rather than ordinary SAT solvers?

Back to Program Verification Index | Previous: (y-18) Trace Abstraction and Floyd-Hoare Automata | (y) Return to Notes | (y) Return to Home