Formal Software Verification

Verified Software,
Built Directly in Lean

Many attempts at formal software verification try to graft mathematical proofs onto existing programming languages. Trying to wrap messy, legacy code in contracts usually costs more time than it saves.

We take a simpler, more direct approach: we build in Lean from the start.

Lean gives us an environment where we can write real software and prove its correctness in the same place. By adopting Lean as our core formal method in software engineering, we remove the need for disjointed toolchains, complex contract layers, or guesswork about how code will run.

Our Formal Verification Stack

Our compilation pipeline follows a simple rule: optimise the implementation with respect to the specification, and mathematically prove that the compiled code still meets it.

A JSON parser

One worked example of a JSON scanner. We specify it in Lean, compile ordinary C, and prove the compiled program still follows that specification.

Select a step, or step through the parser. Arrow keys move between steps.

01 Lean defines the rule An executable specification, proved correct from the start.
02 The rule is written in C A clean, predictable subset that Lean can model.
03 Clang compiles and vectorises Automatic SIMD optimisation at -O2 -mavx2.
04 The IR is normalised Standardising compiler instructions for formal analysis.
05 Lean verifies the machine code End-to-end formal software verification.

01

Lean defines the rule

Using Lean as a formal method in software engineering, we define the scanner’s state machine as an executable specification. Core correctness and safety properties are proved mathematically against the reference before writing any low-level code.

If the proof holds

Every behaviour of the compiled program is one the Lean specification allows.

If a compiler update, flag tweak, or code change alters the program’s behaviour, the build breaks immediately instead of silently introducing a bug.

From Specification to Correct, Secure and Fast Machine Code

  • Formal specification

    We define the core logic and state transitions directly in Lean, proving all baseline functional and safety properties before generating low-level code.

  • Candidate implementation

    We write a candidate implementation in a transparent, predictable subset of C that Lean's formal semantics can model directly without ambiguity.

  • Compiler optimisation

    Clang compiles the C code down to LLVM IR, automatically introducing SIMD vectorisation and instruction-level optimisations without needing handwritten assembly.

  • Proven refinement

    A conditional refinement proof in Lean inspects the normalised LLVM IR to verify that every emitted instruction matches the original specification. If a compiler flag, pragma, or line of code alters program behaviour, the build fails instead of drifting silently.

High Performance Without the Risk

In industry, formal methods have often had a reputation for being slow, academic, or detached from practical deployment.

Our pipeline focuses on fast, reliable execution. The speed comes from the compiler, for example Clang at -O2 -mavx2 vectorising a hot loop, and the proof is checked against that IR. The result is fast, reliable software, backed by formal verification that the optimised code still meets the specification.

Prove the optimised code still meets the specification.

Formal software verification in Lean: we compile through C to LLVM IR, and prove the result.