CLEVER: A Curated Benchmark for Formally Verified Code Generation

Amitayush Thakur, Jasper Lee, George Tsoukalas, Meghana Sistla, Matthew Zhao, Stefan Zetzsche, Greg Durrett, Yisong Yue, Swarat Chaudhuri

TL;DR

CLEVER is a new, rigorous benchmark of 161 programming problems designed to evaluate whether AI can generate code that is formally and completely verified using the Lean 4 theorem prover. By utilizing non-computable logical specifications, CLEVER prevents language models from "cheating" via syntactic copying or passing weak test suites. The results are a stark reality check: even the most advanced state-of-the-art LLMs and agentic frameworks fail to solve more than a single problem end-to-end, establishing formal code verification as a challenging new frontier for AI.

What Problem Does This Paper Address?

While large language models (LLMs) excel at writing code, ensuring that code is actually correct remains a massive challenge. Traditional code generation benchmarks rely on test cases, which offer incomplete coverage and can miss subtle edge cases. To achieve absolute certainty, researchers turn to formal verification—using interactive theorem provers like Lean to mathematically prove that a program matches its specification.

However, existing benchmarks for verified code generation suffer from a major flaw: their formal specifications are often "leaky" or incomplete. They frequently use computable specifications (executable code blocks), which allow an LLM to simply copy the specification logic directly into the implementation or generate trivial solutions that satisfy weak constraints. CLEVER addresses this gap by providing a curated, high-quality benchmark where specifications are strictly non-computable logical propositions, forcing models to truly reason about program semantics rather than exploit syntactic loopholes.

Methods

CLEVER introduces a rigorous, two-stage evaluation pipeline to independently diagnose where models succeed or fail:

  1. Specification Certification (Task 1): Given a natural language prompt, the model must generate a formal Lean specification ($\psi$) and provide an isomorphism proof showing it is semantically equivalent to a hidden, human-written ground-truth specification ($\psi^*$).
  2. Implementation Certification (Task 2): Independent of the first task, the model must generate a Lean implementation ($\pi$) and formally prove its correctness against the ground-truth specification ($\psi^*$).
Figure 1: The two tasks of the CLEVER benchmark pipeline. Task 1 requires first generating a specification ψ from the natural language statement ν, then proving an isomorphism between the generated specification and a human-written specification ψ∗. Task 2 requires first generating a Lean implementation π, then proving its correctness according to the human-written specification. Both of these tasks must be completed correctly (reaching both QED 1 and QED 2) in order for a success to be counted.

All outputs are verified post-hoc using Lean’s strict type checker. The authors evaluated several frontier LLMs (GPT-4o, o4-mini, Claude-3.7, and DeepSeek-R1) using two distinct approaches: a standard Few-Shot Baseline (prompting the models to generate code and proofs directly) and the COPRA Baseline (a neuro-symbolic agentic state-of-the-art proof search framework).

Datasets

The benchmark consists of CLEVER, which adapts 161 out of 164 programming problems from the popular OpenAI HUMANEVAL dataset into Lean 4. The remaining three problems were excluded due to Lean's static typing limitations against Python's dynamic polymorphism.

Additionally, the authors released a small, hand-curated few-shot prompt dataset containing 5 distinct problems complete with human-written implementations and complex correctness proofs (some spanning over 300 lines) to help researchers tune prompts and in-context learning setups.

Key Insights and Ideas

  • Non-Computable Specs as Guardrails: By defining specifications using abstract logical connectives and quantifiers (Prop in Lean) that cannot be directly executed, the benchmark ensures that models cannot simply copy-paste logic. They must engage in symbolic reasoning to bridge the gap between the implementation's control flow and the specification's abstract logic.
  • The "Joint Success" Bottleneck: A fascinating finding was the stark mismatch between specification and implementation difficulty. Tasks where it was easy for a model to certify the specification often featured incredibly difficult implementation proofs, and vice versa. Because end-to-end success requires passing both stages, the joint probability of success drops to near zero.
  • Program Proofs are Structurally Rich: Unlike pure mathematics benchmarks (like miniF2F) where proofs are often short and highly amenable to automated tactic chaining (like linarith or simp), software verification proofs must mirror the branching, loops, and recursive structures of actual code. This requires case-by-case reasoning that completely breaks standard automation tactics.

Key Results

The evaluation yielded a clear conclusion: end-to-end verified program synthesis is incredibly difficult for current AI.

Figure 6: Aggregated compile@k and prove@k results across k attempts, diagnosing failure modes for specification and implementation generation. Dotted lines indicate extrapolation of the pass rate beyond the 600s timeout. (a) Specification Compilation: Most models achieve high compile@k rates, with Claude-3.7 and o4-mini reaching >80%. (b) Specification Certification: Proving specification equivalence is a major bottleneck. All few-shot models solve only one problem (0.62%), while GPT-4o (CoPRA) proves 1.8%. (c) Implementation Compilation: o4-mini has the highest compilation rate at >80%, while other models cluster between 60-70%. (d) Implementation Certification: Claude-3.7 (CoPRA) performs best, certifying 8.7% of implementations, followed by DeepSeek-R1 (Few-shot) at 5.6%. These plots show that while models are fluent at generating compilable artifacts, formal certification remains the key challenge, with all prove@k rates below 10%.
  • High Fluency, Low Logic: Models achieved impressive compilation rates—with o4-mini and Claude-3.7 successfully generating syntactically valid, compilable Lean specifications and implementations over 80% of the time. However, their ability to generate valid proofs was dismal, with certification success rates universally dropping below 10%.
  • End-to-End Failure: Across all tested frontier models and agentic setups, no approach succeeded on more than one single problem (specifically Problem 53, a simple integer addition task) out of the 161 available.
  • Agentic Superiority in Proofs: When paired with the COPRA proof-search agent, Claude-3.7 achieved the highest implementation certification rate (8.696%), proving 14 implementations correctly, showing that specialized symbolic search agents significantly outperform raw LLM generation.

Limitations and Future Work

The authors noted several core challenges encountered during formalization:

  • Language Limitations: Lean 4’s strict static typing makes it difficult to faithfully represent dynamic Python behaviors like Any types or string-based eval functions without creating massive, complex inductive definitions.
  • Mathematical Roadblocks: Certain everyday programming tasks conceal deep mathematical complexities. For instance, creating a verified "prime Fibonacci finder" runs into the foundational roadblock that a mathematical proof for the infinitude of prime Fibonacci numbers does not yet exist. Proving termination for unbounded numerical searches (like polynomial root-finding) similarly requires engineering workarounds like "computational fuel."

Future work will likely focus on developing better neuro-symbolic agents capable of handling the structurally rich, case-heavy proof landscapes unique to computer software.

Summary updated

BibTeX
@inproceedings{thakur2025clever,
  author = {Amitayush Thakur and Jasper Lee and George Tsoukalas and Meghana Sistla and Matthew Zhao and Stefan Zetzsche and Greg Durrett and Yisong Yue and Swarat Chaudhuri},
  title = {{CLEVER: A Curated Benchmark for Formally Verified Code Generation}},
  booktitle = {AI4MATH @ ICML},
  year = {2025},
  url = {https://openreview.net/forum?id=pqNFDA2TFm},
}
Figure