Vericoding: Getting it Right! Methods of Applying Formal Verification in the AI Era

Vericoding: Getting it Right! Methods of Applying Formal Verification in the AI Era

There has been an explosion in the use of formal methods for AI-driven software. This is something we have been predicting for a while — ever since we noticed the collapse in the cost of proof, and because of the advantages that formal verification can bring to software development. It can bring real assurance about properties from our designs to the point of mathematical certainty, rather than simply educated guesses.

But now that it is much easier to apply formal methods, which methods should we be applying? When? And how? We need to choose carefully, based on what assurances we are seeking and how hard it is to get them through a given path.

Three paths to formal correctness

There are many formal methodologies, but we can divide them into three approximate categories: modelling, implementation verification, and correctness by construction. These are only approximations. There is overlap, and a lot of cross-pollination, but they provide a useful taxonomy.

Modelling seeks to produce a simplified formalisation of what the code intends to do. This can make very complex problems tractable by removing some of the unnecessary complexity which might get in the way of understanding the solution. The key here is abstraction. Tools used for this approach include SMT solvers and TLA+.

Implementation verification creates a complete model of the semantics of the language in which you are actually writing the software. This allows you to use a theorem prover to prove properties about an implementation. The framework for this verification may introduce additional abstractions that help in reasoning about semantics. This is the approach of tools like Iris and VeLLVM.

Correctness by construction seeks to build the specification into the software design process. There are multiple ways to do this, but they all essentially require that the semantics is tightly connected to a theorem prover. Currently, the most popular tools in this genre use dependent types: a type discipline which can depend on terms themselves, and which is rich enough that it can, in some sense, describe all of mathematics. Rocq, Agda, and Lean fall into this category. There are other approaches, however, such as the B-method, Isabelle, and others.

ApproachCentral questionStarting point
ModellingDoes this design satisfy the properties we need?An abstraction of the system
Implementation verificationDoes this code satisfy its specification?Code and properties to check
Correctness by constructionCan we preserve the specification as we build?A specification and justified construction steps

And of course we can mix and match approaches. There are, for instance, specifications which utilise all three approaches in Lean. The list below details nine ways of applying formal methods across the three paths.

Modelling

When we model software, we try to make a simulacrum of the code, or of a part of the code which is of interest. That is, we formally specify what the software should be like. The advantage of this approach is that it can be much easier to apply to existing software than other approaches, and it can be extremely useful in finding bugs that are extremely hard to find, while not requiring enormous formalisation efforts. It can, however, have the downside that the map is not the territory. We have to be careful about the fidelity of the model to the object under consideration.

1. Exploring states and transitions

Concurrent systems are very difficult to reason about for humans and LLMs alike. If you have more than a few clients and a few different intermediate states, the number of possible combinations grows very rapidly, making it impossible to think through every possible combination, even for a very small number of clients. The problem comes in a range of forms: races, lost updates, atomicity, deadlock, livelock, starvation, and so on.

If we describe a system in terms of a collection of states and the actions that allow us to move between them, we can deploy model checking to find where these problems might arise. This will give us violations as an actual example trace — the precise actions and states which are required to yield the violation.

Useful for: concurrent protocols, workflows, and interactions whose possible orderings are difficult to reason about informally.

Example: TLA+ with the TLC model checker. A successful exhaustive check covers the configured model; connecting that result to the implementation remains a separate obligation.

2. Satisfiability

It is often possible to describe a problem as a system of logical constraints. This could be anything from data-shape modelling, capabilities and access rules, or combinations of arithmetic rules or business rules.

For example, we might want to know if a given JSON schema description would still admit all the examples which used to work after we have modified it to add additional examples. This is known as subsumption and can be expressed in such a system of logical constraints. Many data-shape problems where we want to retain backward compatibility can be expressed this way.

Some programming languages, such as F* and Boogie, use satisfiability theories to encode their elaborate type systems. This allows the intrinsic approach described above to be realised with the tools from modelling.

SAT (satisfiability) and SMT (satisfiability modulo theories) are frameworks for checking that properties are satisfied. Similarly to the TLA+ approach, they can yield extreme counterexamples when properties do not hold. In the case of our JSON example, this might actually yield a JSON document that is rejected. The Online Z3 Guide is a very useful place to start.

Useful for: access rules, configuration constraints, arithmetic conditions, and finding combinations that violate a requirement.

Examples: SMT solvers such as Z3. The same machinery can also support implementation verification.

Implementation verification: reasoning about the code

This class of tools and techniques helps us to reason not about a model but about the code itself. This might mean exploring execution paths, creating approximations of the behaviour of our software (ruling out classes of errors), or generating mathematical obligations which must hold if our code is to make sense.

