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:
- Initial Entry:
- Inductivity:
- 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:
- Entry:
- Inductivity:
- 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)
| Technique | Goal | Effort | Best For |
|---|---|---|---|
| BMC | Find Bugs | Low | Rapid debugging |
| CEGAR | Proof/Bug | High | Unknown predicates |
| Trace Abstraction | Proof/Bug | High | Large CFGs |
| Synthesis | Find Invariants | High | Mathematical/Numerical loops |
Summary
- Invariant Synthesis automates the most difficult task in program verification.
- Templates restrict the search space to specific shapes of invariants.
- Horn Clauses provide the formal language for expressing invariant constraints.
- SMT Solvers use advanced algorithms to find solutions to these constraints.
- Verification is complete when we have a mathematical reason () for why no error can occur.
Self-Check
- What three obligations must a loop invariant satisfy for a while loop with guard , precondition , and postcondition ?
Answer
Initial entry: . Inductivity: (where is in the post-iteration variables). Safety exit: . The three conditions are exactly what the Hoare while rule needs.
- What is a template, and what is the solver searching for?
Answer
A template is a parameterized invariant shape such as or , with the parameters left symbolic. The solver searches for concrete numeric values of those parameters that make all three loop obligations valid. The template restricts the search space to a tractable family.
- Give the general form of a constrained Horn clause and identify its components.
Answer
, where is a pure theory formula and each is an uninterpreted predicate standing in for an unknown invariant. The body is a conjunction of known constraints plus predicate atoms, and the head is one predicate atom.
- Write the three Horn clauses generated for a generic loop
while B { body }.
Answer
Entry: . Inductivity: . Safety: . A CHC solver finds an interpretation of that satisfies all three.
- Which SMT tools are designed to solve Horn-clause systems, and why does verification use them rather than ordinary SAT solvers?
Answer
Tools such as Spacer (part of Z3) and Eldarica are CHC solvers. Ordinary SAT or SMT solvers check satisfiability of a fixed formula, but CHC solvers search over interpretations of uninterpreted predicates that satisfy a recursive set of implications, which is exactly the shape produced by program-verification conditions over loops and procedure calls.
Back to Program Verification Index | Previous: (y-18) Trace Abstraction and Floyd-Hoare Automata | (y) Return to Notes | (y) Return to Home