https://github.com/leanprover/lean4checker
Replay the `Environment` for a given Lean module, ensuring that all declarations are accepted by the kernel.
https://github.com/leanprover/lean4checker
Last synced: 3 months ago
JSON representation
Replay the `Environment` for a given Lean module, ensuring that all declarations are accepted by the kernel.
- Host: GitHub
- URL: https://github.com/leanprover/lean4checker
- Owner: leanprover
- License: apache-2.0
- Created: 2023-09-25T05:42:19.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-06-30T00:41:06.000Z (11 months ago)
- Last Synced: 2025-06-30T01:30:51.950Z (11 months ago)
- Language: Lean
- Size: 106 KB
- Stars: 25
- Watchers: 10
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Recheck a compiled Lean `olean` file using the Lean kernel.
`lake exe lean4checker ` will replay the environment in ``,
starting from the environment provided by its imports,
ensuring that the kernel accepts all declarations.
`lake exe lean4checker` without an argument will run `lean4checker` in parallel on every `.olean`
file on the search path (note that this include Lean 4 and all dependencies of your project).
You can also use `lake exe lean4checker --fresh Mathlib.Data.Nat.Basic` to replay all the constants
(both imported and defined in that file) into a fresh environment.
This is single threaded, and may be much slower.
This is not an external verifier, as it uses the Lean kernel itself.
However it is useful as a tool to detect "environment hacking",
i.e. using metaprogramming facilities to build an inconsistent Lean `Environment`.
## Usage
To run this in another Lean project, use:
```
lake env path/to/lean4checker
```
or
```
lake env path/to/lean4checker Mathlib.Data.Nat.Basic
```
to check a single file.
## Caveats
Despite `.olean` files being "fairly cross-platform",
`lean4checker` will reject `.olean`s that were compiled on a system
that does not use the same bignum library as your system,
so it advisable to not rely on cached `.olean`s.
## Testing
Run `lake test` to run the test suite. This checks that `lean4checker` accepts its own codebase
and correctly rejects test cases with known problems.
To add a new test case:
1. Create a `.lean` file in `Lean4CheckerTests/` that produces an invalid environment
2. Create a matching `.expected.out` file with the expected error output
3. For tests requiring `--fresh` mode, use `.fresh.expected.out` instead