TL;DR
Large Language Models (LLMs) are great at generating code, but can they prove it's correct? This paper introduces VerifyThisBench, a new benchmark to test LLMs on full program verification (code, specifications, and proofs) from natural language. The results show current SOTA LLMs struggle significantly, highlighting a major gap in formal reasoning capabilities.
What Problem Does This Paper Address?
LLMs have revolutionized code generation, but existing benchmarks primarily focus on functional correctness (does the code run and produce the right output for given tests?). This is insufficient for critical software where absolute guarantees are needed. Formal verification, which mathematically proves a program's correctness against a specification, offers this rigor. However, evaluating LLMs on this complex, multi-stage task – interpreting natural language, generating formal specifications, writing verification-aware code, and constructing machine-checkable proofs – has been lacking. This paper aims to fill that gap by creating a challenging benchmark and evaluating current LLMs on it.
Methods
The core contribution is VerifyThisBench, a benchmark designed to assess end-to-end program verification. It's inspired by the annual VerifyThis competition, which involves human experts creating verified programs. For LLMs, this means taking a natural language problem description and producing:
- Formal Specifications: Precisely defining what the program should do (pre-conditions, post-conditions, invariants).
- Verification-Aware Code: Implementing the logic in a language supported by formal verification tools.
- Machine-Checkable Proofs: Constructing the mathematical arguments that demonstrate the code meets its specifications.
To better understand LLM limitations, they also introduce VerifyThisBenchXS, a relaxed version where partial solutions (code, specifications, or proofs) are provided, allowing LLMs to complete them. They developed a unified evaluation environment supporting seven different verification tools (Dafny, Frama-C, VerCors, VeriFast, Why3, Verus, CBMC) to ensure broad applicability. Experiments involve iterative refinement, where LLMs use error messages from the verifiers to improve their outputs.
Datasets
The primary dataset is VerifyThisBench, comprising 734 tasks derived from the VerifyThis competition series (2011-2024). These tasks cover various domains and complexities.
A relaxed version, VerifyThisBenchXS, was created with 580 tasks, derived from existing solutions and including new Verus solutions. This dataset is broken down into three categories: Code-Gen (providing specifications, LLM generates code and proofs), Specification-Gen (providing code and proofs, LLM generates specifications), and Loop-Gen (providing code and specifications, LLM generates loop invariants).
Key Insights and Ideas
- Formal Verification is a Major Hurdle for LLMs: Even state-of-the-art LLMs perform poorly on end-to-end verification tasks, with very low pass rates even after iterative refinement. This highlights a significant gap in their formal reasoning capabilities.
- Iterative Refinement is Crucial: LLMs show substantial improvement when given feedback from verification tools, indicating that they can learn from errors and correct their outputs.
- Partial Solutions Help Significantly: The relaxed VerifyThisBenchXS dataset shows that providing LLMs with some context (like partial code or specifications) dramatically improves their performance, suggesting that generating everything from scratch is the hardest part.
- Tool Diversity Matters: LLMs perform differently across various verification tools, suggesting that model capabilities are not universally transferable and might be influenced by the tool's syntax and complexity.
- Coherence is Not Guaranteed: While LLMs can sometimes generate verified code, their self-assessment of whether the verified code truly matches the natural language intent (coherence) is often low, indicating a disconnect between syntactic correctness and semantic alignment.
Key Results
- VerifyThisBench: SOTA models achieved a zero-shot pass rate of less than 4% on the full benchmark. After five rounds of iterative refinement, the best model (o3-mini) reached only 9.37%.
- VerifyThisBenchXS: In the relaxed setting, zero-shot pass rates were still low (under 4%), but improved to around 17-18% after refinement for top models like o4-mini and Deepseek.
- Failure Modes: Compilation errors are a dominant failure mode, though they decrease in the relaxed setting. "Partial" success (some but not all obligations proved) is common, indicating progress but not full verification.
- Coherence: On average, only 43% of passed solutions were judged coherent by the models themselves, suggesting that even when code is verified, it might not perfectly align with the original intent.
Limitations and Future Work
- LLM Limitations: The paper clearly demonstrates that current LLMs are far from mastering end-to-end formal verification. Their ability to generate correct specifications and proofs from natural language is severely limited.
- Benchmark Limitations: While VerifyThisBench is comprehensive, the authors acknowledge that automatically verifying the alignment between generated specifications and user intent in natural language remains an open challenge.
- Future Work: The authors release the benchmark and evaluation environment to encourage further research. They suggest that future work should focus on improving LLMs' formal reasoning, understanding of specifications, and ability to generate semantically aligned verified code. Exploring more sophisticated prompt engineering and fine-tuning strategies tailored for formal verification tasks is also a promising direction.
Summary updated