Automatic Generation of Formal Specification and Verification Annotations Using LLMs and Test Oracles
Jo\~ao Pascoal Faria, Emanuel Trigo, Vinicius Honorato, Rui Abreu

TL;DR
This paper demonstrates how large language models can automatically generate formal verification annotations for Dafny programs from natural language comments and test code, significantly reducing manual effort.
Contribution
It introduces a multimodel LLM approach that automates the creation of formal specifications and proof helpers in Dafny, achieving high accuracy with minimal iterations.
Findings
Correct annotations generated for 98.2% of programs
Test assertions effectively validate generated specifications
Proof-helper annotations are key to problem difficulty
Abstract
Recent verification tools aim to make formal verification more accessible to software engineers by automating most of the verification process. However, annotating conventional programs with the formal specification and verification constructs (preconditions, postconditions, loop invariants, auxiliary predicates and functions and proof helpers) required to prove their correctness still demands significant manual effort and expertise. This paper investigates how LLMs can automatically generate such annotations for programs written in Dafny, a verification-aware programming language, starting from conventional code accompanied by natural language specifications (in comments) and test code. In experiments on 110 Dafny programs, a multimodel approach combining Claude Opus 4.5 and GPT-5.2 generated correct annotations for 98.2% of the programs within at most 8 repair iterations, using…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsSoftware Testing and Debugging Techniques · Formal Methods in Verification · Logic, programming, and type systems
