The Wrong Theorem
A proof assistant checked a theorem perfectly. Our own software then credited it to a claim it never stated. One requested claim, one substituted theorem, one misleading success, and the check that catches it.
The question
You ask a proof assistant to establish a claim. It reports success. What, exactly, has been established?
The obvious answer is “the claim”. This chapter is about why that answer can be wrong even when the proof assistant made no mistake at all, and about the one check that closes the gap. The lesson fits in a sentence:
A valid proof of the wrong proposition is not a proof of the proposition we wanted.
The setup
A proof assistant such as Lean checks declarations: a name, a statement and a proof. Its kernel guarantees that the proof proves the statement. It guarantees nothing about whether that statement is the one somebody else had in mind.
Around the kernel there is always other software: a build script, a test
harness, a benchmark, a system like this book’s that collects evidence and
attaches it to claims. That software has to decide which accepted declaration
counts as evidence for which claim. The simplest rule is to go by the name. You
ask for zero_add_left, the file compiles, a theorem called zero_add_left
exists, it uses no sorry: verified.
That was the rule the laboratory used, and it broke. Its ingestion step
credited kernel results to registered claims by declaration name, and took the
claim’s statement from its own registry rather than from the kernel. An
adversarial review then replaced a theorem with one of the same name stating
only True. Lean accepted it, correctly, because True is true. The ingestor
recorded it as evidence for the original claim. The kernel was right; the
attribution was wrong.
Nothing about Lean or Rocq failed. The defect was entirely in the code that decided what Lean’s success meant.
Run it
The demonstration is deliberately small: one requested claim, four candidate files, two ways of attaching evidence.
python experiments/investigations/p04-wrong-theorem/demo.py
In the pinned image the same demonstration is math-engine proof wrong-theorem, run as shown in the introduction. It also checks that the
claim, the four cases and the historical gate are byte-identical to their
pins, and runs a control that hands the demonstration a tampered claim, which
must be refused.
It needs Python and a Lean binary; Mathlib is not used. In the pinned
environment Lean is already installed. Without Docker, install Lean 4.35.0
(with elan, Lean’s version manager) and pass its path with --lean. The
recorded run, with the full JSON for every case, is
experiments/investigations/p04-wrong-theorem/recorded-run-2026-11-13.json.
The requested claim lives in claim.json:
For every natural number n, 0 + n = n. (
∀ n : Nat, 0 + n = n)
It is small, true, and not true by definition in Lean: Lean’s addition
recurses on its second argument, so 0 + n = n needs a proof by induction. Its
sha256 is pinned inside the demonstration, so the claim cannot quietly change:
edit claim.json and the demonstration refuses to run.
The four files all declare a theorem called P04.zero_add_left:
| Case | What the file states | Is it the requested claim? |
|---|---|---|
| honest | ∀ n : Nat, 0 + n = n, by induction |
yes |
| revised | ∀ m : Nat, 0 + m = m, by a library lemma |
yes: only the variable’s name and the proof differ |
| substituted | True |
no |
| weakened | ∀ n : Nat, n ≤ 10 → 0 + n = n |
no: it only covers n up to 10 |
Each file goes through two gates. The name-only gate is the old rule,
kept as a historical regression fixture (historical/name_only_gate.py), never
in production code; a test enforces that. The statement gate is the
project’s identity check. It asks Lean itself to accept
theorem bind : <the statement in claim.json> := @P04.zero_add_left
that is, to confirm that the declaration is a proof of the pinned statement, and it checks the declaration’s axioms against policy.
What happened
Run with Lean 4.35.0:
Requested: For every natural number n, 0 + n = n. (∀ n : Nat, 0 + n = n)
case name-only gate (historical) statement gate
honest verified accepted
revised verified accepted
substituted verified refused
weakened verified refused
Look at the substituted row. The name-only gate reports verified, and the record it writes credits the file with the statement “For every natural number n, 0 + n = n”. Every fact it checked was true: the file compiled, the declaration exists, its axioms are clean (it uses none at all). The conclusion is false.
The statement gate refuses the same file, for one reason: Lean will not
accept @P04.zero_add_left as a proof of ∀ n : Nat, 0 + n = n, because it
is a proof of True. The weakened case is the subtler attack, a true theorem
about the right objects that falls short of the claim, and it is refused for
the same reason.
The first two rows matter as much. The honest and revised files are both accepted. A gate that refused everything would also stop the substitution; the revised case shows this one does not. Renaming a bound variable or changing the proof changes nothing that matters, and the check knows it.
The two gates side by side. Name-only trusts the label and is right three
times out of four — the substituted row is the one that matters. The statement
gate type-checks theorem bind : <claim.json> := @P04.zero_add_left and refuses
exactly the files that state something else. The figure summarizes the run
table; it performs no check itself.
Why
A theorem’s name is a label chosen by whoever wrote the file. Its statement is what the kernel checked. The name-only gate trusts the label and supplies the statement from somewhere else, here from the registry. The two can drift apart through a mistake, a refactor or an attack, and the gate cannot tell.
The statement gate does not compare text. It asks the kernel the one question
the kernel can answer with authority: is this declaration a proof of that
proposition? Lean answers by type-checking the binding, which succeeds exactly
when the declaration’s type is definitionally equal to the pinned statement.
That is why the alpha-renamed ∀ m passes (it is the same proposition) and
True does not.
Where the pinned statement comes from matters too. The gate compares each file
with claim.json, whose hash is fixed independently of the files. It never
asks a file what it claims to prove. A check that compared two records that
agree with each other, both wrong, would pass.
What was actually checked
- The reader demonstration. Four cases, both gates, with real Lean 4.35.0 (core, without Mathlib), run locally and in the pinned image: every case as expected. A test runs it whenever Lean is available. The pinned run is in the evidence table.
- The original incident and its repair, on the full pinned toolchain. The
repaired identity check (MATH-INV-02F) was run against the real
investigation files in Lean with Mathlib and in Rocq. All 84 authorized
declarations (42 in each kernel) were accepted under the identity contract. 168 of 168
pre-registered mutation decisions came out as registered, with no unsafe
acceptance. The 02E replay, every theorem replaced by a same-name
True, was rejected for all 14 names in both kernels. - The attack replay. Every 02E attack that the old attachment rule let through (an empty mapping, an unrelated theorem, a fake control, the same-name substitution) is blocked by the new one, each for its intended reason. Valid cases are still authorized.
What this establishes
That a kernel can correctly accept a declaration whose statement is not the claim it is credited with, and that a system which attaches evidence by name will then report the wrong claim as verified. That binding the declaration to an independently pinned statement, checked by the kernel itself, refuses the substitution and the weakening while still accepting a genuine proof with a renamed variable or a new proof.
What remains open
- Completeness. The identity check rejects every registered attack. That does not show it rejects every possible attack; only the registered ones are tested.
- The pinned statement is only as good as its reading. The gate guarantees
that evidence matches the statement in
claim.json. Whether that statement says what the English claim means is the correspondence question; the kernel cannot settle it.
Try it yourself
- Run the demonstration and read the JSON record for the substituted case. Which statement does the name-only gate credit, and where did that text come from?
- Add a fifth case:
theorem zero_add_left : ∀ n : Nat, n + 0 = n. It is true, and it is the “same” fact to a human reader. Which gates accept it, and why should the statement gate refuse it? - Change one character of
claim.jsonand run again. Why does the demonstration refuse to start? - Make the variable implicit:
∀ {n : Nat}, 0 + n = n. The binding check in this demonstration accepts it, because binder style does not change the proposition. The full MATH-INV-02F contract also compares a structural fingerprint, and refuses it as drift until it is re-approved. Which policy would you choose, and why?
Worked answers: Chapter 35 — Appendix A: Solutions to the Exercises (Part IV, Appendix A)#chapter-4-the-wrong-theorem.
Evidence record
| Contract | experiments/investigations/p04-wrong-theorem/contract.json: lightweight contract (pinned claim, the four cases and their expected outcomes); no kernel qualification claimed |
| Demonstration | experiments/investigations/p04-wrong-theorem/demo.py; claim claim.json (sha256 37b8db8f…); cases in cases/; historical fixture historical/name_only_gate.py; test tests/test_p04_wrong_theorem.py |
| Result | attribution_defect_shown_and_repaired (Lean 4.35.0 core); record recorded-run-2026-11-13.json |
| Reader run | math-engine proof wrong-theorem, run 20261113T232811Z-24153376 in math-env (sha256:74006085…, core Lean 4.35.0), source commit 1f9158e: the kernel checks passed; tampered-claim control refused. Record: experiments/investigations/p04-wrong-theorem/runner-runs/2026-11-13-pinned/ |
| Original incident | an adversarial review of the earlier theorem-identity gate |
| Repair on the full toolchain | the full theorem-identity contract, run 20261113T013549Z-a7525cef: 84/84 identity-bound declarations, 168/168 mutation decisions as registered, 0 unsafe acceptances |
| Production check | src/math_engine/formal_identity.py (lean_identity_footer, lean_declaration_export) |
Sources
- MATH-INV-02F, theorem identity contract
(
docs/research/math-inv-02/02f/MATH-INV-02F-THEOREM-IDENTITY.md), mutation results (MATH-INV-02F-MUTATION-RESULTS.md) and the second full-toolchain run (MATH-INV-02F-D0-RUN-2.md). - MATH-INV-02E, adversarial review and issue register
(
docs/research/math-inv-02/02e/).
Further Reading
For deeper study; not sources for the chapter’s claims.
- Talia Ringer, Karl Palmskog, Ilya Sergey, Milos Gligoric, Zachary Tatlock. “QED at Large: A Survey of Engineering of Formally Verified Software.” Foundations and Trends in Programming Languages 5(2–3) (2019), 102–281. DOI. Why read it: A survey of the engineering gap between a kernel-checked proof and the specification or claim it is meant to establish, which is precisely the failure the chapter describes.
- Richard A. De Millo, Richard J. Lipton, Alan J. Perlis. “Social processes and proofs of theorems and programs.” Communications of the ACM 22(5) (1979), 271–280. DOI. Why read it: The classic argument that formal verification does not by itself settle mathematical or social trust, a useful counterpoint to reading a kernel’s acceptance as the end of the matter.
The mathematics behind this chapter: Chapter 15 — What a Formal Proposition Says (Part II, Chapter 6) (what a formal proposition says) and Chapter 16 — What a Proof Rests On (Part II, Chapter 7) (what a proof rests on).
Next: Chapter 6, an AI-assisted formalization whose headline theorem rests on one unproved step, and the audit that finds it.