# Check it yourself: what "Lean-verified" covers

This guide is a written recipe for each of the seven demonstrations: the command to run, the answer you should see, and which standard public tool gives it. It needs Lean, its build tool and its replay tool, and nothing else. It uses no program of ours, just Lean and its own tools. Each recipe also comes as a [step-by-step page](https://gocheckyourself.org/data/recipes/lean-verified-REPLICATE.md) with commands for Windows, macOS and Linux and the exact output to expect.

## What is claimed

The question these claims answer: which checks accept each of seven small Lean files, and which catches what is wrong in each?

Seven small Lean files were built, re-checked and (for the Lean 4.35.0 builds) given to a separately written kernel. The results are:

| Demo | Build | Axiom report | leanchecker and its fresh mode | nanoda (Lean 4.35.0 build) |
| --- | --- | --- | --- | --- |
| Honest file | passes | none | accepts | accepts |
| Added axiom | passes | the added axiom | accepts | refuses: axiom not permitted |
| Unfinished proof | passes, with a warning | the placeholder axiom | accepts | refuses: axiom not permitted |
| One-number system | passes | one standard axiom | accepts | accepts |
| Different plus sign | passes | none | accepts | accepts |
| Faulty definition | passes | one standard axiom | accepts | accepts |
| Kernel check off | passes | none | **rejects** | does not accept (assertion failure, exit code 101) |

The per-demo statements are in the statement file.

## Status

Seven Lean demonstrations; not yet refereed. Each result was produced on one Windows PC and produced again, after edits to the comments of six files and to one declaration name; the output in this guide is from the second run. Lean 4.34.1 (commit 5045d005) was used for the builds and leanchecker; Lean 4.35.0 (commit eb6cafb7) for the nanoda step, because leanexport (lean4export 3.1.0) and nanoda_bin (0.4.19) are in that release toolchain and not in 4.34.1's. No reader outside this project has reviewed the files or the text.

## Commands

Start with the fingerprints. The certificates folder holds one file, a SHA-256 list of the seven Lean files and the three build files. The three build files are in the download lean-verified-lean.zip (unpack it as the lean folder). The seven Lean files are in the demos folder; download them into a demos folder next to the lean folder. From the book folder, run the command below (on Windows, CertUtil -hashfile with SHA256 does the same one file at a time); with all ten files, every line must report OK.

```
sha256sum -c certificates/SHA256SUMS.txt  # Linux
shasum -a 256 -c certificates/SHA256SUMS.txt   # macOS
```

You need elan (the Lean version manager). No Mathlib. The lean folder pins Lean 4.34.1. Run from the lean folder of this book. For each demo name in the table below, run:

```
lake build Demo.<Name>
lake env leanchecker Demo.<Name>
lake env leanchecker --fresh Demo.<Name>
```

The build command builds the file and prints Lean's messages, including the axiom report. The replay command replays every stored declaration through the kernel. The fresh command also replays everything the file imports (about 100 seconds and 1 GB of memory per demo). leanchecker prints nothing and exits with code 0 when it accepts; it prints a message and exits with code 1 when it rejects.

Optional second kernel (nanoda). Build the same files with Lean 4.35.0, export the named theorem, and give the export to nanoda with a configuration that permits only the three standard axioms:

```
lake env leanexport Demo.<Name> -- <theorem name> > export.ndjson
lake env nanoda_bin config.json
```

where config.json is:

```
{
  "export_file_path": "export.ndjson",
  "permitted_axioms": ["propext", "Classical.choice", "Quot.sound"],
  "unpermitted_axiom_hard_error": true,
  "nat_extension": true,
  "string_extension": true,
  "print_success_message": true,
  "print_axioms": false,
  "num_threads": 1,
  "pp_to_stdout": false,
  "pp_declars": []
}
```

### Recipe for each demo

Each recipe gives the module name, the theorem to export for nanoda, and the expected output.

**Honest file.** The module, and the theorem to export for nanoda:

```
module:  Demo.Honest
theorem: Demo.honest
```

Expected build output:

```
ℹ Built Demo.Honest
info: ../demos/Demo/Honest.lean:4:0: 'Demo.honest' does not depend on any axioms
Build completed successfully (2 jobs).
```

leanchecker: accepts, both modes. nanoda: Checked 38 declarations with no errors.

**Added axiom.** The module, and the theorem to export for nanoda:

```
module:  Demo.AddedAxiom
theorem: Demo.two_plus_two_is_five
```

Expected build output:

```
ℹ Built Demo.AddedAxiom
info: ../demos/Demo/AddedAxiom.lean:7:0: 'Demo.two_plus_two_is_five' depends on axioms: [Demo.bad]
Build completed successfully (2 jobs).
```

leanchecker: accepts, both modes. nanoda refuses the export:

```
Error: export file declares unpermitted axiom "Demo.bad"
```

**Unfinished proof.** The module, and the theorem to export for nanoda:

```
module:  Demo.UsesSorry
theorem: Demo.two_plus_two_is_five_sorry
```

Expected build output:

```
⚠ Built Demo.UsesSorry
warning: ../demos/Demo/UsesSorry.lean:3:8: declaration uses `sorry`
info: ../demos/Demo/UsesSorry.lean:5:0: 'Demo.two_plus_two_is_five_sorry' depends on axioms: [sorryAx]
Build completed successfully (2 jobs).
```

leanchecker: accepts, both modes. nanoda refuses the export:

```
Error: export file declares unpermitted axiom "sorryAx"
```

**One-number system.** The module, and the theorem to export for nanoda:

```
module:  Demo.SmallerNumberSystem
theorem: Demo.small_number_system
```

Expected build output:

```
ℹ Built Demo.SmallerNumberSystem
info: ../demos/Demo/SmallerNumberSystem.lean:7:0: 'Demo.small_number_system' depends on axioms: [propext]
info: ../demos/Demo/SmallerNumberSystem.lean:8:0: 5 : Fin 1
info: ../demos/Demo/SmallerNumberSystem.lean:9:0: 0
info: ../demos/Demo/SmallerNumberSystem.lean:10:0: 0
Build completed successfully (2 jobs).
```

leanchecker: accepts, both modes. nanoda: Checked 294 declarations with no errors.

**Different plus sign.** The module, and the theorem to export for nanoda:

```
module:  Demo.RedefinedPlus
theorem: Demo.redefined_plus
```

Expected build output:

```
ℹ Built Demo.RedefinedPlus
info: ../demos/Demo/RedefinedPlus.lean:12:0: 'Demo.redefined_plus' does not depend on any axioms
info: ../demos/Demo/RedefinedPlus.lean:13:0: 5
info: ../demos/Demo/RedefinedPlus.lean:14:0: instAddNat_demo
info: ../demos/Demo/RedefinedPlus.lean:19:0: instAddNat
Build completed successfully (2 jobs).
```

leanchecker: accepts, both modes. nanoda: Checked 38 declarations with no errors.

**Faulty definition.** The module, and the theorem to export for nanoda:

```
module:  Demo.WrongDefinition
theorem: Demo.one_is_prime
```

Expected build output:

```
ℹ Built Demo.WrongDefinition
info: ../demos/Demo/WrongDefinition.lean:10:0: 'Demo.one_is_prime' depends on axioms: [propext]
Build completed successfully (2 jobs).
```

leanchecker: accepts, both modes. nanoda: Checked 198 declarations with no errors.

**Kernel check off.** The module, and the theorem to export for nanoda:

```
module:  Demo.SkipKernelTC
theorem: Demo.wrong
```

Expected build output:

```
ℹ Built Demo.SkipKernelTC
info: ../demos/Demo/SkipKernelTC.lean:13:0: 'Demo.unchecked' does not depend on any axioms
info: ../demos/Demo/SkipKernelTC.lean:18:0: 'Demo.wrong' does not depend on any axioms
Build completed successfully (2 jobs).
```

leanchecker (both modes) rejects, with exit code 1 (the fresh mode prints the same message without its opening line):

```
leanchecker found a problem in Demo.SkipKernelTC
uncaught exception: while replaying declaration 'Demo.unchecked':
(kernel) declaration type mismatch, 'Demo.unchecked' has type
  True
but it is expected to have type
  False
```

nanoda does not accept; it stops with exit code 101:

```
thread 'main' panicked at src\tc.rs:955:71:
assertion failed: self.def_eq(u, v)
```

### What the answers show

Only the last demo is rejected by an automatic re-check. The added axiom and the unfinished proof are caught by the axiom report (and by nanoda's axiom rule). The one-number system, the different plus sign and the faulty definition pass every automatic check, because their proofs are valid; they are caught only by reading the statement and the definitions.

lean4lean was also tried. The copy in the Lean 4.35.0 toolchain folder could not read the compiled files ("incompatible header"), so no lean4lean result is claimed.

How I direct this work, and my own tools, are not part of this book. Everything you need to check the results is public: the results, their certificates and fingerprints, the Lean proofs, and a written recipe for each check. In this book the results are the seven Lean files and what each check printed; there are no certificate files beyond the fingerprint list of those files. The seven Lean files are in the demos folder.

Supporting records are available on request.

## Expected output

The expected output of every command is given in the recipe for each demo above. In short: six of the seven files pass every leanchecker run, the seventh (kernel check off) is rejected by both runs with a type mismatch between True and False, nanoda accepts the four files whose proofs are valid, refuses the two with extra axioms, and does not accept the seventh.

## Time and memory

Without the fresh mode, a few minutes for all seven demos. With the fresh mode, about 100 seconds and up to about 1 GB of memory per demo. The nanoda step takes a few seconds per demo. Setting the environment variable LEAN_NUM_THREADS to 2 keeps memory use modest.

## What is not claimed

- That Lean, leanchecker or nanoda is unreliable. Each behaved as designed; the demonstrations show the limits of what each check covers.
- That these seven files cover every way a Lean result can mislead.
- A result about the 2026 kernel bug. It was not reproduced, and both Lean versions used contain its fix (chapter 4).
- A result from lean4lean (not usable here), from Lean's comparator tool, or from any kernel other than Lean's own and nanoda.
- That nanoda checked the Lean 4.34.1 builds. It checked the same source files built with Lean 4.35.0, because the export tool is in that toolchain.
- That nanoda's behaviour on the kernel-check-off file is a diagnosis. It stopped with an internal assertion failure. The book gives no cause for it; it notes only that the failure is consistent with the type mismatch that leanchecker reports.

## Where to go next

- Why do three of the seven files pass every automatic check? See [What "Lean-verified" does not mean](chapters/02-what-it-does-not-mean.md).
- What happens if the kernel itself has a bug? See [Kernel bugs, and why a second checker helps](chapters/04-kernel-bugs-and-second-checkers.md).
