Kernel aborts process with `INTERNAL PANIC: universe level depth is too big` (`lean_level_mk_data`)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 32/100
Direzione di ricerca
Start with src/kernel/level.cpp:42–50 and the uses of get_depth named in the issue; compare the suggested approaches with approxDepth in src/kernel/expr.cpp and get_count_arg in src/kernel/type_checker.cpp. Run the supplied ReproLevelDepthPanic.lean with lean --trust=0 to confirm the panic. Done means deep universe levels no longer terminate Lean, the LSP worker, or leanchecker unexpectedly, with the behavior covered by a regression check.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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 nightly release, for example on
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”) - When reporting a perceived soundness bug: Does it affect
lake check --paranoid?
If in doubt, please reach out on [email protected] for responsible disclosure.
Description
lean_level_mk_data in src/kernel/level.cpp:42–50 packs a universe level's depth into a 24-bit field (d <= 16777215) and calls lean_internal_panic("universe level depth is too big") whenever depth exceeds 16777215:
extern "C" LEAN_EXPORT uint64_t lean_level_mk_data (uint64_t h, object * depth, uint8_t hasMVar, uint8_t hasParam) {
if (!is_scalar(depth))
lean_internal_panic("universe level depth is too big");
size_t d = unbox(depth);
if (d > 16777215)
lean_internal_panic("universe level depth is too big");
...
}
Because lean_internal_panic immediately terminates the process (std::exit(1) by default, or abort() / SIGABRT with LEAN_ABORT_ON_PANIC=1) rather than raising a catchable kernel exception, a 38-line pure safe, well-typed Lean file (no unsafe, no sorry, no @[extern]) defining a chain of universe-polymorphic definitions d_{i+1}.{u} : Prop := d_i.{succ^4096 u} accumulates level depth $4097 \times 4096 + 1 = 16{,}781{,}313 > 2^{24} - 1$ during whnf and crashes lean --trust=0, the Lean LSP server worker, leanchecker --from-export, and leanchecker-paranoid --from-export.
Context
Discovered while auditing bit-field invariants in src/kernel/level.cpp and src/kernel/expr.cpp against independent kernel implementations. When the same valid environment is exported to lean4export NDJSON, nanoda_bin checks and accepts all declarations cleanly, whereas leanchecker and leanchecker-paranoid terminate with INTERNAL PANIC: universe level depth is too big.
Steps to Reproduce
- Save the following self-contained file as
ReproLevelDepthPanic.lean(or paste intohttps://live.lean-lang.org/#project=lean-nightly):
import Lean
open Lean
run_meta do
let u := Level.param `u
let mut L := u
for _ in [:4096] do
L := Level.succ L
let Lsucc := Level.succ L
let prop := Expr.sort .zero
let polyIdTy := Expr.forallE `P prop (Expr.forallE `p (.bvar 0) (.bvar 1) .default) .default
let polyIdVal := Expr.lam `P prop (Expr.lam `p (.bvar 0) (.bvar 0) .default) .default
let d0Val := Expr.app (Expr.lam `x (.sort Lsucc) polyIdTy .default) (.sort L)
addDecl (.defnDecl {
name := `d_0, levelParams := [`u], type := prop, value := d0Val,
hints := .regular 1, safety := .safe
})
for i in [1:4097] do
let prev := Name.mkSimple s!"d_{i - 1}"
let cur := Name.mkSimple s!"d_{i}"
addDecl (.defnDecl {
name := cur, levelParams := [`u], type := prop, value := Expr.const prev [L],
hints := .regular (i + 1).toUInt32, safety := .safe
})
addDecl (.thmDecl {
name := `levelDepthPanicTrigger, levelParams := [],
type := Expr.const `d_4096 [.zero], value := polyIdVal
})
- Run
lean --trust=0 ReproLevelDepthPanic.lean(orLEAN_ABORT_ON_PANIC=1 lean --trust=0 ReproLevelDepthPanic.lean).
Expected behavior: Either universe levels of arbitrary depth are supported (e.g. saturating the cached depth field or falling back when d >= 2^24 - 1), or exceeding the maximum supported universe level depth raises a structured, catchable kernel exception instead of terminating the lean / LSP / leanchecker process via lean_internal_panic.
Actual behavior: The kernel prints INTERNAL PANIC: universe level depth is too big to stderr and immediately terminates the process (exit 1, or SIGABRT / exit 134 under LEAN_ABORT_ON_PANIC=1).
Versions
Lean (version 4.38.0-nightly-2026-11-26, x86_64-unknown-linux-gnu, commit e1228b8b45918ece1a00d68e5fc5e6a685ca59ee, Release)
Lean (version 4.36.0, x86_64-unknown-linux-gnu, commit 611c117bfaf7b7ae1cfcf246ce6fba31e8f509e9, Release)
Ubuntu 24.04.4 LTS (Linux 6.17.0-1022-azure x86_64)
Additional Information
Because lean_level_mk_data is an extern "C" primitive invoked directly by pure Lean.Level constructors (src/Lean/Level.lean), throwing a C++ exception directly inside lean_level_mk_data is unsafe across Lean FFI frames. We suggest two possible fix directions:
- Saturate the cached
depthfield (analogous toapproxDepthinlean_expr_mk_data): Clampdepthat the sentinel0xFFFFFF(note also that bits34..39ofLevel.Dataare currently unused). Across the codebase,get_depth(level)is only used insrc/kernel/level.cppin four places:operator==(fast inequality filter, falling back to structural comparison on ties),is_lt(strict weak ordering key, falling back tokind/hash/children on ties), andmk_max/printon explicit levels (which can fall back to countingsuccs only whenget_depth(l) == 0xFFFFFF). - Pre-check in the C++ kernel and raise
kernel_exception(analogous toget_count_arginsrc/kernel/type_checker.cpp): Keeplean_internal_panicinlean_level_mk_dataas a last-resort safety net, and checkget_depthbefore constructing deeper levels in C++ kernel entry points (instantiateon universe parameters,mk_succ,mk_max,mk_imax), throwing a catchablekernel_exceptioninstead of terminating the process.
- Lingua principale
- Lean
- Stelle
- 10.5k
- Fork
- 1.2k
- Merge medio
- 19h 36m
- PR unite (30g)
- 323
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di leanprover/lean4
-
P-medium
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
leanprover/lean4#16958 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
leanprover/lean4#16897 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
leanprover/lean4#16892 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 86/100
leanprover/lean4#16886 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
leanprover/lean4#16820 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di leanprover/lean4
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
ranxianglei/billion-context#8319 ·
I maintainer di solito rispondono entro 1 giorno
-
backend bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
nolte/kamerplanter#3193 ·
I maintainer di solito rispondono entro 1 giorno
-
bug documentation queries
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
ClickHouse/clickhouse-cs#815 ·
I maintainer di solito rispondono entro 1 giorno
-
CF_CFDP_S_SendFileData computes the file checksum from the SB buffer after CFE_SB_TransmitBufferAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno