Manuscript Offprint

arXiv:2611.01357

ProofPatch: Reviewing Lean Statements and Keeping the Reviews Valid as Formalizations Evolve

Xujun Che, Depeng Xu, Jian Xiang, Taufiqua Khan

Xujun Che, Depeng Xu, Jian Xiang, and Taufiqua Khan

University of North Carolina at Charlotte, Charlotte, NC, USA {xche,dxu7,jxiang1,tkhan13}@charlotte.edu

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.

Keywords: Lean · specification validation · proof review · change impact analysis · autoformalization

1 Introduction

A machine-checked proof is only as good as its statement. The kernel of the Lean proof assistant [26], its small trusted proof checker, guarantees that a proof establishes the statement it is given, but not that the statement is the theorem anyone meant. Checking that is the long-standing problem of validating a specification [30,38], and in practice it falls to people who read the formal statement next to its informal counterpart. Tools help them: counterexample generators in Isabelle [3,5] and Coq [28] refute wrong conjectures before anyone tries a proof, and vacuity detection [2,20] catches properties that hold for a trivial reason.

X. Che et al.

Two developments make this review harder. The first is volume. Large language models (LLMs) now prove competition problems in Lean [31] and translate informal statements into Lean at scale [36], and compiling is a weak sign of being right: on 227 graduate-level statements, a tool-augmented GPT-5.2 agent compiles 87.2% but is faithful on only 57.7% [40]. The second is durability. Formal developments change constantly, increasingly through agents, and a review decision goes stale without notice when something it relied on changes. A theorem can keep every character of its statement while a definition it uses is rewritten. A line diff then shows nothing on the theorem, and continuous integration re-checks the proofs but not the review.

We present ProofPatch, a tool for reviewing Lean statements and keeping the outcome of that review valid as the development evolves. Its central design choice is to work on elaborated terms rather than on source text. An elaborated term is the statement as the kernel sees it, after Lean has expanded notation, inserted implicit arguments and coercions, and resolved type-class instances. Two commits to Mathlib, Lean's community library of mathematics [35], show why this matters. One rewrote statements such as ContMDiffWithinAt I I' n f s x into a new notation, CMDiffAt[s] n f x. The text changed, but the elaborated statement stayed the same up to definitional equality, the equality the kernel itself checks by unfolding definitions and computing, so a review of the old statement still applies. Another replaced open Classical in by open scoped Classical in above a definition. The definition's text stayed the same, but its elaborated body now uses a different decidability instance, the term that decides the condition of an if-then-else. Reviews of the 26 theorems whose statements use the definition relied on the old body, yet a line diff shows nothing on any of them.

On this choice ProofPatch builds the review loop of Figure 1. A reviewer can challenge a statement: modify it in a small, typed way, for instance by dropping a hypothesis, and let the kernel check the result, which yields evidence such as a counterexample or a proof that the hypothesis was never needed. The decision is recorded as a receipt, which stores fingerprints of the elaborated statement and of every definition it depends on, so that it can be re-checked mechanically after any change. A reviewer can also lock a declaration to pin it. A gate runs on every patch, written by a person or by an LLM agent, and reports which receipts no longer apply and which locks are violated. Two versions of a declaration count as the same when their elaborated terms coincide after a small canonicalization, or when the kernel confirms that they are definitionally equal. This notion is precise and checkable, and deliberately conservative: a change the kernel cannot see through goes back to the reviewer.

ProofPatch applies to any Lean development. Machine-generated formalizations make it necessary by multiplying what there is to review and how often it changes. This paper makes four contributions:

  • a way to record review decisions against elaborated statements and their dependencies, with precise guarantees about what a kept receipt implies;

Figure

Fig. 1. One review in ProofPatch. The reviewer acts on the artifacts in the middle row. Every fact in them comes from the kernel and from elaborated terms, not from text or from a model.

  • kernel-based evidence for reviewers, obtained by counterexample search and mutation on elaborated statements, with the guarantee that the statement the kernel checks is the statement the reviewer sees;

  • a gate that applies these checks to every patch, in continuous integration, in the editor and inside an agent loop that feeds the gate's report back to the model, implemented for Lean 4 and Mathlib;

  • an evaluation on 229 pairs of Mathlib revisions against text-based baselines, on 1,527 labeled statements, and on 344 agent runs.

References (40)