# Trust checks *For authors who want CI to fail when a paper's claims and its Lean development disagree. [DESIGN.md](../DESIGN.md) §7.7 and §10.3 give the reasoning behind these checks.* `imprimatur check` reports five kinds of problem with the results a paper cites: | Code | Meaning | |---|---| | `untrusted` | the result depends on `sorry`, uses an axiom outside `allowed_axioms`, or has an untrusted constant in its dependency cone | | `claim` (warning) | an item marked `[claim]` depends on `sorry`: a statement whose proof is elsewhere, on purpose (below) | | `unchecked` | `[trust].checker` asks for a verified checker, and it did not accept the development (below) | | `broken-ref` | the key names no declaration | | `drift` | the statement changed since an author last checked the prose against it | | `sig-changed` (warning) | the statement reads differently (a binder renamed, notation changed), but means the same | ## The dependency cone **What the cone is.** A theorem's statement mentions definitions, which mention others. The cone is every constant reached this way, up to the trusted modules: those whose names start with an entry of `[trust].trusted_prefixes` (by default `Mathlib`, `Std`, `Batteries`, `Lean`, `Init`). **What a member of the cone may not be.** Each member is checked, and is untrusted if it: - is defined using `sorry`; - is an axiom (unless `allowed_axioms` lists it); - is `partial`; - is `unsafe`. **Why this matters.** Without the cone check, a hypothesis definition could be changed to `True`. The theorem would become trivial, while its statement read exactly as before. ## Claims: statements proved elsewhere A paper sometimes states a result whose proof is not in its development: a note that says what another project's Lean proves, from a file that restates its theorems over Mathlib with `sorry` for every proof. Mark such an item `[claim]`: ```latex \begin{leanclaim}[claim]{Riemann.riemannHypothesis}{The Riemann Hypothesis} \end{leanclaim} … must set that point aside \leancheck[claim]{Riemann.riemannHypothesis}. ``` `check` then reports the `sorry` as a warning, `claim`, instead of the error `untrusted`. Everything else is checked as for a proved result: the axioms, and the dependency cone, so a claim whose hypotheses rest on a sorried definition is still untrusted. The `provenance` view writes **sorry** in the axioms column of a claim, so the reader sees it too. `examples/riemann` is a note made of claims. ## A verified checker The checks above take Lean's word for what is proved. Lean v4.35 and later ship [con-leche](https://github.com/leanprover/con-leche), an external checker verified in Lean: a theorem says that whatever it accepts has a model in set theory, so a theorem it accepts is true in that model, not just accepted by a program. To have it check the development too: ```toml [trust] checker = "con-leche" ``` Then `imprimatur build` exports the modules in `imports` with `leanexport` and runs `con-leche` on the export, alongside the extractor, and writes the verdict into the bundle. `imprimatur check` reports `unchecked` unless the verdict is *accepted*: - con-leche **declines** a development that uses `sorry` anywhere (even in a declaration the paper never cites), an axiom beyond `propext`, `Classical.choice` and `Quot.sound`, or a feature it does not implement; the message names the declaration; - it **rejects** one with an invalid declaration, which Lean's kernel should never have let through. **What it costs.** About a minute for the export and the check together on a small development, more with each package it depends on, and around ten minutes of checking for all of Mathlib on a machine with many cores. The verdict is kept in `.imprimatur/checker.json` with a fingerprint of the development, so a run that changes only the paper reads it back in well under a second; only a rebuilt development is checked again. `--timing` shows the checker's time. **Switching it off.** `imprimatur build --no-checker` (and `check`, `show`) skips it for a run: the bundle carries no verdict, and `check` goes by Lean's verdict alone. Removing the `checker` line does the same for good. A development con-leche declines, say for a `sorry` in work in progress, is checked this way until the `sorry` is gone. ## Tying prose to Lean: `\leancheck` and `accept` When prose states a result in your own words, tie it to Lean: ```latex Every derivable judgement is sound \leancheck{MyPaper.Results.theorem1_main}. ``` After reading the prose against the Lean statement, record that you did: ```sh imprimatur accept MyPaper.Results.theorem1_main # or: imprimatur accept --all ``` This writes the current hashes into the paper: ```latex \leancheck[stmt=b41c0a9e77d2, sig=07ae13c4f0a1]{MyPaper.Results.theorem1_main} ``` A key can also be the title of a `latex_group` or `latex_display`: its statement is its members', and its hashes are theirs together. From then on, `imprimatur check` compares them with the current Lean: - **`stmt=` differs:** an error (`drift`). Something the statement means has changed: the statement itself, or a definition in its cone. Re-read the prose, then run `accept` again. - **Only `sig=` differs:** a warning. The statement is printed differently, but means the same. - **A proof changed:** neither hash changes. A `\leancheck` without `stmt=` is checked only for broken references and trust. **What a statement hash covers.** A `stmt=` hash covers: - the statement (for a definition, also its definition); - every definition in its cone: a recursive one by its equation lemmas, any other by its body; - binders, but not their names, and universes, but not their names. So it is the same on every supported Lean toolchain. With several keys, `stmt=` covers all of them together. ## Comparator manifests For a project audited with [comparator](https://github.com/leanprover/comparator), list its manifests: ```toml [manifests] comparator = ["lean/ComparatorChallenges/*.json"] ``` Each theorem in a manifest is checked, even if the paper doesn't mention it: - it must exist; - it must be trusted, using the manifest's `permitted_axioms` in place of `allowed_axioms`. The solution modules are imported automatically. A paper can quote the audited challenge statement as `KEY@challenge`, for example `\begin{leanblock}{OAI.X.main@challenge}{…}`. It is rendered from the challenge module, which is imported on its own, because it declares the same names as the solution. ## Blueprints With `[manifests] blueprint = true`, leanblueprint's `\lean{…}` and `\leanok` are read too: - every `\lean{…}` key must exist; - a node marked `\leanok` whose declarations aren't trusted is an error (`leanok-untrusted`); - a `\lean{…}` without `\leanok` is work in progress, so its `sorry` is not reported; - `strip` leaves blueprint markup alone. ## In CI Run `imprimatur check` in CI and before submitting. It exits non-zero on any error. Warnings (`sig-changed`, `orphan-slot`, `missing-input`) don't fail it.