How Powerful are LLMs in Generating Formal Program Specifications?

๐Ÿ“… 2026-08-13
๐Ÿ“ˆ Citations: 0
โœจ Influential: 0
๐Ÿ“„ PDF
๐Ÿค– AI Summary
This work addresses the challenge of accurately evaluating the quality of formal program specifications generated by large language models (LLMs), a task often confounded by the inherent complexity of formal verification. To mitigate this issue, the authors propose Coins, a framework built upon the Rocq formal system that aligns evaluation with the asymmetric nature of formal reasoning. Coins instantiates generated specifications against trusted test cases and automatically derives concrete proof obligations, using test-case-driven proof success rates as a reliable proxy for specification qualityโ€”thereby avoiding misattribution of proof difficulty to specification inadequacy. Large-scale experiments on HumanEval demonstrate that current LLMs still face substantial difficulties in specification generation, and that Coins provides a more accurate assessment of genuine differences in specification quality.
๐Ÿ“ 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.
Problem

Research questions and friction points this paper is trying to address.

formal specification
large language models
specification evaluation
formal verification
program synthesis
Innovation

Methods, ideas, or system contributions that make the work stand out.

formal specification
large language models
evaluation framework
test-case-based reasoning
proof obligations
F
Fanpeng Yang
Institute of Software, Chinese Academy of Sciences, Beijing, China; University of the Chinese Academy of Sciences, Beijing, China
X
Xing Li
Institute of Software, Chinese Academy of Sciences, Beijing, China; University of the Chinese Academy of Sciences, Beijing, China
S
Shuling Wang
Institute of Software, Chinese Academy of Sciences, Beijing, China; University of the Chinese Academy of Sciences, Beijing, China
Jie An
Jie An
Institute of Software, Chinese Academy of Sciences, Beijing, China
Formal MethodsCyber-Physical SystemsAutomata LearningMonitoring
Zeyu Sun
Zeyu Sun
Institute of Software, Chinese Academy of Sciences
Software EngineeringNatural Language Processing
S
Shenghua Feng
Institute of Software, Chinese Academy of Sciences, Beijing, China
Wenhan Wang
Wenhan Wang
Institute of Software, Chinese Academy of Sciences
AI4SEprogram understandingSoftware TestingLLM4Code
W
Weiyi Wang
Institute of Software, Chinese Academy of Sciences, Beijing, China; University of the Chinese Academy of Sciences, Beijing, China
Naijun Zhan
Naijun Zhan
School of Computer Science, Peking University
Formal MethodsReal-timeembedded and hybrid systemsProgram Verification
F
Fanjiang Xu
Institute of Software, Chinese Academy of Sciences, Beijing, China; University of the Chinese Academy of Sciences, Beijing, China