Introduction
While Large Language Models (LLMs) have demonstrated remarkable proficiency in generating code, ensuring the absolute correctness of this code remains a significant challenge. Traditional software testing often fails to uncover subtle edge cases, which can lead to critical system failures. Formal verification offers a rigorous alternative by using mathematical logic to prove that a program adheres to its specifications. However, this process requires developers to provide complex "annotations"—such as loop invariants and assertions—to guide the proof engine. This high barrier to entry has limited the adoption of formal methods. DafnyBench is introduced as a large-scale benchmark designed to evaluate and improve the ability of LLMs to automate this demanding task.
The DafnyBench Dataset
DafnyBench represents the largest benchmark to date for formal software verification, comprising 782 programs written in the Dafny programming language. Totaling approximately 53,000 lines of code, it significantly expands upon previous datasets like Clover (66 programs) and dafny-synthesis (153 programs). The dataset was constructed by scraping thousands of Dafny files from GitHub and integrating existing benchmarks, followed by a rigorous deduplication process using the Minhash algorithm to ensure variety.
As shown in the figure above, the benchmark covers a wide range of program complexities. The distribution of characters and required annotations highlights the diversity of the tasks, ranging from simple textbook examples to more intricate real-world code.
Methodology: The "Fill Annotations" Task
The primary evaluation task in DafnyBench is "Fill Annotations." In this setup, human-written invariants and assertions are stripped from verified programs. LLMs are then tasked with regenerating these annotations. Success is determined by the Dafny verification engine; a model's output is considered correct only if the engine can mathematically prove the code's correctness without the use of "cheating" commands that bypass verification checks. This automated pipeline ensures an objective and scalable evaluation of model performance.
Key Findings and Results
The evaluation of several state-of-the-art models revealed a clear performance hierarchy and several critical bottlenecks in current AI capabilities:
- Model Performance: Claude 3 Opus emerged as the top performer with a 67.8% success rate, followed by GPT-4 Turbo (59.8%) and GPT-4o (59.3%). Open-source models lagged significantly, with CodeLlama-7b achieving only 28.0%, barely exceeding the "No LLM" baseline of 26.9% (where programs verify without any annotations).
- The Complexity Wall: A significant "complexity wall" was observed. While models achieved nearly 80% success on short programs, performance plummeted below 20% as program length and logical depth increased. This suggests that current models struggle with the exponential growth of logical dependencies in larger software systems.
- Feedback Limitations: Providing models with up to 10 retry attempts using compiler error messages yielded diminishing returns. Success rates plateaued quickly, indicating that LLMs struggle to reason through formal logic errors to iteratively correct their work.
Conclusion and Future Directions
DafnyBench provides a critical foundation for advancing AI-powered formal verification. While top-tier models show promise, the gap between open-source and closed-source performance, along with the struggle to handle complex logic, highlights areas for future research. Potential improvements include using program transformations to mitigate data contamination and expanding the benchmark to include multi-file projects and natural-language-to-specification tasks. By lowering the effort required for formal verification, tools developed using DafnyBench could eventually make bug-free software a standard reality.
Summary updated