首个系统性评测大模型生成代码规范能力的基准,揭示其隐藏缺陷与真实表现。
LiveFMBench: Unveiling the Power and Limits of Agentic Workflows in Specification Generation

- 构建动态更新的630个带ACSL注释的C程序基准,防止数据泄露。
- 直接提示下准确率虚高,剔除欺骗性结果后真实准确率下降约20%。
- 思维链和代理流程显著提升效果,尤其适合小模型和难题场景。
形式化规范对程序验证至关重要,但编写正确规范成本高且难自动化。尽管大语言模型(LLMs)和智能体展现出潜力,其真实能力与失败模式仍不清晰。本文提出首个系统性、防污染的基于LLM与智能体的C程序形式化规范生成评估:LiveFMBench,包含630个带ACSL注释的C程序,其中360个为新收集以缓解数据泄露。我们评估了直接提示(不同采样量)、推理增强(思考模式)、智能体流水线,并进行细粒度错误分析。实验发现,朴素评估严重夸大性能——直接提示下的模型可能欺骗自动证明器或忽略代码上下文约束;剔除此类情况后,真实规范生成准确率下降约20%。增加采样和使用思考模式均显著提升成功率,小模型更受益于思考模式。智能体流水线在低采样预算和高难度数据集上尤为有效。错误分析显示,错误循环不变量是主要错误类型,而智能体显著减少了断言错误。结果揭示当前基于大模型的方法存在根本局限,远未达到替代人工规范的程度。我们已公开LiveFMBench及全部评估资源。
原文摘要 · Abstract (English)
Formal specification is essential for rigorous program verification, yet writing correct specifications remains costly and difficult to automate. Although large language models (LLMs) and agents have shown promising progress, their true capabilities and failure modes remain unclear. We present the first systematic and contamination-aware study of LLM- and agent-based formal specification generation for C programs. We introduce LiveFMBench, a continuously evolving benchmark of 630 ACSL (ANSI/ISO C Specification Language)-annotated C programs, including 360 newly collected cases designed to mitigate data leakage. Using this benchmark, we evaluate direct prompting with different sampling sizes, reasoning-enabled (thinking mode) inference, the agentic pipeline, and perform a fine-grained failure analysis. Experimental results reveal that naive evaluation substantially overestimates performance because models under direct prompting may exhibit unfaithful behaviors, such as deceiving automated provers or ignoring code-context constraints; after excluding such cases, the true specification generation accuracy drops by approximately 20\%. We further find that both increased sampling and thinking mode significantly improve success rates, with smaller models benefiting more from thinking mode. Agentic pipelines are particularly effective under low sampling budgets and on harder datasets. Failure analysis further shows that incorrect loop invariants are the dominant error type, while agentic pipelines notably reduce assertion errors. These results expose fundamental limitations in current LLM-based approaches and suggest they remain far from replacing human-authored formal specifications. We release LiveFMBench at https://huggingface.co/datasets/fm-universe/Live-FM-Bench and all evaluation artifacts to support future research.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。