Skip to content

leanchecker: replay map does not check constNames[i] against constants[i].name (recursor entry stored under a different key), recursor analogue of #15100 #16675

Closed

Description

@babykalki

Prerequisites

I reported this privately to the Lean FRO first. They suggested filing it here as a description of the behaviour.

Description

ModuleData documents the invariant constNames = constants.map (·.name). The default (non---fresh) leanchecker path builds its replay map from these two parallel arrays (replayFromImports in src/LeanChecker.lean). It does not check that constNames[i] == constants[i].name.

For a .recInfo entry, Replay.lean fetches the entry by its map key. Recursor checking, however, is postponed under the embedded RecursorVal.name, and checkPostponedRecursors re-checks the entry under that embedded name. So if an .olean stores an edited RecursorVal under a map key that differs from its embedded name, that entry is never compared with a kernel-generated declaration.

Concretely, start from an inductive T and append one entry to its .olean. The entry's constNames key is renamed, but its ConstantInfo is still the RecursorVal named T.rec, with the type changed to False. Then:

  • leanchecker Edited exits 0.
  • leanchecker Cons exits 0. Cons imports Edited and declares theorem t : False := @renamed.
  • leanchecker --fresh Cons exits 1 with unknown constant 'renamed'.

This matches the constructor case in #15100, with recInfo in place of ctorInfo.

Context

leanchecker is documented as a detector for environment tampering, not an external verifier, and ordinary .olean import trusts artifacts by design. The gap is the one #15100 describes. The replay map is keyed by constNames, but constructor and recursor entries are postponed and re-checked under their embedded names. An entry stored under a non-matching key therefore skips that comparison. #15100 showed this for ctorInfo and #15101 for quotInfo. recInfo behaves the same way.

Steps to Reproduce

In a fresh empty directory, with lean and leanchecker from a v4.33.1 toolchain on PATH (no network needed):

cat > Seed.lean <<'LEAN'
inductive T where
  | mk
LEAN

cat > Gen.lean <<'LEAN'
import Lean
open Lean
-- Read Seed.olean, append one entry: constNames key `renamed`, but the ConstantInfo
-- is still the RecursorVal named `T.rec`, retyped to `False`. Key != embedded name.
def main : IO Unit := do
  let (data, _region) ← readModuleData "Seed.olean"
  let some ri := data.constants.find? (fun ci => ci.name == `T.rec)
    | throw <| IO.userError "no T.rec"
  let .recInfo rv := ri | throw <| IO.userError "T.rec not a rec"
  let edited : ConstantInfo := .recInfo
    { rv with name := `T.rec, levelParams := [], type := .const ``False [], isUnsafe := false }
  saveModuleData "Edited.olean" `Edited
    { data with constNames := data.constNames.push `renamed, constants := data.constants.push edited }
  IO.println "GEN_DONE"
LEAN

cat > Cons.lean <<'LEAN'
import Edited
theorem t : False := @renamed
LEAN

export LEAN_PATH=$PWD
lean Seed.lean -o Seed.olean          # exit 0
lean --run Gen.lean                   # writes Edited.olean, prints GEN_DONE, exit 0
lean Cons.lean -o Cons.olean          # exit 0 (import trusts the artifact)
leanchecker -v Edited                 # (1)
leanchecker -v Cons                   # (2)
leanchecker -v --fresh Edited         # (3)
leanchecker -v --fresh Cons           # (4)

Expected behavior

leanchecker rejects Edited. The appended entry's map key renamed does not match its embedded name T.rec, and no kernel-generated declaration named renamed exists. A replay-map key should identify the same declaration as the entry's ConstantInfo.name.

Actual behavior

Steps (1)–(3) exit 0. Only --fresh on the consuming module reports the entry. Measured output, with exit codes:

# (1) leanchecker -v Edited
replaying Edited
# exit 0

# (2) leanchecker -v Cons
replaying Cons
# exit 0

# (3) leanchecker -v --fresh Edited
replaying Edited with --fresh
# exit 0   (nothing in Edited itself refers to `renamed`)

# (4) leanchecker -v --fresh Cons
replaying Cons with --fresh
uncaught exception: while replaying declaration 't':
(kernel) unknown constant 'renamed'
# exit 1

Versions

Lean (version 4.33.1, x86_64-unknown-linux-gnu, commit 819816b2e0a3bf405af45ae5c7af2491d8f5bee6, Release)

Also reproduced on 4.35.0 (eb6cafb7), on Linux x86_64. The relevant lines of src/Lean/Replay.lean and src/LeanChecker.lean are unchanged on master as of 2026-11-22.

Additional Information

  • leanchecker --fresh reports the entry when run on the consuming module: (kernel) unknown constant 'renamed', exit 1 (step 4). On Edited alone it passes, because nothing in Edited refers to renamed.
  • import Edited compiles theorem t : False := @renamed with exit 0. Ordinary import trusts artifacts by design, and leanchecker accepts constructor entries whose map key differs from the embedded name #15100 describes the same downstream behaviour for its constructor case.
  • Export path, measured on exactly these files. lean4export Cons t (exit 0) writes no declaration record for renamed: the name appears only as a reference in the value of t. Every checker run on the export reports renamed as unknown:
    • leanchecker --from-export exits 1 with (kernel) unknown constant 'renamed'. This is the 4.35.0 binary, plain and paranoid build.
    • nanoda exits 101: declaration t depends on renamed which was not found.
    • con-ron on the export exits 1: rejected: unknown constant [at theorem t].
    • con-ron's direct .olean reader (--olean) refuses Edited.olean itself with exit 3: the name table (constNames) does not list its constants' names.

One possible approach (optional): when building the replay map, require constNames[i] == constants[i].name with no duplicates, before any dependency traversal. This would cover #15100, #15101 and this variant. Checking the same constNames = constants.map (·.name) invariant while loading ModuleData would add a second layer.

Impact

Writing such an entry requires editing an .olean file. Ordinary import and leanchecker --fresh on the consuming module behave as described above, and export-based checking reports the entry (measured above). Filing for tracking, in line with #15100 and #15101.

Activity

  1. nomeata commented on Nov 22, 2026

    @nomeata
    Collaborator

    Thanks, not severe but worth fixing id say.

  2. added
    P-medium
    on Nov 22, 2026
  3. added a commit that references this issue on Nov 22, 2026
    4e48c96
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P-medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions