Proving our own standard library

Tests check the inputs somebody thought of. vary prove is supposed to check all of them.

That is a big claim, so we tested it on the one codebase where we couldn't hide the results: our own. We ran it over every module of the standard library and five example projects, with the bundled solver and three seconds per obligation, and expected a victory lap.

It crashed on three files. It refused to look at most of the functions it did open. A lot of the "bugs" it reported weren't bugs.

The good news was real, and small

In the first hour it found three genuine problems. lcm(0, 0) divided by zero, because gcd(0, 0) is zero. A discount function in the shop example broke both of its promises when a coupon had a negative percentage or one above a hundred. A set of request wrappers called a function in a way its own precondition forbids.

All of that code had tests. None of them reached those inputs, because nobody tries a negative coupon until a customer does. That's the argument for a prover, and it held up.

The rest of the hour was less flattering. About 80 percent of the real functions came back "unsupported", which is the prover's polite way of giving up. One string method, one JSON value or one call into the runtime anywhere in a function, and the whole function was off the table. Real functions are mostly plain integers, strings and lists with one awkward call in the middle, so that rule threw away nearly everything.

What we changed

The biggest change was letting the prover continue after a call it cannot inspect. It treats the return value as unknown, accounts for state the call might have changed, and checks the rest of the function. The report names those calls so readers can see what each proof assumes.

We also cut down on false alarms. The prover can infer missing clauses for field changes and loop bounds, then check and label those clauses for review. When it finds a counterexample, it tries the inputs on the real runtime. If the failure does not reproduce, the result is "unknown" rather than "refuted".

We record the results in the repository and use CI to catch regressions. The table shows how much more of the library the prover can now check.

MeasureFirst runSecond roundNow
Functions seen894953954
Functions unsupported716159
Files where the prover crashed300
Obligations proven95740965200
Obligations unsupportednot counted1207126
Obligations refuted5200

The initial refutations included three real bugs. The others came from missing invariants or promises in the examples that needed correction.

What it does today

It's not a toy. The list of things it checks on ordinary code is long, and every item below runs from one command.

AreaWhat it checks
CrashesDivision by zero, a missing dict key, !! on None, an index out of range, unwrap on an error, a failing assert
OverflowInteger math that would wrap a 64-bit Int, which is how abs_diff breaks on huge values
LoopsLoop invariants and termination, with the end of a counting loop worked out for you
DataLists, dicts, strings, sets, data types, enums with payloads, Result and optionals
ClassesClass invariants, which fields a method may change, aliasing, and interface contracts
HelpersLemmas, ghost variables and forall and exists, all erased from the compiled program
BugsA failing input printed as Vary values, replayed on the real runtime, with a test block that reproduces it
SpeedResults cached per function, so editing one function re-proves only it and what depends on it
EditorProves in the background on save, and shows a real failure as an error with an example input
ProductionProven run-time checks can be removed from the compiled program, if you opt in
Mutation testingA mutant the prover shows breaks a contract is killed without running a single test
Escape hatchA goal the solver can't settle can be exported to Lean, and the checked proof imported back

What it still can't do

Some functions remain out of reach. The prover often returns "unknown" for a loop whose invariant is too weak to finish the proof. It reports "unsupported" for some class and value shapes, including lists returned by getters and results with a class as the error type. Class aliasing is modelled, but classes account for many of the remaining gaps.

Concurrency has a narrower guarantee: spawn and task_group are checked one task at a time against their contracts and field writes. The prover catches tasks that may write the same field, but does not explore every possible schedule. It cannot reason about what happens inside channels.

It also takes builtins and AI calls on trust and names them in the report. A proof does not verify the compiler or JVM it runs on. The bundled solver handles products of bounded values; harder algebra and floats go to Z3 by default. Without Z3, float goals are unsupported.

Finally, this is still a new prover. We have tested it on small programs and converted benchmarks, but it has no outside production record. Dafny and SPARK have much longer track records and cover more of their languages.

So why bother?

We aren't trying to out-prove Lean or replace tests. The goal is smaller and more useful: put a contract on the function that handles money, run one command, and get either a proof or the exact input that breaks it. When the prover can't tell, it says so. It has never been allowed to say "proven" when it means "probably".

The same work also turned up a code generation bug. While checking the float model against the runtime, we found that comparing a NaN with < returned true.

Try it yourself

Start with one function you care about. Give it a contract, then prove the folder it lives in:

vary prove src/

Each obligation comes back proven, refuted with a failing input, or unknown with a reason. For the proofs that matter, run it again with --json and read the assumes list: it names every call the proof took on trust.

When the prover suggests a clause it inferred, such as which fields a method changes or why a loop ends, take it into the source:

vary check src/ --fix

If a call into code the prover cannot see blocks a proof, give that function an out clause, or mark it pure if it changes nothing. Floats and multiplication of two variables are handed to Z3, which ships with Vary. To send every goal to Z3:

vary prove src/ --solver z3

Once a proof passes, keep it passing. Write a baseline and check against it in CI, which fails if anything that was proven stops being proven:

vary prove src/ --write-baseline proofs.json
vary prove src/ --baseline proofs.json