Joachim Breitner

Riemann con leche

Published 2026-12-03 in sections English, Lean.

Earlier this November, an AI-written proof of the Riemann Hypothesis was published by Alpöge, written in the language of the Lean theorem prover and when the community rushed to check its validity, it reached for con-leche, a formally verified checker for Lean proofs that I had just created. A few things had to fall into place for this to happen.

This post tells the genesis of con-leche until the day of the Riemann Hypothesis, from my personal perspective. I’m sprinkling a bit of technical detail into the post that may not make sense to everyone, feel free to skip that. In fact, I have the feeling that I am writing this up mostly for my own sake, but feel invited to come along, if you are curious.

Parental “leave”

The story begins with my wife’s pregnancy. We were expecting our first child to arrive in September, and I wanted to make the most of the last summer unconstrained by being a father, and went on a form of early parental leave, mini sabbatical so to say, starting in July. I thought I’d do lots of paragliding and biking and other trips and all of that, and I did do some of that, but it turns out that I am really bad at not working, so I continued to work on Lean. But being on leave, and not having a particular assignment, encouraged me to pursue more experimental ideas.

A hot topic at that time were bugs in the Lean kernel. The Lean theorem prover is built around a small trusted component, the kernel, and all proofs have to be checked by that before they are considered ok. And because trusting one piece of software is risky, we strongly recommend to export the proofs and have them checked by multiple external checkers (e.g. nanoda, lean4lean), the idea being that a bug in one of them would hopefully not be in the other one, and together this forms a rather solid system.

This approach served us well for many years, with very few soundness-relevant bugs found. But two things changed in 2026, with the advent of powerful AI models: They got really good at finding bugs. And with AI-generated writing more and larger Lean proofs, some started to wonder if AI agents might sneakily choose to rather find and exploit such a bug than to go through the effort of writing the actual proof demanded from them.

The latter concern was theoretical – I have not yet seen an AI agent that was not explicitly asked to do so to try to exploit bugs in Lean, only publicity stunts where someone made it look as if the agent was sneaky – but we certainly saw a short spike of bugs found in the Lean kernel and the other Lean checkers (and in other proof assistants, too). So something had to be done.

We need proofs!

We fostered an ecosystem of even more Lean checkers (the “Lean Kernel Arena”, currently with 36 checkers) and improved Lean’s proof logic to make writing a checker easier (the “Kernel Logic Renovation”). The real fix, however, was always clear: We need verified proof checkers. Proof checkers that themselves come with a proof that they only accept good proofs, and will never ever accept a proof of a false statement. Verifying a checker would not only rule out the kind of implementation bugs that we saw; it would also address concerns that Lean’s logic, its particular shade of dependent type theory, had issues.

(Some people were particularly concerned about Lean’s treatment of nested inductives types, although I always thought these concerns to be blown out of proportion: The implementation of that part has some hairy bookkeeping, so that is where implementation bugs may have been more likely. The theory behind it – a reduction to mutual inductives - always seemed plausible to me.)

There is an ongoing, multi-year project to verify a Lean checker, including its theory: lean4lean by Mario Carneiro, and it seemed our best bet to just wait for Mario to finish the work. At that time, however, the metatheory wasn’t done yet (at the time of writing, rumors are that it is done now, but only by AI and thus not yet published), and given the urgency of the issue, I wondered if there was another path to an external checker that, if it says “ok”, really really means the proof is ok.

Not verified, but verifying

Since it seemed we were lacking the theoretical tools yet for a verified checker, I thought maybe I can write a verifying checker. A checker that, for every single step it does, justifies that step within some other, simpler, consistent logical system. It wouldn’t tell us much about the checker as a whole, but for any given proof that the checker accepts, we’d know it’d be fine.

