Skip to content

fix: kernel to check opaque values for fvars#14498

Merged
nomeata merged 1 commit into
masterfrom
joachim/14484
Jul 22, 2026
Merged

fix: kernel to check opaque values for fvars#14498
nomeata merged 1 commit into
masterfrom
joachim/14484

Conversation

@nomeata

@nomeata nomeata commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

This PR fixes a kernel unsoundness: just as for definitions and theorems, an opaque declaration's value must not contain fvars.

This was discovered by Patrick Hulin with the help of GPT-5.6 Sol.

The impact of this bug is that a malicious metaprogram can prove False, by first seeding the kernel's type checker cache for a free variable, and then refering to that free variable from the body of an opaque. See #14484 for an example.

Because the export format used by comparator cannot even express an fvar, the “gold standard for validating proofs” is – luckily – not affected. And even if it were, users who use comparator with nanoda as a second independent checker would be safe, as the bug does not exist in nanoda.

This bug can only be exploited by meta programs running in the same process. Such malicious meta programs can do nefarious things; this is known and unavoidable. So while we have a genuine kernel unsoundness at hand, it does not lead to new attack vectors in practice.

Fixes #14484

This PR fixes a kernel unsoundness: just as for definitions and
theorems, an `opaque` declaration's value must not contain fvars.

This was discovered by Patrick Hulin with the help of GPT-5.6 Sol.

The impact of this bug is that a malicious metaprogram can prove
`False`, by first seeding the kernel's type checker cache for a free
variable, and then refering to that free variable from the body of an
`opaque`. See #14484 for an example.

Because the export format used by comparator [cannot even express an
fvar](https://github.com/leanprover/lean4export/blob/af5aa64bb914c3c2c781f378088dbd38acf4f804/Export.lean#L160),
the “[gold standard for validating
proofs](https://lean-lang.org/doc/reference/latest/ValidatingProofs/#validating-comparator)”
is – luckily – not affected. And even it were, users who use comparator
with multiple checkers would be safe.

This bug can only be exploited by meta programs running in the same
process. Such malicious meta programs can do nefarious things; this is
known and unavoidable. So while we have a genuine kernel soundness at
hand, it does not lead to new attack vectors in practice.

Fixes #14484
@nomeata
nomeata requested a review from leodemoura as a code owner July 22, 2026 13:48
@nomeata nomeata added the changelog-language Language features and metaprograms label Jul 22, 2026
@nomeata
nomeata enabled auto-merge July 22, 2026 14:03
@nomeata
nomeata added this pull request to the merge queue Jul 22, 2026
@nomeata
nomeata removed this pull request from the merge queue due to a manual request Jul 22, 2026
@nomeata
nomeata added this pull request to the merge queue Jul 22, 2026
@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Jul 22, 2026
@leanprover-bot

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-07-21 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-07-22 14:14:38)

@github-actions github-actions Bot added the mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN label Jul 22, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Jul 22, 2026
@mathlib-lean-pr-testing

Copy link
Copy Markdown

Mathlib CI status (docs):

Merged via the queue into master with commit 7346219 Jul 22, 2026
56 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

The backport to releases/v4.32.0 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-releases/v4.32.0 releases/v4.32.0
# Navigate to the new working tree
cd .worktrees/backport-releases/v4.32.0
# Create a new branch
git switch --create backport-14498-to-releases/v4.32.0
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 7346219967957ca3dd4302a75a849b67eed1b3cd
# Push it to GitHub
git push --set-upstream origin backport-14498-to-releases/v4.32.0
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-releases/v4.32.0

Then, create a pull request where the base branch is releases/v4.32.0 and the compare/head branch is backport-14498-to-releases/v4.32.0.

Garmelon pushed a commit that referenced this pull request Jul 22, 2026
This PR fixes a kernel unsoundness: just as for definitions and
theorems, an `opaque` declaration's value must not contain fvars.

This was discovered by Patrick Hulin with the help of GPT-5.6 Sol.

The impact of this bug is that a malicious metaprogram can prove
`False`, by first seeding the kernel's type checker cache for a free
variable, and then refering to that free variable from the body of an
`opaque`. See #14484 for an example.

Because the export format used by comparator [cannot even express an
fvar](https://github.com/leanprover/lean4export/blob/af5aa64bb914c3c2c781f378088dbd38acf4f804/Export.lean#L160),
the “[gold standard for validating
proofs](https://lean-lang.org/doc/reference/latest/ValidatingProofs/#validating-comparator)”
is – luckily – not affected. And even if it were, users who use
comparator with nanoda as a second independent checker would be safe, as
[the bug does not exist in
nanoda](https://github.com/ammkrn/nanoda_lib/blob/f58f2f6d535e189a40fcb02ede8eb95f97a92d37/src/tc.rs#L169).

This bug can only be exploited by meta programs running in the same
process. Such malicious meta programs can do nefarious things; this is
known and unavoidable. So while we have a genuine kernel unsoundness at
hand, it does not lead to new attack vectors in practice.

Fixes #14484
Garmelon pushed a commit that referenced this pull request Jul 22, 2026
This PR fixes a kernel unsoundness: just as for definitions and
theorems, an `opaque` declaration's value must not contain fvars.

This was discovered by Patrick Hulin with the help of GPT-5.6 Sol.

The impact of this bug is that a malicious metaprogram can prove
`False`, by first seeding the kernel's type checker cache for a free
variable, and then refering to that free variable from the body of an
`opaque`. See #14484 for an example.

Because the export format used by comparator [cannot even express an
fvar](https://github.com/leanprover/lean4export/blob/af5aa64bb914c3c2c781f378088dbd38acf4f804/Export.lean#L160),
the “[gold standard for validating
proofs](https://lean-lang.org/doc/reference/latest/ValidatingProofs/#validating-comparator)”
is – luckily – not affected. And even if it were, users who use
comparator with nanoda as a second independent checker would be safe, as
[the bug does not exist in
nanoda](https://github.com/ammkrn/nanoda_lib/blob/f58f2f6d535e189a40fcb02ede8eb95f97a92d37/src/tc.rs#L169).

This bug can only be exploited by meta programs running in the same
process. Such malicious meta programs can do nefarious things; this is
known and unavoidable. So while we have a genuine kernel unsoundness at
hand, it does not lead to new attack vectors in practice.

Fixes #14484
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport releases/v4.32.0 backport releases/v4.33.0 builds-mathlib CI has verified that Mathlib builds against this PR changelog-language Language features and metaprograms mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing check apparently allows proof of False after adversarial metaprogram

3 participants