[Paper Review] DafnyBench: A Benchmark for Formal Software Verification
DafnyBench introduces the largest existing benchmark for formal software verification, comprising 782 Dafny programs with ~53,000 lines of code, designed to train and evaluate LLMs in generating verification hints. The best-performing LLM setup achieved a 68% success rate in verifying programs, with improvements observed through feedback retries and degradation with increasing code and hint complexity.
We introduce DafnyBench, the largest benchmark of its kind for training and evaluating machine learning systems for formal software verification. We test the ability of LLMs such as GPT-4 and Claude 3 to auto-generate enough hints for the Dafny formal verification engine to successfully verify over 750 programs with about 53,000 lines of code. The best model and prompting scheme achieved 68% success rate, and we quantify how this rate improves when retrying with error message feedback and how it deteriorates with the amount of required code and hints. We hope that DafnyBench will enable rapid improvements from this baseline as LLMs and verification techniques grow in quality.
Motivation & Objective
- To address the lack of large-scale, diverse benchmarks for training and evaluating LLMs in formal software verification.
- To enable rapid progress in automating formal verification by providing a scalable, realistic dataset of verified Dafny programs.
- To quantify the current capabilities of LLMs in generating effective verification hints for real-world Dafny programs.
- To improve the accessibility and adoption of formal verification by reducing the human effort required through AI assistance.
- To establish a standardized evaluation framework for future advancements in AI-driven formal verification.
Proposed method
- The benchmark collects 782 formally verified Dafny programs from public GitHub repositories, ensuring real-world relevance and diversity.
- Each program is paired with a 'hints_removed' version, stripping verification annotations to simulate LLM generation tasks.
- LLMs such as GPT-4 and Claude 3 are prompted to regenerate the missing hints, which are then fed into the Dafny verifier to test correctness.
- Evaluation includes retrying with error message feedback to simulate iterative refinement, measuring success rate improvements.
- The benchmark includes edge cases such as cheating (e.g., using `assume false` or `{:verify false}`) to ensure robustness in evaluation.
- Evaluation is conducted using API calls to LLMs via the sglang package, with full reproducibility ensured through metadata and scripts.

Experimental results
Research questions
- RQ1What is the baseline success rate of current LLMs in generating sufficient hints to verify Dafny programs?
- RQ2How does feedback from Dafny’s error messages improve LLM-generated hint quality over multiple retries?
- RQ3How does the required code size and number of hints affect the success rate of LLM-based verification?
- RQ4How does DafnyBench compare to prior benchmarks like Clover and dafny-synthesis in scale and realism?
- RQ5To what extent do LLMs fail due to semantic or syntactic errors in generated hints, and how can such failures be detected?
Key findings
- The best-performing LLM and prompting scheme achieved a 68% success rate in verifying Dafny programs from the DafnyBench benchmark.
- Retry attempts with error message feedback improved the success rate, indicating that iterative refinement enhances LLM performance in verification tasks.
- Verification success deteriorated with increasing program size and number of required hints, highlighting scalability challenges.
- The benchmark includes 782 programs with ~53,000 lines of code, making it the largest of its kind, surpassing prior benchmarks like Clover (66) and dafny-synthesis (153).
- Cheating attempts—such as using `assume false` or `{:verify false}`—were detected and rejected by the evaluation pipeline, ensuring integrity of results.
- Reproducibility is ensured with full metadata, evaluation scripts, and estimated costs under $500 for full model runs, enabling widespread adoption.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.