Speaker Notes

Your Code Has Bugs. Lean4 Has Proofs: Formal Verification for Engineers — Varun Pant, AWS

Formal verification provides mathematical proof that code matches its specification, and combining it with AI coding agents enables spec-driven development at scale.

AI Engineer · 10:07 · YouTube ↗

Talk · solo speaker  Intermediate · concepts and strategy

Highlights

3 clips · 3 min of 10 min
    • Humans own the specification while machines generate code and proofs
    • Specifications act as living artifacts upstream from implementation
    • Formal verification tools mathematically prove code matches its spec for all inputs
    • Lean uses tactics as moves to navigate a tree toward proving a theorem
    • Interactive proof assistants allow backtracking when a tactical branch fails
    • A small trusted kernel independently verifies the final proof
    • Strata translates high-level intermediate representations from any language to a core IR
    • A unified IR allows dispatching programs to Lean proof engines or SMT solvers
    • Open-source tools bridge diverse programming languages to formal verification pipelines

Questions this video answers

9 · every answer cites the moment it was said
01 Why aren't traditional testing and LLM judges enough for modern AI-generated code? 2 sources · 0:24

Traditional tests only check a subset of inputs and human code review cannot keep up with high agent speeds. Additionally, using an LM as a judge for code is probabilistic and cannot guarantee correctness for every single input.

02 How does formal verification differ from probabilistic testing? 2 sources · 0:51

Formal verification provides a mathematical proof that your code satisfies its specification for every possible input. Probabilistic testing or LLM judging only checks some inputs and cannot guarantee absolute correctness.

03 What is spec-driven development and how do AI coding agents fit into it? 2 sources · 1:19

In spec-driven development, humans write and validate the specification upstream, while AI coding agents implement the code from it. The formal verification tool then proves that the implementation matches the validated specification.

04 How does the Lean proof assistant work using the chess analogy? 2 sources · 3:27

Lean uses tactics as moves on a chessboard to prove a theorem goal by traversing a tree of possibilities. If a path fails, you backtrack and try another branch until a kernel independently confirms the final proof.

05 How was zlib formally verified using Lean? 2 sources · 4:41

An open-source project converted the zlib C compression library into Lean code. The AI generated a formal spec, wrote the code in Lean, decomposed the problem into helper lemma subgoals, and proved the theorem.

06 How does AWS use Lean for Cedar authorization policies? 2 sources · 6:15

AWS writes the functional specification of Cedar in Lean while the production code runs in Rust. They use differential random testing nightly to ensure both give the exact same output for the same inputs.

07 What is an SMT solver and how does it compare to an interactive proof assistant? 1 source · 7:17

An SMT solver is a powerful automated calculator where you feed in a formula and it returns whether it is satisfiable or unsatisfiable. Unlike an interactive proof assistant like Lean which functions like a chessboard with tactics, a solver computes the result automatically.

08 How does Verus use pre and post conditions in Rust code? 2 sources · 7:35

Verus allows developers to add requirements and specifications directly into Rust code using pre and post condition keywords. These static checks are enforced by the verifier and then erased at runtime like ghost code.

09 What is Strata and how does it support multiple programming languages? 2 sources · 8:32

Strata is an open-source tool being developed by AWS that lets you create custom compiler-like dialects for any programming language. It lowers high-level code into a low-level intermediate representation called Strata core so it can be dispatched to verification engines.

Section-by-section summary

2 parts

Mathematical Proofs Replace Probabilistic Testing

Traditional testing and human reviews cannot guarantee correctness across all possible inputs, but formal verification provides absolute mathematical proof. Using a specification-driven approach, developers define correct behavior upstream, and AI agents generate code that formal verification tools validate. Lean 4 acts as both a programming language and a proof assistant, leveraging interactive tactics and a small trusted kernel to verify theorems.

Applying Formal Verification to Production Code

Real-world projects demonstrate how formal verification can be applied to production languages like C and Rust using Lean specifications and differential testing. Tools like Verus and Eneus enable deductive verification using SMT solvers and pre- and post-condition annotations. Emerging frameworks like Strata aim to generalize this by lowering any programming language into a unified intermediate representation for automated verification.

0:00 / 10:07
k play/pause · f fullscreen · m mute
n next · p previous clip · t highlights/full
< > slower/faster · / search what was said
  • Formal verification3× · first 0:42

    Mathematical proof that code satisfies its specification for all inputs.

  • Lean12× · first 1:25

    A programming language and interactive proof assistant used for definitions and proofs.

  • Tactics3× · first 3:06

    Moves used in an interactive proof assistant to traverse a tree and prove a goal.

  • Cedar1× · first 6:06

    An open-source authorization policy language used by AWS.

  • Solvers3× · first 7:03

    Powerful automated calculators that take formulas and return satisfiable or unsatisfiable.

  • Verus1× · first 7:30

    An open-source tool that uses the Z3 solver for static verification of Rust code.

  • Strata2× · first 8:34

    An open-source tool allowing any programming language to be lowered into a core representation for verification.