# Kernel bugs, and why a second checker helps

## The question

What if the Lean kernel itself has a bug, so that a false statement gets through?

## Why it matters

Every Lean check in the end trusts the kernel. A kernel bug would let a false statement through every check that relies on it.

## What answering it would help with

Knowing what a second, separately written kernel adds lets a reader decide how much checking an important result needs.

## What our research shows

**The answer in one line:** it has happened (a 2026 report, fixed the same day), and a second checker written separately is evidence against such a bug, not a guarantee.

Everything in chapter 3 is something a careful reader can catch with the right check. This chapter is about the case where the check itself is wrong.

### The kernel is a program

The kernel is small, but it is still software, and software has bugs. Lean's reference manual says so itself: its list of assumptions that remain even after its strongest check includes that no implementation bug affects all of the checkers used at the same time.

### A 2026 example

This section is taken from the public sources named in CREDITS.md, which were read for this book. I did not reproduce the bug, and no exploit file is shipped in this book.

- On 28 July 2026 a user of GitHub with the name kiranandcode opened issue 14576 in the Lean repository, titled "Kernel accepts wrong-structure projections, allowing an axiom-free proof of False". The report says the example uses the ordinary, checked path for adding declarations, and does not use sorry, the kernel-skip option or a modified compiled file. It also says the report arose while reviewing a published proof of a famous open conjecture.
- The same day, Leonardo de Moura's pull request 14577, which adds a missing check in the kernel's handling of inductive declarations, was merged, and the issue was closed. Its description says that a nested inductive datatype whose parametric arguments were ill typed could be accepted, because those arguments escaped type checking.
- A post to the oss-security mailing list by Jonathan Brossard on 2 August 2026 describes the bug as a kernel soundness bug, lists the affected versions as all Lean 4 versions up to and including 4.31.0 and nightly builds through 27 July 2026, and says that leanchecker also accepts the 0 = 1 proof it demonstrates. The post says a different forged proof, a disproof of the Collatz conjecture, was accepted by the Lean kernel and by the independent checker nanoda.
- The Lean 4.32.2 release notes (28 July 2026) say that the issue was discovered by Ramana Kumar and reported by Kiran Gopinathan, that "the bug can be exploited even when using comparator", and that nanoda "does not suffer from the same bug" but could be fooled by proof terms that also exploit a separate nanoda bug, since fixed. Leonardo de Moura's postmortem of 1 August 2026 adds that lean4lean is affected by the kernel bug, since its handling of inductives is a port of the reference implementation.
- Using the Lean release notes, the release tags and GitHub's lists of commits, I checked that the fix is in Lean 4.32.2 (released 28 July 2026) and in v4.33.0, v4.34.0, v4.34.1 (the version used in this book) and v4.35.0; v4.32.0 and v4.32.1 do not contain it. That is a statement about the source history, not a test of the bug.

### What this shows

- **A kernel bug is not the same kind of failure as the ones in chapter 3.** There, a reader or a second tool catches a problem the kernel was never asked about. Here the kernel was asked, and answered wrongly.
- **leanchecker could not help**, as its documentation says: it uses the same kernel. The oss-security post reports that leanchecker accepts the 0 = 1 proof, and that a separately written kernel, nanoda, accepted a different forged proof (the Collatz disproof), so a second implementation did not catch that one either. The sources do not say why, and this book does not guess.
- **A second kernel still helps.** Two programs written separately by different people are unlikely to make the same mistake, and when one of them is wrong, a disagreement is a signal worth chasing. This example shows that agreement is evidence, not a guarantee.
- **Version matters.** A result checked with a toolchain from before a fix has a weaker claim than the same result checked after. Keep the toolchain version with the result, and read the release notes.

### What this book does about it

Two re-checks were run on the demonstrations in chapter 3.

- **leanchecker**, which uses the same kernel as the build, on the Lean 4.34.1 builds.
- **nanoda**, a kernel written separately in Rust, version 0.4.19. Lean's own release toolchain for version 4.35.0 contains it, together with leanexport, the program that writes a theorem and everything it depends on out as plain text. Those tools are not in the 4.34.1 toolchain, so the same source files were built with Lean 4.35.0, exported, and given to nanoda. It was set to permit only the three standard axioms. Chapter 3 has the results: it accepted the files whose proofs are valid, refused the two with extra axioms under its axiom rule, and did not accept the file with checking switched off (it stopped with an internal assertion failure).

Two limits. One: the nanoda results are for the Lean 4.35.0 builds of the same files, not for the 4.34.1 builds. The other: **lean4lean**, the other separately written kernel, is also in the 4.35.0 toolchain folder on this PC, but it could not read the compiled files ("incompatible header"), so no lean4lean result is claimed.

Both Lean versions used here contain the fix for the 2026 bug, so none of these runs says anything about that bug.

### Yesterday, today, tomorrow

**Yesterday.** Mario Carneiro wrote lean4lean and ammkrn wrote nanoda partly so that the Lean kernel would not be the only judge of Lean proofs. In July 2026 a kernel bug was reported by kiranandcode and fixed by Leonardo de Moura within hours, and Jonathan Brossard wrote it up for the security community.

**Today.** Sonny notes the Lean version with each result and treats an agreement of two separately written kernels as stronger evidence than one, not as proof. In this book the demonstrations were re-checked with leanchecker and with nanoda, and the book says which Lean version each was run on.

**Tomorrow.** Getting lean4lean to run on these files, and running a separate kernel on every future Lean result that matters, is the next step. If a kernel bug is found later, a result checked with an older toolchain can be re-checked with the fixed one.

## Check it yourself

The nanoda step for the seven demonstrations is the optional second-kernel recipe in [the check guide](../VERIFY.md). The 2026 bug is described from the public sources named in [the credits](../CREDITS.md); it was not reproduced here.

## Where to go next

- How were the demonstrations that these checks were run on built, and what did each check say? See [Five ways to get 2 + 2 = 5 past a build](03-two-plus-two-is-five.md).
- What does a successful check still leave unsaid? See [What "Lean-verified" does not mean](02-what-it-does-not-mean.md).