Ordinary execution runs a program on particular inputs. Symbolic execution runs it using values that stand for many possible inputs.

For example, a function might branch on whether balance >= amount. A symbolic executor records the condition needed to take each branch and uses a solver to find inputs that reach an error or violate a contract.

CrossHair applies this idea to Python, executing functions with symbolic arguments and using Z3 to reason about their values. This makes it possible to search for counterexamples to preconditions and postconditions without writing every test input ourselves.

Useful for: discovering edge cases in existing code, especially where the desired behaviour can be expressed as a contract.

The limitation: the search may not finish exploring the relevant paths. “No counterexample found” must be interpreted in light of the tool’s coverage and reported result.

4. Bounded model checking: searching whole executions

Another approach translates executions of a program into a logical formula. We then ask whether any execution within specified bounds violates an assertion.

The bounds might limit loop iterations or input sizes. Within that scope, the checker can reason about combinations of values and branches that would be difficult to cover with handwritten tests.

CBMC uses this approach for C and C++, including checks for memory safety and user-specified assertions.

Useful for: small critical components, bounded algorithms, and low-level code.

The limitation: a result within a bound becomes a general result only when we also justify that the bound covers the executions that matter.

5. Abstract interpretation: computing with sets of possibilities

Instead of executing a program with individual values, we execute an approximation of it using descriptions of possible values.

For example, if x lies between 0 and 10, then x + 1 lies between 1 and 11. More sophisticated abstractions can retain relationships between variables or information about memory.

A sound analysis overapproximates the possible behaviours. If that approximation excludes an error, the analysis can establish its absence under the stated assumptions. If the approximation includes an error, further investigation may show that it was a false alarm introduced by the approximation.

Useful for: proving the absence of particular error classes across substantial amounts of existing code.

Example: Frama-C’s Eva analysis uses abstract interpretation to analyse possible values and runtime errors in C programs.

6. Deductive verification: turning contracts into proof obligations

We state what must be true before a function runs and what it must establish afterwards. The verifier uses the code to generate the obligations needed to connect the two.

Loops usually need invariants: properties that hold initially and remain true after each iteration. Function calls can be handled through their contracts, allowing us to reason about larger programs in pieces.

Useful for: establishing functional properties such as “this function returns a sorted permutation of its input”, rather than only ruling out crashes.

Example: Frama-C/WP proves contracts on C code by generating obligations using weakest-precondition reasoning. Automated solvers or proof assistants discharge those obligations.

7. Resource reasoning: who may access what?

For mutable and concurrent software, values alone are often insufficient. We also need to reason about ownership, permissions, and interference.

Separation logic supports reasoning about distinct portions of memory and the resources required by an operation. Concurrent forms let us describe how threads share resources while preserving invariants.

Useful for: mutable data structures, shared memory, synchronization, and concurrent libraries.

Example: Iris is a framework for concurrent separation logics, mechanised in Rocq. It provides foundations for constructing and applying program logics, rather than a single automatic bug-search procedure.

Correctness by construction: carrying the specification into development

These approaches make correctness obligations part of building the program. The specification constrains the available constructions, or each development step comes with evidence that it preserves the required properties.

8. Encoding properties in types

We can give values types that express properties of their contents. A vector’s type can include its length, for example, so an operation requiring two equally sized vectors can express that requirement directly.

The programmer then supplies a term that satisfies the type, sometimes together with explicit proofs. Dependent types make this approach particularly expressive; Lean’s indexed families provide a concrete example.

Useful for: interfaces where important constraints should accompany values throughout the program.

Examples: Lean, Rocq, and Agda. The assurance concerns the properties actually encoded: an ordinary function written in one of these languages does not automatically satisfy every intended requirement.

9. Stepwise refinement

We begin with an abstract specification and gradually introduce implementation details. Each refinement produces obligations showing that the more concrete design preserves the required relationship to the earlier one.

For example, we might begin with an abstract collection of reservations, then introduce a concrete representation and prove that its operations implement the abstract operations correctly.

Useful for: developing systems where we want a documented, checked connection between requirements and implementation.

Example: refinement is central to the B-method, which supports a progression from abstract models towards implementable designs with associated proof obligations. Atelier B is one system that supports that progression.

More from the blog

View all posts →
AI-Guided Certified Program Refinement

AI-Guided Certified Program Refinement

Software's core problem is knowing what it should do. AI-guided certified program refinement — vericoding — makes specification the artefact we tinker with, and lets AI guess program transformations that a theorem prover certifies.

Vericoding Services

Prove the program correct. Then make it faster.

Models now write more code than you can review line by line. You specify what the program must do. We prove the implementation meets that specification, and where latency or compute cost is the problem, we replace it with a faster program that still does.

See the services
Code checked by a proof, then measured for speed