Furthermore, I figured that it would be really useful if that target logic was extensional, that there is only one kind of equality. If I can prove that a = b, then I can replace a with b anywhere. That kind of reasoning is what Lean’s reduction of nested inductives to mutual inductives morally relies on: The (definitional) reduction rules for the nested inductive are justified by (propositional) equalities of its mutually inductive model.

I had no idea if that would fly, but it seemed worth a try, so on July 30th I explained to Claude what I want: A fork of the nanoda Lean checker (written in Rust), with a small in-process LCF-style proof system modelling set theory and a model of all things Lean as sets in that theory (written [e] for a Lean expression e). During every step the checker takes, it would justify it in that system. If it reduces e to e', or determines that e and e' are definitionally equal, it should accompany that with a proof that they have the same meaning as sets ([e] = [e']). If it infers e : t, it should also show that the meaning of e as a set is a member of t as a set ([e] ∈ [t]).

I kept iterating on this for a few weeks, and at the end I could handle a sizeable chunk of mathlib, but it became clear to me that this approach would not be efficient enough for practical use for two reasons:

  1. A lot of extra bookkeeping to construct and pass around the statements on the set theoretic side, with sometimes large encoding, expensive substitution, etc.

  2. Lack of rule inversion, an issue that will haunt this story for a while.

    The problem appears when the checker is about to reduce a beta-redex of the form (fun x => b) a to b[x := a]. It may know at this point that [(fun x => b) a] is a member of some set, but from this semantic fact (i.e. fact about the set interpretation), it is not necessarily clear that [(fun x => b)] really is a function, or that [a] is in the domain of that function. In a normal type-theoretic approach, we can learn that from (fun x => b) a being well-typed by looking at all the possible rules about function application (and maybe hoping we can prove “injectivity of pi-types”), but we don’t have a sound type system to lean on here.

    So the next best thing we can do is, before we do reduction, infer the type of b and a and dynamically check that all is fine. This is extra work that we (presumably) don’t need for correctness, only to be able to build the proofs. Such extra work I call the “certification tax” here.

I eventually abandoned this approach. It was never announced; I just published the code for archival reasons. Nevertheless, it was a crucial step in this story, because of a by-product.

Inductives, be gone!

As mentioned I reached for an extensional target logic because that would allow me to handle nested inductives like the official kernel does: build an equivalent mutual inductive group, and copy over the result of that (in particular the recursor and its reduction rules). Since I needed not just the reduction rules, but also proofs that these rules hold, I extended the construction of the nested inductive to also construct, as normal Lean theorems, proofs that these rules hold as equalities. This construction looked useful on its own, e.g. for anyone else trying to write a verified checker, so I extracted it into its own preprocessing tool lean-inductive-models and announced it on August 17.

I did not stop at modelling just nested inductives that way: Using various constructions, some building on top of each other, this tool can construct any kind of Lean inductive declaration, including proofs of reduction rules and eta rules and projection rules, assuming a fixed set of very basic inductive types (Eq, Quot, PUnit, PSigma' and Nat). At some point the tool also supported level monomorphization; later I removed that feature again.

This tool itself could be used as an additional proof checker, and joined the Kernel Arena for that: If it accepts a proof, then we have good reason to believe that whatever fancy nested inductives are used in that proof, they are not logically concerning. In fact, when Leo collaborated with someone at OpenAI in August to let their latest internal model hunt for remaining implementation bugs in the official kernel, lean-inductive-models was not susceptible to the exploits, as Leo reported. Promising!

Another effect of having lean-inductive-models was that it suddenly made writing a properly verified checker much more realistic. If the main hurdle towards a verified checker are inductive types (whether that’s because of the theory, or just because they are fiddly), and my tool defines them away, then maybe I can write a verified checker after all. It would only support the target fragment, with all inductive types beyond the above five basis types justified by a concrete model, given by the preprocessor and then just checked.

Verified, one way, or another?

With that encouragement, on August 19 I started working on what eventually turned into con-leche, then still under the name setlec (for set-theoretic Lean checker). The idea, as can be seen in the initial prompt, was to do what nanodatg did, but instead of building the proof at run time, we’d prove that such a proof exists for any successful execution of the checker, and then we’d have the verified checker.

Already the same day I had a checker with an end to end proof that it is consistent, i.e. does not accept bad proofs, by virtue of rejecting everything. A good start, but hardly useful, so for the next three weeks I iterated with Claude on the design; that of the checker, but especially that of the proof itself. Already after five days it accepted all of Init, including verified fast Nat operations. A promising start!

The main challenge in this work, I think, is that Lean expressions on their own, without their inferred type, do not have enough information to map them to sets in the most direct way. Consider (fun x : A => b): This Lean expression can denote a function, if b is an element of a data type, or it could denote a proof, if b itself is one. In terms of sets these should look rather different. In order to disambiguate, setlec had to annotate the expressions and put on each binder the sort of its codomain, the sort of the type of b. This annotation pass lived outside the proof and needed to be neither verified nor trusted. Storing the sort here, and not the type, was already rather nice, because sorts aren’t affected by substitution. But it still complicated the implementation and also the main proof: While I could easily state “no proof of theorem : False gets accepted”, I could state the stronger and arguably more interesting “every accepted Lean file has a model” only about the result of checking all declarations, not the input you give to it.

Also, creating and checking the annotation was costly, and it didn’t even remove the certification tax entirely. For a while (August 25 to Sept 1) I tried to do without the annotations, and instead adjusted the set interpretation so that it did not need information about the type of expressions: the interpretation of [(fun x : A => b)] would look at the interpretation of [b] for all x ∈ [A] and if these look like proofs, the whole thing is interpreted as a proof. This kinda worked, but there are corner cases (when [A] is empty) where this does not work well, and the checker would still have to sometimes use infer during beta-reduction to disambiguate, and that was still expensive.

When I returned to the annotation design I at least realized that I don’t need the full codomain level: Since I only need to know whether it can be a proposition or not, it sufficed to store a PropWhen data structure that’s either neverProp or lists the universe parameters that all need to be zero for this to be a proposition. The following week I remember to have explored more and more desperate and doomed directions, and in my weekly log at the Lean FRO I was clearly frustrated (“Feels like mentoring a PhD student who keeps going on wild goose chases … Also, the whole puzzle is hogging my mind more than I would want” – remember that I originally planned to take time and mind off this summer!).

Nevertheless, I kept pushing. On Friday, Sept 4, I wrote “not giving up on setlec”. Then things suddenly started to fall into place.

A week of deliveries

On Sunday morning, only two days later, setlec was finally able to process good chunks of mathlib. At this point I became confident that this will actually work; we will have a verified and practically useful checker for Lean proofs! I was very excited. I told the team about it, and (thankfully) discussed possible better names than setlec with my colleagues. It was briefly called Lech (after the German river) and Leach, but soon con-leche came up and stuck. On Sunday late evening, for the first time, it had processed all of mathlib

setlec: accepted 695202 declarations (--verified)

This was the milestone I wanted to reach before making the tool public. But as it happened, the Anthropic FLT proof had just dropped two days before. This was maybe the first high impact AI generated Lean proof that was too large to check on a normal machine, and it seemed highly desirable to be able to check such proofs with a verified checker, once we have it. So Sebastian Ullrich started to run con-leche on FLT, discovered some performance issues that I then fixed, and most importantly I added parallelism to con-leche in a way that the main theorem still covers it (subtypes are really useful for that). On Thursday, September 10, at 3:30am, I wrote

After a bunch of tweaks, con-leche does FLT in parallel, although far from a match to nanoclo:

accepted 1044222 declarations wall 2 h 22 min task clock 11 h 38 min peak RSS 59.2 GB

If you are wondering why I wrote to the company chat at 3:30am? Because between the first successful mathlib run and the first successful FLT run, my wife delivered our first son (all well and healthy, thanks for asking), so this story is now set in the maternity ward (and me working on the phone only).

In parallel to these performance tweaks, I had Claude try to see if we can actually do without the lean-inductive-models preprocessor, and handle (non-mutual, non-nested) inductive types directly, like all the other checkers, and yes it could. Now that we had the set theoretic model in place, and had the necessary results about core type checking at hand, modelling inductive types directly as sets and proving all the relevant set-membership and equalities turned out to be straightforward. So the tool whose existence encouraged me to approach the whole endeavor was, at the end, not necessary.

Also during these days I sped up reading the input file a lot. I let Claude write a highly optimized parser that scans the input JSON directly, rather than building an intermediate data structure with hash maps of keys and so on. This is something I wouldn’t dare to do in a trusted component like a checker – but here, I could ask Claude to do that only when it can prove it to be equivalent to a naive parser that serves as specification, and with that in place I was happy with whatever highly tuned code it would spit out.

With all this in place, I released announced con-leche publicly on Thursday morning, still from the maternity ward, and then put my child in the baby carrier and walked home.

Sticks and stones

Needless to say, I was proud as a father. Lean’s story about why you can trust its proofs just got so much better! This was a big relief for us at the Lean FRO, and presumably for many of our users who took notice.

That said, reactions weren’t all positive. Beyond reasonable and welcome scepticism I was surprised by how vehemently some people in the wider PL community refused to take this work seriously, spread doubt that it means something for “Lean” and other misinformation, and some even made thinly veiled ad-hominem attacks on “social” media. I was confused at first, but – after reaching out to some of them and hashing it out – eventually understood that it’s not con-leche itself that they are unhappy about, but rather the AI involvement in its creation. If I had written it all by hand there’d be less bile spewed. I may have enlivened that reaction by humbly understating my own contributions to this work relative to Claude’s.

Anyways, I made my peace with that: development with heavy AI support is the new normal. Whether that is good or bad is not this post’s topic. Some people feel strongly about this. I’ll let them have their feeling.

Continuous nurturing

Of course con-leche wasn’t perfect, just because it worked and was verified to be consistent, and over the next few months I continuously improved it.

More drinks, por favor

The verification of con-leche only covers its source code, so it cannot rule out issues due to Lean compiler and runtime. To address them, I created a port of it to Rust (con-ron) and later also X86 assembly (con-agua), all with proofs that relate them back to con-leche’s algorithm and its consistency proof. Checking your proof with all of them gives very strong confidence now, even without the Lean runtime itself verified, by the now familiar argument that a bad proof would have to exploit independent bugs in the Lean runtime, in the Rust compiler (or the Aeneas Rust verification tool) and in the way I run the verified X86 code (or the Kraken semantics).

This in particular protects against a bad proof exploiting possible bugs in Lean’s bignum library (GMP at the time of writing), as both con-ron and con-agua use their own bignum implementation that is covered by the verification.

Inductives, be gone no more!

Eventually I figured out how I can handle all kinds of inductive types directly and uniformly in con-leche. Mutual and nested inductives are accepted as they are, without preprocessing or reduction to something else. The last remnants of lean-inductive-models disappeared from the project, and the set-theoretic interpretation of any data type is now simply the least fixed point of the equation described by its declaration, with constructors understood as sums of products.

No more annotations

In October, a huge improvement landed when I could drop the annotation phase from con-leche.

Recall that one big hurdle is how to interpret (fun x : A => b) as a set when we don’t know if it describes a proof or a function. I went back to the design where the interpretation is purely syntax directed, and interprets [(fun x : A => b)] as a proof whenever it looks like a proof, which then necessarily includes non-proof functions with empty domains. Unlike in August, now the proof went through, if done correctly: the set interpretation of a proof (called “the point”) has to be distinct from the empty set and the denotation of a Lean type must be either the singleton set containing the point or not contain the point. Then we can prove the crucial theorems, e.g. preservation of reduction, in a slightly weaker form where we assume the input does not “look like a proof”. That assumption is ok because of proof irrelevance. And in the end the proof closes with a very small amount of “certification tax” remaining in the defeq congruence check for lambdas. In particular beta reduction was ok without additional checks.

If the previous paragraph was actually intelligible to you then you may be interested in “The Proof Idea of con-leche”, an (AI-written) exposition of the con-leche consistency proof.

This was huge for me because it allowed me to explain to a curious mathematician with a few simple rules on a blackboard how they can, should they so be inclined, think of Lean expressions, types and proofs simply as familiar set theoretic constructs. To some audiences this may be more accessible than explaining type theory as a basis for math on its own.

This refactoring also unblocked the following further improvements, which will play a role in the Riemann Hypothesis proof checking.

Simpler main theorems

As mentioned above, previously I could state “every accepted Lean file has a model” only about the annotated result of checking the declarations. With the annotations gone, it became possible to state that about the input, which made a much nicer main theorem:

theorem main_json_model (V : Type w) [SetTheory V] {file : String} {fs : FS} {b : ByteArray}
    (h : ModelIO.CanGive (Driver.runArgs ["--", file]) fs 0) (hb : fs.file file = some b) :
    ∃ r, parseChunks [b] = .ok r ∧ ∃ model, IsModel V model (· ∈ constantsOf r.decls.toList)

By this time, I was also able to cover the checker’s driver – reading input files, parsing command line arguments – in the verification, so the theorem is now not only about an internal function (it used to be about checkDecls), but essentially about the whole program (Driver.runArgs)

Modular checking

So far, an external Lean checker would see one file with all the definitions and theorems and proofs. This is clearly a scalability issue: As libraries like TauCeti grow by millions of lines every week or so, checking “all of TauCeti” is better done piecemeal. Lean already has a notion of modules (individual Lean files), and has a module system that allows compiling a .lean file without having to see everything about its imported files. In particular, a proof in a dependency is irrelevant here, we only need the theorem statements.

We had discussed external modular checking, and the theory behind it, on and off. But now with con-leche working and no longer needing these annotations, it was possible to build out the theory: Which checks exactly would con-leche have to do for each module (in addition to the normal checks it had to check that the public view of its declarations, as seen by importing modules, is consistent with what the module itself built, and that the things it imports are not conflicting), what does it have to check at a global view (module imports are acyclic), and how to put that all in one main consistency theorem of modular checking.

Interestingly, the intuitive phrasing of the main theorem here – there exists one global model, valid for each module – does not work, because Lean’s module system allows the same name with different meanings in disjoint areas of the module graph. Therefore the main theorem of modular checking says “every module has a model, and when two modules see the same name, the models agree”.

Together with modular checking came the ability for con-leche to read Lean’s compiled .olean files (which are really just its run-time data structures dumped to disk, ready to be mmap-ed on the next run) directly, avoiding lean4export and the textual proof export file.

The modular checking work was finished on Friday, November 20th, the day of the Riemann Hypothesis proof drop.

A second comparator

While working on modular checking it became clear that the checks done there – is the public view on a module consistent with what the module itself does – are very very similar to what comparator checks.

The comparator tool by Henrik Böving was originally a separate tool and is nowadays shipped with Lean as lake comparator. It is the officially blessed tool to validate a Lean proof to the highest standards. In a nutshell it performs three tasks:

  1. It compiles the proof (the “solution”) in a sandbox and exports it. Otherwise malicious proof code could take over your machine and post “The proof is good” on your behalf on Twitter.

  2. It checks the exported proof, outside that sandbox, using multiple checkers (leanchecker, nanoda, lean4lean and con-leche and con-ron).

  3. It compares (hence the name) the theorem proven by the solution against a trusted formulation of the statement; the “challenge”.

    Because Lean is so extensible, if you write import SomeFile and later theorem : 1 + 1 = 2, then the Lean code in the imported SomeFile.lean may affect what that theorem statement actually says. Therefore you have to have a trusted specification of the statement of interest, with only trustworthy files imported.

    This check is the one that looks like the modular checking check in disguise.

So far, comparator was the only tool capable of performing step 3. It wasn’t a lot of code, but it was unverified. Also, I was wondering, what does this check even mean, formally?

As the modular checking was shaping up, I also worked on con-leche --compare; a mode where con-leche not only checked the solution and the challenge, but performed a similar comparison. (It takes exported proofs, so the sandboxing of step 1 remains the user’s task.) After a few iterations, it was working and I had a proof of the correctness of the comparison. I was actually surprised by the shape of the final theorem statement:

theorem main_compare_json_model (V : Type w) [SetTheory V] {c s : String} {fs : FS}
    (h : ModelIO.CanGive (Driver.runArgs ["--compare", "--", c, s]) fs 0) :
    ∃ bC rC, fs.file c = some bC ∧ parseChunks [bC] = .ok rC ∧
      ∃ model, IsModel V model (· ∈ constantsOf rC.decls.toList)

The solution only shows up in the assumption h, stating that the con-leche --compare challenge.ndjson solution.ndjson run finished successfully. It is not mentioned in the conclusion at all. In fact, the conclusion looks basically just like in the theorem main_json_model above.

But it makes perfect sense; the point of running comparator is to guarantee that the statements in the challenge are true. It does not matter how it comes to that conclusion, and whether it had to peek at the solution for that.

Riemann drops

On Friday, Nov 20th, this was all still fresh out of the oven, and I hadn’t landed it on con-leche’s master branch yet, only pushed it to a feature branch. That was hours before I heard about Alpöge’s proof of the Riemann Hypothesis, and before on the Lean community Zulip people scrambled to build and check the proof to see if it held up. Because of the size of the initial proof, with 17 million lines of Lean, this wasn’t something to just do on your laptop, and so I didn’t attempt it myself, but rather watched anxiously as others reported on their success.

Especially Andrew Sutherland’s verification was well noted, because he was swift and shared his results nicely. Even before lake comparator --paranoid finished (which was expected to take a long time because leanchecker isn’t parallelized), he announced that the proof passes nanoda and – much to my relief – con-leche.

I was never worried that the proof was wrong – I have not yet seen evidence that AI agents are so misaligned that they would cheat using bugs in the kernel, even if they knew about them, unless they are explicitly asked to do so – but I was worried whether con-leche will be able to handle the proof. It would be very unfortunate if it fell over for some small reason and we’d have to explain to the world why this doesn’t mean that the proof is bad or that Lean is not useful here. But it held up, and in the early proof checking runs done by Szymon Teżewski, it was even the fastest, checking the whole proof in under four minutes on 64 threads. This also attests to the quality of Lean as a parallel programming language.

Both Andrew and Szymon ran con-leche also from the branch with the con-leche --compare feature, and it confirmed that Alpöge’s proof really was a proof of the Riemann Hypothesis, as it had already been defined in mathlib. This turned out to be crucial for swift confirmation, as the lake comparator run was still running. It had passed the comparison check and said so on its output, but because it was still running leanchecker (which is not parallelized), it had not “officially finished” for several days.

The next day, people from the Mathlib Initiative and I wrote a press release where we explain how the Lean community thoroughly checked the Riemann Hypothesis proof and that we consider it correct.

So in the end, a tool that I started working on rather optimistically, with many detours, including a feature that I added literally the day of the proof release, ended up giving the mathematical community confidence in an enormous and high-impact proof at unprecedented speed and unprecedented reliability. That makes me happy.

I wrote this post by hand. AI helped with fact checking, typo fixing and adding some links.

Comments

Have something to say? You can post a comment by sending an e-Mail to me at <mail@joachim-breitner.de>, and I will include it here.