ProofPatch: Reviewing Lean Statements and Keeping the Reviews Valid as Formalizations Evolve
Organizations: University of North Carolina at Charlotte, Charlotte, NC, USA
Abstract
The kernel of the Lean proof assistant checks that a proof establishes its statement. Whether the statement says what was intended is left to human reviewers. This is the old problem of validating a specification, and it grows more pressing as language models write formal statements in bulk and agents edit formal developments continuously. We present ProofPatch, a tool that helps reviewers judge Lean statements and keeps their judgments valid while the development changes. A reviewer can ask the kernel targeted questions about a statement, such as whether a hypothesis is needed or whether a counterexample exists. Each decision is stored with fingerprints of the statement as Lean elaborated it and of the definitions it depends on, and any declaration can be pinned so that a patch changing it is blocked, whether a person or an agent built on a large language model (LLM) wrote the patch. Working on elaborated terms rather than source text is the central design choice: notation and formatting changes leave a decision intact, and a changed definition reaches every theorem that uses it. On 229 pairs of consecutive revisions of Mathlib, Lean's mathematics library, ProofPatch sends 118 of 12,898 synthetic decisions back for review. Every text-based alternative misses at least 38 of these or sends back at least 13 times as many. On 1,527 labeled statements, kernel evidence flags unfaithful ones with precision 0.88 to 0.96, and in 344 runs of an LLM agent no change to a pinned statement got through.
Figures & tables
| declaration, proof elided | receipts | lock | after patch |
|---|---|---|---|
| def clamp (lo hi x : ) : := | definition | ✗ lock fails | |
| max lo (min hi x) | |||
| theorem clamp_le_hi (lo hi x : ) (h : lo hi) : | ✓ alice | statement | re-review |
| clamp lo hi x hi | |||
| theorem lo_le_clamp (lo hi x : ) (h : lo hi) : | ✗ alice | re-review | |
| lo clamp lo hi x |
| Method | sent back | needless | missed |
| statement diff | 94 | 54 | 78 |
| file diff | 12,898 | 12,780 | 0 |
| text closure | 308 | 237 | 47 |
| text closure with context | 1,831 | 1,714 | 1 |
| text closure on the kernel’s graph | 290 | 210 | 38 |
| text closure with context on the kernel’s graph | 1,612 | 1,495 | 1 |
| Flagger | ProofNetVerif | graduate | synthetic | recall | acc. |
|---|---|---|---|---|---|
| strict evidence | 0.953 (43) | 1.000 (1) | 1.000 (3) | 0.049 | 0.424 |
| broad evidence | 0.928 (69) | 0.875 (8) | 0.500 (8) | 0.081 | 0.439 |
| LLM judge | 0.905 (799) | 0.513 (78) | 1.000 (29) | 0.872 | 0.845 |
| judge with strict veto | 0.903 (806) | 0.513 (78) | 1.000 (29) | 0.878 | 0.847 |
| single round / with feedback | |||||
|---|---|---|---|---|---|
| Tasks | accepted | declined | kernel error | caught | |
| repair, examples | 41 | 34 / 37 | 1 / 0 | 6 / 4 | 0 / 0 |
| repair, Mathlib | 31 | 4 / 7 | 0 / 6 | 27 / 18 | 0 / 0 |
| adversarial, default prompt | 50 | 5 / 6 | 41 / 37 | 4 / 2 | 0 / 5 |
| adversarial, second prompt | 50 | 6 / 6 | 9 / 16 | 31 / 24 | 4 / 4 |
Appendix figures & tables8 assets
Supplementary material from the paper’s appendix.
Appendix
| Patch | Reported effect | Locks | Receipts | Verdict |
|---|---|---|---|---|
| body of clamp becomes min hi (max lo x) | body changed, six closures changed | 5 of 6 | 1 of 7 | blocked |
| body of clamp becomes if lo min hi x then min hi x else lo | definitional rewrite | 6 of 6 | 7 of 7 | accepted |
| bound variables of clamp become a b y | no change | 6 of 6 | 7 of 7 | accepted |
| clamp_of_mem becomes clamp_eq_self | renamed | 6 of 6 | 7 of 7 | accepted |
| proof of score_le_hundred becomes sorry | sorryAx added | 6 of 6 | 7 of 7 | blocked |
| statement of score_le_hundred becomes score x 101 | statement changed | 5 of 6 | 6 of 7 | blocked |
| Operation | median | p90 | |
|---|---|---|---|
| interactive challenge: replay, provers, refutation | 21 | 0.40 s | 0.57 s |
| statement probe on a file that imports Mathlib | 5,839 | 0.33 s | 1.96 s |
| first elaboration of a Mathlib file, imports loaded once | 458 | 13.5 s | 43.3 s |
| reload after an edit to the last declaration | 1 | 0.10 s | |
| gate comparison, both revisions indexed | 229 | 10 ms | 34 ms |
| agent task, up to three rounds with the gate | 244 | 26.8 s | 116.8 s |
Formal Verification
Formal verification uses mathematical models and machine-checked proofs to establish whether software and systems satisfy precise specifications.
See all 354 papers