How Powerful are LLMs in Generating Formal Program Specifications?
Abstract
Formal verification provides strong guarantees of software correctness, but its adoption is limited by the high cost of writing precise formal specifications. While recent large language models (LLMs) have shown strong capabilities in theorem proving and verified code generation, their true ability to generate program specifications remains unclear. Existing evaluations require either verifying implementation conformance or proving semantic equivalence between specifications, both of which are formidably difficult and may conflate proof difficulty with specification quality. To address this problem, we introduce Coins, a Rocq based evaluation framework that assesses specification quality by instantiating specifications under evaluation on trusted test cases and generating concrete proof obligations. This design aligns with the asymmetric nature of formal reasoning, where successful proofs provide reliable evidence while proof failures are inherently ambiguous. Using Coins, we conduct a large scale study on HumanEval with a curated set of human written Rocq specifications. Our results show that specification generation remains a formidable challenge, and that verification complexity can obscure genuine differences in specification quality. Overall, we find that accurate specification evaluation, rather than model scaling alone, is central to understanding the power of LLMs for specification synthesis, and that test case based formal reasoning offers a more faithful and discriminative measure of progress.
Lay Summary
Software correctness checking can provide very strong guarantees, but it first depends on writing a specification: a precise, machine-checkable description of what a program is supposed to do. Writing specs is both time-consuming and laborious, often even harder than writing the program itself. Whether AI models can write good specifications remains unclear, mainly because judging specification quality is very difficult—proving that a specification matches a program is hard, and judging a specification's quality often relies on hand-written ground-truth specifications; moreover, when a proof fails, there is no way to tell whether the specification is wrong or simply too hard to prove. We introduce Coins, which evaluates a specification by proving concrete Rocq theorems instantiated from trusted examples of intended and unintended behaviors, thereby reducing the extent to which specification quality is confounded with the model's proving ability and yielding a denser, more discriminative evaluation signal.