Free · Daily brief + weekly playbookDaily 60-sec AI Voice Brief + Weekly Production AI Agent PlaybookGet the brief →
AnalysisResearch Paper · For R&DarXiv cs.AI→ original

Lean Proofs for AI-Generated Code Break After Refactoring 13-27% of the Time

A group of researchers (preprint on arXiv) asked a simple question: if code is formally proven correct in Lean, and the program is then slightly rewritten — say, a chunk of logic is extracted into a separate function — does the old proof still hold? To test this, they took 185 problems from the VERINA benchmark and produced 458 "certified" code variants: each variant is still guaranteed to behave the same as the original, but written differently. It turned out that the proof survival rate (PSR, the share of proofs that remain valid after refactoring) for reference proofs hand-written by the VERINA authors breaks in just 4.3% of cases. For proofs generated by specialized AI models (DeepSeek-Prover and Goedel-Prover), the breakage rate is 13-27%. Yet on the same set of problems, AI-generated proofs actually survive refactoring more often than reference proofs — by 16-20 percentage points — simply because the reference sample is easier. And crucially: almost all breakages can be fixed with a single targeted edit — renaming an identifier.

AI-processed from arXiv cs.AI; edited by Hamidun News
Lean Proofs for AI-Generated Code Break After Refactoring 13-27% of the Time
Source: arXiv cs.AI. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourcearXiv cs.AI ↗
Editor-in-Chief
DeepSeek-Prover-V2-7Bproof survival exceeds the reference baseline by 15.6 points, Goedel-Prover-V2-32B by 18.8 points, Goedel-Prover-V2-8B by 20.3 points.
Key metric #2Of 54 eligible reference-proof breakages, 51 were fixed with a single edit; of 85 breakages in AI-model proofs, 58 were fixed.

When a language model writes code and immediately attaches a formal mathematical proof of its correctness in Lean, it looks bulletproof: the program is guaranteed to do what it's supposed to. But every existing test checks the proof against only one fixed version of the code. In real-world development, code gets rewritten constantly — duplicate logic gets pulled into a separate function, operations get reordered, conditions get inverted — while the program's behavior stays the same. The question is whether the old proof survives that kind of restructuring, even when the code's meaning hasn't changed.

The authors propose a methodology called RefactorProof to measure exactly this. They took 185 problems from the well-known VERINA benchmark (which checks both code and Lean proofs) and applied five kinds of mechanical, fully automated rewrites to each problem: extracting a piece of logic into a separate function, swapping operands in commutative operations, inverting conditions, and so on. For every such rewrite, Lean was used to separately prove that the program's behavior hadn't changed. This produced 458 verified code variants. Each variant was then paired with the original proof (byte-for-byte identical) to see whether Lean still accepted it.

What turned out to be fragile — and what didn't

The reference proofs that the VERINA authors wrote by hand for 46 problems survived refactoring almost unscathed — a breakage rate of just 4.3%. But that doesn't mean hand-written proofs are inherently more robust: all 46 of those problems are the simplest in the benchmark, with a median code length of one line, and only 6.5% of them are recursive.

Proofs generated by specialized theorem-proving models — DeepSeek-Prover-V2-7B and two versions of Goedel-Prover-V2 (8B and 32B) — broke much more often: failure rates ranged from 13.3% to 26.8%. But when comparing the models to the reference baseline on an identical, matched set of problems, the picture flips: model-generated proofs survive refactoring more often than reference proofs — by 15.6 points for DeepSeek-7B, 18.8 points for Goedel-32B, and 20.3 points for Goedel-8B. The difference is statistically significant in all three cases.

Why some proofs collapse and others hold

The researchers identified a specific mechanism behind this resilience. Reference proofs typically begin with the unfold command, which expands the function's definition directly in the text. Model-generated proofs more often start by explicitly asserting that a function call and its body are equal, using the rfl tactic (a so-called "definitional bridge"), and then prove the rest automatically.

When code gets moved into a separate function (logic extraction), that "bridge" turns out to be far more durable: at the task level, bridge-based proofs survive in 6 out of 6 cases, while other strategies only manage 6 out of 31. But this trick has a downside: if the rewrite substantively changes the function's body (rather than just its location), a bridge tied to the specific text of that body stops type-checking — such proofs survive only 0 out of 3 times, compared to 17 out of 19 for more general proofs not tied to a specific wording.

A break isn't a catastrophe

The main practical takeaway: a proof failing to check after refactoring doesn't necessarily mean an expensive rewrite. The researchers tested this directly: they took the broken proofs and tried to fix them with one simple, targeted edit — renaming a single identifier. Out of 54 eligible breakages in reference proofs, 51 were fixed this way; out of 85 breakages in model-generated proofs, 58 were fixed.

For teams relying on verifiable AI code generation, the conclusion is straightforward: the mere fact that a proof stops checking after refactoring is no reason to panic, nor is it evidence that a model is fundamentally worse at producing proofs. It's better read as a signal to build automatic checking and lightweight proof repair into the verification pipeline after any code change, rather than treating a single breakage as a final verdict on a model's quality.

Story

Key Questions Answered

What turned out to be fragile — and what didn't?

The reference proofs that the VERINA authors wrote by hand for 46 problems survived refactoring almost unscathed — a breakage rate of just 4.3%. But that doesn't mean hand-written proofs are inherently more robust: all 46 of those problems are the simplest in the benchmark, with a median code length of one line, and only 6.5% of them are recursive.

Why some proofs collapse and others hold?

The researchers identified a specific mechanism behind this resilience. Reference proofs typically begin with the unfold command, which expands the function's definition directly in the text. Model-generated proofs more often start by explicitly asserting that a function call and its body are equal, using the rfl tactic (a so-called "definitional bridge"), and then prove the rest automatically.

What are the key details on A break isn't a catastrophe?

The main practical takeaway: a proof failing to check after refactoring doesn't necessarily mean an expensive rewrite. The researchers tested this directly: they took the broken proofs and tried to fix them with one simple, targeted edit — renaming a single identifier. Out of 54 eligible breakages in reference proofs, 51 were fixed this way; out of 85 breakages in model-generated proofs, 58 were fixed.

ZK
Zhemal Khamidun — Head of AI at Alpina Digital · MIPT (academic supervisor of the Tech Entrepreneurship department). Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Unified AI Workspace · Nomad

Test Frontier LLMs & Autonomous Agents in One Workspace

Run Claude Opus 5.5, GPT-6, Gemini 3.1, and DeepSeek side-by-side in Nomad AI (nomadnet.ai) — unified model routing, deep research, and multimodal workflows under one subscription.

Try Nomad AI →Launch Nomad Agent
Jemal Hamidun

Editor-in-chief · Cite this analysis

Jemal Hamidun

Head of AI at Alpina Digital · Academic Supervisor of the Tech Entrepreneurship Department at MIPT

Head of AI & CPO of AlpinaGPT at Alpina Digital, Academic Lead of Tech Entrepreneurship at MIPT. Founder of Hamidun News and Vibe Academy.

Ready-to-paste citation for journalists, blogs and Telegram channels

Source: Hamidun News — Lean Proofs for AI-Generated Code Break After Refactoring 13-27% of the Time https://news.hamidun.com/en/news/14888/lean-proofs-for-ai-generated-code-break-after-refactoring-13

What do you think?
Loading comments…