Repository navigation
fix: make the kernel is_prop check require a sort - #14807
Merged
Merged
Conversation
This PR fixes a soundness issue. **TL;DR.** The kernel's `is_prop` decided whether a term is a proposition by taking the weak head normal form of its inferred type and checking that the result is syntactically `Sort 0`. When the inferred type did not reduce to a sort but was left as a stuck term, `is_prop` returned `false` instead of treating the term as ill-formed. This let the proof-irrelevance guard in projection inference be skipped, so a non-proof field could be projected out of a value used as a `Prop`, and `False` derived. The fix computes the inferred type with `ensure_sort`, which reduces it and requires the result to be a sort, raising `(kernel) type expected` otherwise. The bogus proof was also accepted by nanoda, an independent implementation of the Lean kernel. When a field is projected out of a value whose type is a proposition, the kernel requires the field's type to also be a proposition. This is what keeps proof irrelevance sound: any two proofs of the same proposition are definitionally equal, so if a projection could read a piece of data (something not itself a proof) out of a proof, that data would be forced to be equal for all proofs, which is false in general. The guard is expressed in terms of `is_prop`. `is_prop e` computed `whnf (infer_type e)` and returned whether the result is a sort whose level normalizes to zero. The problem is the case where `infer_type e` is a stuck term that does not reduce to a sort, for example an `Eq.rec` whose major premise is a free variable. There `whnf` returns the stuck term, `is_sort` is `false`, and `is_prop` returns `false`. Returning `false` means "not a proposition", which skips the projection guard even when the value is being used as a `Prop` elsewhere. With the guard skipped, a data field can be projected out of that value, and combined with proof irrelevance this yields `False`. The fix replaces `whnf` with `ensure_sort`: `is_prop` now reduces the inferred type and requires it to be a sort, raising `(kernel) type expected` if it is not. A value whose type does not reduce to a sort is ill-formed, so rejecting it is correct. On well-typed terms the type of a type is always a genuine sort, so the stricter check never fires spuriously. The bogus proof was also accepted by nanoda, an independent implementation of the Lean kernel.
leodemoura
enabled auto-merge
August 18, 2026 00:34
leodemoura
enabled auto-merge
August 18, 2026 00:55
Collaborator
|
Reference manual CI status:
|
|
Mathlib CI status (docs):
|
nomeata
added a commit
to leanprover/lean-kernel-arena
that referenced
this pull request
Aug 18, 2026
#141) Definitional equality is not transitive on three `Acc.rec`-based values: proof irrelevance relates `a ≡ b` and `b ≡ c`, but not `a ≡ c`. Three ways to turn that into `False`: * rec-missing-ih: in the affected kernels the defeq cache is a union-find structure, i.e. it closes that relation transitively, but it is only consulted for expressions with equal hashes. A crafted collision therefore makes a K-like reduction fire in the pass that builds the minor premises of a recursor and not in the pass that builds its rules, so the `step` minor premise takes an induction hypothesis that its rule does not supply. Fixed by leanprover/lean4#14806. Frozen as a static export file, since the malformed recursor comes out of the kernel's own inductive-type elaborator; the reproducer is kept alongside it. * proj-of-stuck-prop: the same reduction decides the result sort of an inductive family, which is a `Prop` when checked under `_kernel_fresh.0` and stuck for the closed instantiation, so a `Bool` field can be projected out of a proposition that proof irrelevance applies to. Fixed by leanprover/lean4#14807, and its use of the cache by #14806. * proj-of-subst-prop: the same projection, but reached without any help from the defeq cache — `P := a = b` and `Q := a = c` are definitionally equal types whose proofs behave differently under `Eq.rec`, so an inductive family declared over `P` is a family of propositions while its instance at a proof of `Q` has a sort that does not reduce to `Prop`. Needs no axioms. Fixed by leanprover/lean4#14807. All three were accepted by the official kernel at v4.28.0, v4.29.1, v4.33.0 and nightly-2026-08-01, which also re-derives the broken declarations when replaying the export data. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013aD597ZqUV1XrMPdveoaKt Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
VladimirReshetnikov
added a commit
to VladimirReshetnikov/Shenanigans
that referenced
this pull request
Aug 18, 2026
Turns the hunt's strongest finding into something deliverable rather than leaving it as a CATALOG row. Reports/2026-08-18-upstream-14807-incomplete.md is written to be pasted as a comment on leanprover/lean4#14807 or filed as an issue referencing it. The substance: #14807 fixed type_checker::is_prop by replacing whnf with ensure_sort, so an unreducible inferred type is rejected instead of reported as "not a proposition". to_cnstr_when_structure in src/kernel/inductive.h hand-inlines the same predicate, with a comment showing the copy was made by hand when #14613 was fixed, and it is byte-identical on releases/v4.33.0 and on master -- so the fix written for that defect does not reach its second copy. There the negative answer is permission: control falls to expand_eta_struct, which fabricates mk_proj nodes for every field and hands them to the recursor's computation rule without any of them passing infer_proj. Of the seven is_sort( hits in the kernel, five assert or throw and two reduce-and-match; of those two, only inductive.h reads the negative as permission to EMIT new terms rather than to skip a check. The draft is explicit that this is not a proof of False on any toolchain and that I could not make it one, and it gives the structural reason: a Prop-valued one-constructor structure carrying data gets a Prop-only recursor -- the frontend refuses its projection with "field must be a proof, but it has type Bool" -- while a subsingleton that large-eliminates has no data to extract. The ask is narrower and defensible: after #14807 ships this site is still open, it is the only remaining place where an unreducible type yields permission rather than rejection, and what it permits is fabricating projections. Includes the four-toolchain eta measurement and a suggested fix (call type_checker::is_prop rather than re-implementing it; the duplication is what let the copies drift across #14613 and #14807). Co-Authored-By: Claude Opus 5 <[email protected]>
yermakoffivan
pushed a commit
to yermakoffivan/lean4
that referenced
this pull request
Aug 19, 2026
This PR applies the fix from leanprover#14807 to `inductive.h`. As the comment in `inductive.h` points out, the code should check whether `e_type` is a proposition using `is_prop`, but it was still inlining the old, buggy version of `is_prop`.
kim-em
pushed a commit
that referenced
this pull request
Aug 21, 2026
This PR fixes a soundness issue. **TL;DR.** The kernel's `is_prop` decided whether a term is a proposition by taking the weak head normal form of its inferred type and checking that the result is syntactically `Sort 0`. When the inferred type did not reduce to a sort but was left as a stuck term, `is_prop` returned `false` instead of treating the term as ill-formed. This let the proof-irrelevance guard in projection inference be skipped, so a non-proof field could be projected out of a value used as a `Prop`, and `False` derived. The fix computes the inferred type with `ensure_sort`, which reduces it and requires the result to be a sort, raising `(kernel) type expected` otherwise. The bogus proof was also accepted by nanoda, an independent implementation of the Lean kernel. We believe the lean4lean external kernel does not have this bug. When a field is projected out of a value whose type is a proposition, the kernel requires the field's type to also be a proposition. This is what keeps proof irrelevance sound: any two proofs of the same proposition are definitionally equal, so if a projection could read a piece of data (something not itself a proof) out of a proof, that data would be forced to be equal for all proofs, which is false in general. The guard is expressed in terms of `is_prop`. `is_prop e` computed `whnf (infer_type e)` and returned whether the result is a sort whose level normalizes to zero. The problem is the case where `infer_type e` is a stuck term that does not reduce to a sort, for example an `Eq.rec` whose major premise is a free variable. There `whnf` returns the stuck term, `is_sort` is `false`, and `is_prop` returns `false`. Returning `false` means "not a proposition", which skips the projection guard even when the value is being used as a `Prop` elsewhere. With the guard skipped, a data field can be projected out of that value, and combined with proof irrelevance this yields `False`. The fix replaces `whnf` with `ensure_sort`: `is_prop` now reduces the inferred type and requires it to be a sort, raising `(kernel) type expected` if it is not. A value whose type does not reduce to a sort is ill-formed, so rejecting it is correct. On well-typed terms the type of a type is always a genuine sort, so the stricter check never fires spuriously. The issue was reported by Daniel Selsam (OpenAI) using their internal models. The bogus proof was also accepted by nanoda, an independent implementation of the Lean kernel. We claim that lean4lean, another implementation of the Lean kernel, does **not** have this bug, since their `isProp` already uses `ensureSortCore` (See https://github.com/digama0/lean4lean/blob/master/Lean4Lean/TypeChecker.lean#L224-L230). (cherry picked from commit 7412bc4)
kim-em
pushed a commit
that referenced
this pull request
Aug 21, 2026
This PR fixes a soundness issue. **TL;DR.** The kernel's `is_prop` decided whether a term is a proposition by taking the weak head normal form of its inferred type and checking that the result is syntactically `Sort 0`. When the inferred type did not reduce to a sort but was left as a stuck term, `is_prop` returned `false` instead of treating the term as ill-formed. This let the proof-irrelevance guard in projection inference be skipped, so a non-proof field could be projected out of a value used as a `Prop`, and `False` derived. The fix computes the inferred type with `ensure_sort`, which reduces it and requires the result to be a sort, raising `(kernel) type expected` otherwise. The bogus proof was also accepted by nanoda, an independent implementation of the Lean kernel. We believe the lean4lean external kernel does not have this bug. When a field is projected out of a value whose type is a proposition, the kernel requires the field's type to also be a proposition. This is what keeps proof irrelevance sound: any two proofs of the same proposition are definitionally equal, so if a projection could read a piece of data (something not itself a proof) out of a proof, that data would be forced to be equal for all proofs, which is false in general. The guard is expressed in terms of `is_prop`. `is_prop e` computed `whnf (infer_type e)` and returned whether the result is a sort whose level normalizes to zero. The problem is the case where `infer_type e` is a stuck term that does not reduce to a sort, for example an `Eq.rec` whose major premise is a free variable. There `whnf` returns the stuck term, `is_sort` is `false`, and `is_prop` returns `false`. Returning `false` means "not a proposition", which skips the projection guard even when the value is being used as a `Prop` elsewhere. With the guard skipped, a data field can be projected out of that value, and combined with proof irrelevance this yields `False`. The fix replaces `whnf` with `ensure_sort`: `is_prop` now reduces the inferred type and requires it to be a sort, raising `(kernel) type expected` if it is not. A value whose type does not reduce to a sort is ill-formed, so rejecting it is correct. On well-typed terms the type of a type is always a genuine sort, so the stricter check never fires spuriously. The issue was reported by Daniel Selsam (OpenAI) using their internal models. The bogus proof was also accepted by nanoda, an independent implementation of the Lean kernel. We claim that lean4lean, another implementation of the Lean kernel, does **not** have this bug, since their `isProp` already uses `ensureSortCore` (See https://github.com/digama0/lean4lean/blob/master/Lean4Lean/TypeChecker.lean#L224-L230). (cherry picked from commit 7412bc4)
nomeata
added a commit
that referenced
this pull request
Aug 21, 2026
The three kernel soundness regression tests added by #14806 and #14807 build their exploit on `Acc.rec` at a `Bool` motive, which this branch forbids, so they no longer elaborate. `Acc.rec'` cannot stand in: it is backed by `Classical.choice` and has no iota rule, so the definitionally-distinct reducts the tests rely on do not exist. This mirrors the earlier removal of `tests/elab/casesOnAcc.lean`. It does cost coverage for the `is_def_eq` cache and `is_prop` fixes; reinstating it needs an exploit vehicle that does not go through a recursive `Prop` inductive. Co-Authored-By: Claude Opus 5 <[email protected]>
nomeata
added a commit
to leanprover/lean-kernel-arena
that referenced
this pull request
Aug 21, 2026
…152) The same `Prop` that carries a `Type` field — `Issue.Owner : ∀ (h : GateP), resultSort h`, where `resultSort h` K-reduces to `Prop` for a variable `h` and stays stuck for the closed `gateWitness : GateQ` — but the field is recovered through the `Prop`-only recursor, an `Acc.rec` large elimination and a `propext` transport rather than through a projection, so a guard on projections alone does not catch it. Proof irrelevance identifies `Owner.mk gateWitness Empty` with `Owner.mk gateWitness Unit`, and `Empty` becomes inhabited; the proof uses `propext` and no other axiom. Fixed, like proj-of-subst-prop, by leanprover/lean4#14807. The exploit is by Daniel Selsam (OpenAI), generated with OpenAI's internal models, and is the regression test from leanprover/lean4#14847. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013aD597ZqUV1XrMPdveoaKt Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
5 tasks
nomeata
added a commit
to nomeata/lean-inductive-models
that referenced
this pull request
Oct 1, 2026
The toolchain moves from v4.33.0 to v4.35.0-rc3. The code builds unchanged, with no warnings; what moved is behavior that tests and docs pin. * Kernel soundness fixes (in v4.34.0). leanprover/lean4#14807 makes `is_prop` require the inferred type to reduce to a sort, and #14806 replaces the union-find `is_def_eq` success cache with an order-independent pair set. With these, `--type-check-input` rejects the Arena's bad/bugs/proj-of-stuck-prop, proj-of-subst-prop, rec-of-subst-prop and rec-missing-ih (exit 1; they were exit 3 on v4.33.0). The Arena corpus is now 123 good accepted and 71 bad rejected, with 0 checker errors (it was 67 rejected and 4 errors). The README, `Driver/Filter.lean`, `MainCliTest` and the `defhead_beyond_delta` source said Lean's kernel "is unsound on" owners whose sort is computed by ι or projection. It was a specific, since-fixed bug, and they now say so. The exit-3 guard stays, because the checker's normaliser still cannot restate such an owner. * #14582 (v4.34.0) makes the kernel reject non-uniform occurrences of a datatype being declared. con-leche's `nested_nonuniform_param` is therefore now `1 reject` in the verdict table, where it was `0 accept`. The table header now says its kernel column is the pinned toolchain's. * #14771 (v4.35.0) makes `Environment.find?` fall back to the kernel constant map of an `ofKernelEnv` environment. The `runEnvProbe` canary fired, and it now pins the new behaviour: `Tree` and `Tree.rec_1` are visible. Its doc and `runCollisionProbe`'s now say the kernel-level replay route is open but unused. `runCollisionProbe`'s `Environment.lean` line citations are re-read against v4.35.0-rc3. * #14728 (v4.34.0) makes `foldConsts`/`getUsedConstants` count projection structure names. `Order.lean`'s own walk stays, because it shares one visited set across a record's roots, and its comment now says why. * DagSafety.md's list of which core walks are memoized is re-read against v4.35.0-rc3. Only `foldConsts` and `instantiateMVars` (#14520, a lift cache) changed. The note on structural caches now covers the kernel's new defeq success set. * ci.yml and Testing.md: the address-space figures for `lean` are re-measured. The fixture and Mathlib exports stay as they are. They are produced by lean4export caccfbe on v4.29.1, independently of this toolchain. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DBwTeqz3xpWkJVcrfwWZJo
gimbalzero
added a commit
to gimbalzero/certus
that referenced
this pull request
Nov 21, 2026
`is_proof_type` answered "not a proposition" when the inferred type of `t` did not reduce to a sort. For a structure whose sort is a stuck term this let `infer_proj` skip the "no data out of a proof" guard, and together with proof irrelevance that proves `False` (Arena bugs/proj-of-subst-prop). As in leanprover/lean4#14807, the type of `t` must now reduce to a sort, and otherwise checking fails with "type expected". Adds the Arena reproducer as a fixture and a regression test that requires its rejection. Co-Authored-By: Claude Opus 5.5 <[email protected]>
gimbalzero
added a commit
to gimbalzero/certus
that referenced
this pull request
Nov 22, 2026
* Kernel: is_proof_type requires a sort (fixes proof of False, #17) `is_proof_type` answered "not a proposition" when the inferred type of `t` did not reduce to a sort. For a structure whose sort is a stuck term this let `infer_proj` skip the "no data out of a proof" guard, and together with proof irrelevance that proves `False` (Arena bugs/proj-of-subst-prop). As in leanprover/lean4#14807, the type of `t` must now reduce to a sort, and otherwise checking fails with "type expected". Adds the Arena reproducer as a fixture and a regression test that requires its rejection. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Arena: bugs/proj-of-subst-prop is now rejected; drop it from known-unsound.txt Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a soundness issue.
TL;DR. The kernel's
is_propdecided whether a term is a proposition by taking the weak head normal form of its inferred type and checking that the result is syntacticallySort 0. When the inferred type did not reduce to a sort but was left as a stuck term,is_propreturnedfalseinstead of treating the term as ill-formed. This let the proof-irrelevance guard in projection inference be skipped, so a non-proof field could be projected out of a value used as aProp, andFalsederived. The fix computes the inferred type withensure_sort, which reduces it and requires the result to be a sort, raising(kernel) type expectedotherwise. The bogus proof was also accepted by nanoda, an independent implementation of the Lean kernel. We believe the lean4lean external kernel does not have this bug.When a field is projected out of a value whose type is a proposition, the kernel requires the field's type to also be a proposition. This is what keeps proof irrelevance sound: any two proofs of the same proposition are definitionally equal, so if a projection could read a piece of data (something not itself a proof) out of a proof, that data would be forced to be equal for all proofs, which is false in general. The guard is expressed in terms of
is_prop.is_prop ecomputedwhnf (infer_type e)and returned whether the result is a sort whose level normalizes to zero. The problem is the case whereinfer_type eis a stuck term that does not reduce to a sort, for example anEq.recwhose major premise is a free variable. Therewhnfreturns the stuck term,is_sortisfalse, andis_propreturnsfalse. Returningfalsemeans "not a proposition", which skips the projection guard even when the value is being used as aPropelsewhere. With the guard skipped, a data field can be projected out of that value, and combined with proof irrelevance this yieldsFalse.The fix replaces
whnfwithensure_sort:is_propnow reduces the inferred type and requires it to be a sort, raising(kernel) type expectedif it is not. A value whose type does not reduce to a sort is ill-formed, so rejecting it is correct. On well-typed terms the type of a type is always a genuine sort, so the stricter check never fires spuriously.The issue was reported by Daniel Selsam (OpenAI) using their internal models.
The bogus proof was also accepted by nanoda, an independent implementation of the Lean kernel.
We claim that lean4lean, another implementation of the Lean kernel, does not have this bug, since their
isPropalready usesensureSortCore(See https://github.com/digama0/lean4lean/blob/master/Lean4Lean/TypeChecker.lean#L224-L230).