The gap between formal equivalence in the traditional sense and true behavior is important to keep in mind as formal verification scales.
Typically equivalence of functions concerns its inputs and outputs. But this leaves out a lot; real machine code also has to keep the processor's security protections, survive a signal arriving at any instruction, and, for crypto, not leak secrets through timing.
We ended up proving some of these and checking the rest, and being explicit about the limitations. The Arm64 model we built on didn't include return-address signing, so we added it and tested it against real hardware. Next we want to move more of what we check into the proof itself.
As formal verification becomes mainstream, it's important to think extremely carefully about what our spec actually covers.
Optimizing beyond the compiler: using LLMs for provably correct speedups.
A compiler lowers your program to optimized assembly while preserving its semantics. Its optimizations are guided by deterministic heuristics that must be safe for every program, so they can't take advantage of the specifics of yours or the exact chip it runs on.
An LLM can write tailored assembly for a program's hot paths, specific to that code and chip. But it's a stochastic compiler, with no guarantee it preserves semantics. Any rewrite might quietly change what the program does.
We model the semantics of machine code in Lean, and make the LLM prove each rewrite equivalent to the original binary. Across the programs we tested, that gave a 33% average speedup over the fastest compiler builds.
Compiler optimizations need to be correct for every program. An agent's only need to be correct for one, enabling idiosyncratic optimizations.
We built a system that lets agents generate optimized, provably equivalent machine code. unzip, ICU, libsignal: 1.33× faster on average.
Post linked below
Working on Lanes: a framework for building fast, provably correct software in Lean
It’s very early (v0.0.2, a preview), but the aim is:
1. An actor framework and runtime that makes concurrent systems easier to prove, while being competitive in performance with Go
2. A model checker that runs on the application’s real code
3. A useful extended standard library, bringing much of Go’s standard library to Lean, differentially tested against it
4. Models of the stores and services apps talk to (Postgres, SQLite, S3, Stripe, etc), checked against real or reference implementations
Programs follow “functional core, imperative shell”: all core logic is pure, deterministic steps, and the runtime performs all IO and side-effects, which makes the logic easy to test, simulate and prove.
Agents can check their work with, from cheapest to strongest:
- Type checking
- Testing
- Model checking
- Deterministic simulation
- Full proofs
Now that agents write most code (with less of it being human reviewed), how far an agent can verify its own work is the bottleneck.
Formal methods are very powerful, but map poorly onto how software has historically been written.
If programming eventually converges to “whatever is most legible to agents”, we’ll probably end up using dependently typed functional languages like Lean. The infrastructure just needs to be built.
Still in an early state, lots to polish. Will post updates on progress, and a full write-up once it's in a more usable shape.
https://t.co/CRq0jmkVyq