Repository navigation
Description
Prerequisites
- Checked that this issue is not already filed.
- Reduced the issue to a self-contained test case without Mathlib or Batteries.
- Tested the reproducer against a release build of current
master(11636539d4150daeabe43cbc5cc5826b06f1e3ce).
Description
The default leanchecker path treats every ConstantInfo.quotInfo as a request to add the fixed canonical Declaration.quotDecl. It does not require the submitted entry to be one of Quot, Quot.mk, Quot.lift, or Quot.ind, and it does not compare the submitted metadata with the declaration generated by the kernel.
The reproducer serializes a noncanonical .quotInfo named evil with type False. leanchecker Evil exits successfully, while an ordinary import exposes evil : False and accepts theorem boom : False := evil. A differential control uses the same external name and type but encodes it as a theorem whose body is True.intro; the kernel correctly rejects that control. Changing only the metadata variant to .quotInfo therefore skips validation of the submitted declaration.
Context
On the .quotInfo branch, replay discards the entire QuotVal, replays Eq, and calls addDecl (Declaration.quotDecl). It then erases the submitted pending name. With Init already imported, adding the quotient package is effectively idempotent, so no declaration named evil is checked.
The --from-export path has a separate post-check for the four canonical quotient names, but the ordinary .olean path does not. leanchecker is documented as an environment-hacking detector rather than an external verifier. The bug here is that it reports success for a submitted declaration it never checks; ordinary .olean import trusts artifacts by design.
Steps to Reproduce
From a release build of the Lean repository, save the following as poc.sh and run bash poc.sh from the repository root:
#!/usr/bin/env bash
set -euo pipefail
ROOT="$PWD"
LEAN="$ROOT/build/release/stage1/bin/lean"
CHECKER="$ROOT/build/release/stage1/bin/leanchecker"
export PATH="$ROOT/build/release/stage1/bin:$PATH"
WORK="$(mktemp -d)"
trap 'rm -rf "$WORK"' EXIT
cd "$WORK"
cat > Generator.lean <<'LEAN'
import Lean
open Lean
def baseData (constant : ConstantInfo) : ModuleData := {
isModule := false
imports := #[{ module := `Init }]
constNames := #[`evil]
constants := #[constant]
extraConstNames := #[]
entries := #[]
}
def quotientConstant : ConstantInfo := .quotInfo {
name := `evil
levelParams := []
type := .const ``False []
kind := .type
}
def invalidTheoremConstant : ConstantInfo := .thmInfo {
name := `evil
levelParams := []
type := .const ``False []
value := .const ``True.intro []
all := [`evil]
}
def main : IO Unit := do
saveModuleData "Evil.olean" `Evil (baseData quotientConstant)
saveModuleData "Control.olean" `Control (baseData invalidTheoremConstant)
LEAN
LEAN_PATH="$WORK" "$LEAN" --run Generator.lean
echo 'noncanonical quotient entry:'
LEAN_PATH="$WORK" "$CHECKER" -v Evil
echo "exit: $?"
echo 'invalid theorem control:'
set +e
LEAN_PATH="$WORK" "$CHECKER" -v Control
CONTROL_STATUS=$?
set -e
echo "exit: $CONTROL_STATUS"
test "$CONTROL_STATUS" -ne 0
cat > Consumer.lean <<'LEAN'
import Evil
#check evil
theorem boom : False := evil
#check boom
LEAN
LEAN_PATH="$WORK" "$LEAN" Consumer.leanExpected behavior: leanchecker rejects the noncanonical quotient entry because no canonical quotient declaration named evil exists and the submitted QuotVal does not match any declaration generated by Declaration.quotDecl.
Actual behavior: The quotient-tagged artifact exits 0 and the consumer compiles, while the invalid-theorem control is rejected:
noncanonical quotient entry:
replaying Evil
exit: 0
invalid theorem control:
leanchecker found a problem in Control
uncaught exception: while replaying declaration 'evil':
(kernel) declaration type mismatch, 'evil' has type
True
but it is expected to have type
False
replaying Control
exit: 1
evil : False
boom : False
Versions
Lean (version 4.34.0-pre, arm64-apple-darwin25.6.0, commit 11636539d4150daeabe43cbc5cc5826b06f1e3ce, Release)
macOS 26.6.2 (build 25G83)
Additional Information
Relevant code on the tested commit:
replayFromImportsbuilds the submitted replay map.- The
.quotInfobranch discards the submitted metadata and addsDeclaration.quotDecl. Kernel.Environment.replaytreats every safe, non-partial map entry as completed after that branch returns.- The kernel's quotient initializer returns immediately when quotients are already present.
- Export mode already performs a canonical quotient post-check.
Separately, leanchecker -v --fresh Evil also exited 0 on this build.
The .quotInfo branch could require both the replay-map key and QuotVal.name to be one of the four canonical quotient names, then compare the complete submitted value with the corresponding kernel-generated ConstantInfo before clearing the pending entry. Sharing that validation with export mode would keep both paths consistent.
Impact
leanchecker returns success for a same-version artifact containing a noncanonical quotient-tagged declaration it never checks. The artifact remains usable after ordinary import and exposes an unchecked proof of False, so the checker misses the environment-hacking pattern it is intended to detect.
Activity
mufeedvh commentedon Sep 9, 2026
Closing after additional validation: the supported untrusted-code path (lake check/lake challenge) exports via NDJSON and runs leanchecker --from-export. This construction is rejected there with unknown constant and exit 1. The remaining behavior is limited to direct .olean replay, outside that security boundary, so I do not think it warrants further maintainer attention in the scope I intended to report.
fix: reject replay map entries stored under a different name (leanpro…