Repository navigation
fix: reject declarations naming the kernel's _nested auxiliary types - #14616
Merged
Merged
Conversation
This PR fixes a kernel bug: an inductive declaration could name one of the auxiliary types the kernel generates when eliminating nested inductives, and end up with a stored constructor type that is ill typed. Such a declaration can only be produced with metaprogramming. The auxiliary types live under `_nested` and exist only in the temporary environment used for the elimination. A constructor naming one is checked there, but `restore_nested` then rewrites the name back to the nested type, which can live in a different universe. Combined with proof irrelevance, the resulting ill-typed constructor makes two distinct functions look like proofs of the same proposition, and `equiv_manager` closes them transitively, giving `False` with no axiom dependencies. `environment::add_inductive` now rejects the reserved prefix, alongside the existing checks for metavariables and free variables. Both `Expr.const` names and `Expr.proj` structure names are covered: the kernel rewrites nested occurrences in the constructor to the auxiliary type, so a projection can reach that type without the declaration naming it as a constant.
leodemoura
enabled auto-merge
July 31, 2026 12:15
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
leodemoura
added a commit
that referenced
this pull request
Jul 31, 2026
…ration This PR makes the kernel re-check what it writes into the environment after eliminating a nested inductive. `restore_nested` rewrites the auxiliary types back into nested applications, and the resulting constructor types, recursor types, and recursor computation rules were added without being type checked. The other checks in `add_inductive` are expected to make this redundant, and no declaration in the standard library or the test suite fails it. It is defense in depth against a mistake in the restoration reaching the environment: with the `_nested` prefix check from #14616 disabled, this check on its own rejects the reproducer for that issue, with the ill-typed application that was its root cause. The inductive types themselves are added unchanged rather than restored, so they need no check. The cost is not measurable: on a file declaring 300 nested inductives, 5778/5532/5708/5731 ms with the check versus 5555/5598/5761/5780 ms without. Co-Authored-By: Claude Fable 5 <[email protected]>
nomeata
added a commit
to leanprover/lean-kernel-arena
that referenced
this pull request
Jul 31, 2026
Scaled-down regression test for the kernel bug fixed in leanprover/lean4#14616. A declaration that names one of the kernel's _nested auxiliary types must be rejected by a correct kernel (the fix adds a reserved-prefix check in add_inductive, covering both Expr.const names and Expr.proj structure names). This is deliberately NOT a proof of False. The bug's axiom-free False relies on transient in-kernel state (the equiv_manager defeq cache) that is not reconstructed on a fresh replay of an export, so it cannot be captured as an export-based arena test: the same buggy official kernel that accepts the exploit in-memory rejects the exported form. Instead, this mirrors the upstream test tests/elab/kernelNestedAuxName.lean. tests/nested-aux-name.{lean,yaml} export a well-typed inductive KNAux whose constructor field names the ordinary Prop-valued def _nested.KNHost_1. Because KNAux is well-typed, an unguarded kernel accepts it; a guarded kernel rejects it for the reserved _nested prefix. Verified: official (v4.32.1, guard unreleased) accepts the exported KNAux -- reported incorrect, as expected; flips to correct once the fix ships. Uses metaprogramming (skipKernelTC), so a standalone test. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01N8V39PLAKbpoG7ctgCFhbp Co-authored-by: Claude Fable 5 <[email protected]>
Garmelon
pushed a commit
that referenced
this pull request
Aug 3, 2026
#14616) This PR fixes a kernel bug: an inductive declaration could reference one of the auxiliary types the kernel generates when eliminating nested inductives, and end up with a stored constructor type that is ill typed. Such a declaration can only be produced with metaprogramming. The auxiliary types live under `_nested` and exist only in the temporary environment used for the elimination. A constructor naming one is checked there, but `restore_nested` then rewrites the name back to the nested type, which can live in a different universe. Combined with proof irrelevance, the resulting ill-typed constructor makes two distinct functions look like proofs of the same proposition, and `equiv_manager` closes them transitively, giving `False` with no axiom dependencies. The kernel now rejects the reserved prefix, alongside the existing checks for metavariables and free variables. Both `Expr.const` names and `Expr.proj` structure names are covered: the kernel rewrites nested occurrences in the constructor to the auxiliary type, so a projection can reach that type without the declaration naming it as a constant.
2 of 3 tasks
keithadler
added a commit
to keithadler/tenet
that referenced
this pull request
Sep 27, 2026
Divergence 3 and the negative corpus said Lean reserves the whole _nested namespace and Tenet does the same. It does not. leanprover/lean4#14616 adds check_no_nested_aux to add_inductive, which rejects an inductive whose type or constructor types mention a _nested constant or proj structure name, and nothing more. reserved-namespace.ndjson, which declares axiom _nested.squatter, comes back ok=1 failed=0 through tools/leancheck on Lean 4.34.1. mk_unique_name skips names already taken, so a squatter does not disturb the elimination either. Tenet already makes that check, in Inductive.CheckNoNestedAux. Reserving every name under the prefix is on top of it, so Tenet rejects a file Lean accepts. The entry now says so and keeps the reservation as a deliberate strictness divergence, with its cost stated. The overview no longer counts it among the entries where Tenet is closer to the type theory, since the theory has nothing to say about names. The manifest and the comments on NestedPrefix and its test, which repeated the claim, are corrected too. Kernel behaviour is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
kim-em
added a commit
to kim-em/lean4lean
that referenced
this pull request
Oct 12, 2026
`environment::add_inductive` runs `check_no_nested_aux` on the inductive types as well as on the constructor types (leanprover/lean4#14616); do the same in `checkInductiveSources` and retire the divergence entry (the kernel does not otherwise reserve the `_nested` namespace). The proofs discard the new check's result. `Tests/KernelHardening.lean` checks that both kernels reject an inductive type naming `_nested` for the reserved prefix. Co-Authored-By: Claude Fable 5.1 <[email protected]>
4 tasks done
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 kernel bug: an inductive declaration could reference one of the auxiliary types the kernel generates when eliminating nested inductives, and end up with a stored constructor type that is ill typed. Such a declaration can only be produced with metaprogramming.
The auxiliary types live under
_nestedand exist only in the temporary environment used for the elimination. A constructor naming one is checked there, butrestore_nestedthen rewrites the name back to the nested type, which can live in a different universe. Combined with proof irrelevance, the resulting ill-typed constructor makes two distinct functions look like proofs of the same proposition, andequiv_managercloses them transitively, givingFalsewith no axiom dependencies.The kernel now rejects the reserved prefix, alongside the existing checks for metavariables and free variables. Both
Expr.constnames andExpr.projstructure names are covered: the kernel rewrites nested occurrences in the constructor to the auxiliary type, so a projection can reach that type without the declaration naming it as a constant.