Repository navigation
Description
Prerequisites
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest master/nightly build.
Description
Lean accepts a checked theorem declaration containing an oversized projection index. The projection index is a Nat, but the kernel paths convert it to C++ unsigned after checking only is_small(). This lets an invalid projection reduce as if it were a valid field projection.
The reproducer proves, without axioms:
{ first := 0, second := 1 }.4294967298 = 1The same file confirms that the raw natural-number equality 4294967297 = 1 is rejected, so the issue is specific to projection handling.
Context
This appears to affect multiple kernel paths, not just one projection function:
src/kernel/type_checker.cpp:221(infer_proj)src/kernel/type_checker.cpp:377(reduce_proj)src/kernel/type_checker.cpp:1008(lazy_delta_proj_reduction)
Each path checks is_small() and then calls get_small_value() into an unsigned.
Steps to Reproduce
- Save this file as
ProjectionOverflowFieldEquality.lean:
import Lean
open Lean
namespace ProjectionOverflowFieldEquality
def hugeIdx : Nat := 4294967297
structure PairBox where
first : Nat
second : Nat
run_elab
let boxValue :=
mkApp2 (mkConst ``PairBox.mk [])
(mkNatLit 0)
(mkNatLit 1)
let hugeProjection := mkProj ``PairBox hugeIdx boxValue
let eqType :=
mkApp3 (mkConst ``Eq [levelOne])
(mkConst ``Nat)
hugeProjection
(mkNatLit 1)
let eqProof :=
mkApp2 (mkConst ``Eq.refl [levelOne])
(mkConst ``Nat)
(mkNatLit 1)
let decl := Declaration.thmDecl {
name := `ProjectionOverflowFieldEquality.hugeProjection_eq_one
levelParams := []
type := eqType
value := eqProof
}
match (← getEnv).addDeclCore (doCheck := true) 0 decl none with
| .ok env => modifyEnv fun _ => env
| .error ex => throwError "{ex.toMessageData {}}"
run_elab
let natEqType :=
mkApp3 (mkConst ``Eq [levelZero])
(mkConst ``Nat)
(mkNatLit hugeIdx)
(mkNatLit 1)
let bogusProof :=
mkApp2 (mkConst ``Eq.refl [levelZero])
(mkConst ``Nat)
(mkNatLit 1)
let decl := Declaration.thmDecl {
name := `ProjectionOverflowFieldEquality.hugeIndex_eq_one
levelParams := []
type := natEqType
value := bogusProof
}
match (← getEnv).addDeclCore (doCheck := true) 0 decl none with
| .ok _ => throwError "unexpectedly accepted Nat index equality"
| .error _ => logInfo "checked Nat index equality rejected"
#check ProjectionOverflowFieldEquality.hugeProjection_eq_one
#print axioms ProjectionOverflowFieldEquality.hugeProjection_eq_one
end ProjectionOverflowFieldEquality- Run:
lean --trust=0 ProjectionOverflowFieldEquality.leanExpected behavior: The theorem declaration using .4294967298 should be rejected because the projection index is not a valid field index for PairBox.
Actual behavior: Lean accepts the theorem and reports no axioms:
checked Nat index equality rejected
ProjectionOverflowFieldEquality.hugeProjection_eq_one :
{ first := 0, second := 1 }.4294967298 = 1
'ProjectionOverflowFieldEquality.hugeProjection_eq_one' does not depend on any axioms
Versions
Lean (version 4.31.0-pre, arm64-apple-darwin25.3.0, commit ref: refs/heads/master, Release)
Tested commit:
659249a7df544a0507137f5869d44b23f1951f78
OS:
macOS arm64
Additional Information
Suggested fix: use one shared checked conversion for projection indices in all kernel projection paths. It should reject indices outside the C++ unsigned range and reject indices outside the actual field range before they are used by type inference, reduction, or defeq shortcuts.
Impact
This is a checked-kernel correctness issue: a theorem declaration is accepted even though its type contains an invalid projection index that should not be reducible as a valid field projection.
Activity
nomeata commentedon May 2, 2026
Duplicate of #12746, right?
proj_idxtruncation:size_t→unsigned#12746fix: stop truncating kernel counts and indices to 32 bits (leanprover…