arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2604.22601cs.SEcs.AI
收藏

从自然语言到验证代码:迈向借助Dafny基于形式验证的AI辅助问题到代码生成

From Natural Language to Verified Code: Toward AI Assisted Problem-to-Code Generation with Dafny-Based Formal Verification

Department of Computer Science, The University of Alabama(阿拉巴马大学计算机科学系);The University of Alabama(阿拉巴马大学);Alabama Water Institute, The University of Alabama(阿拉巴马水研究院,阿拉巴马大学)

Md Erfan, Md Kamal Hossain Chowdhury, Ahmed Ryan, Md Rayhanur Rahman

AI总结:

本文提出NL2VC-60数据集,通过分层提示策略评估不同LLM在形式验证中的表现,发现结构化提示和迭代反馈能显著提升验证成功率,证明开放权重LLM可用于高可靠软件开发。

摘要:

大型语言模型(LLMs)在自动化软件工程中展现出潜力,但其正确性常因错误或幻觉代码而受质疑。为确保模型诚实,形式验证要求LLMs在生成实现逻辑的同时提供形式规范,由数学验证器证明正确性。然而,从非正式自然语言到精确形式规范的转换仍是一项艰巨任务。本文通过提供包含60个复杂算法问题的NL2VC-60数据集来解决这一问题:我们评估了七个开放权重LLM的11个随机问题集,采用分层提示策略:无上下文提示、提供结构锚点的签名提示以及利用Dafny验证器迭代反馈的自愈提示。为解决空验证问题(模型通过平凡规范满足验证器),我们集成了uDebug平台以确保功能验证。结果表明,无上下文提示导致几乎全面失败,而结构化锚点和迭代自愈反馈显著提升了验证成功率。具体而言,Gemma 4-31B达到了90.91%的验证成功率,而GPT-OSS 120B在结构化反馈引导下从零提升至81.82%的成功率。这些发现表明,形式验证现在对于开放权重LLM是可行的,它们作为有效学徒,能够合成复杂注释并促进高可靠软件开发。

英文摘要:

Large Language Models (LLMs) show promise in automated software engineering, yet their guarantee of correctness is frequently undermined by erroneous or hallucinated code. To enforce model honesty, formal verification requires LLMs to synthesize implementation logic alongside formal specifications that are subsequently proven correct by a mathematical verifier. However, the transition from informal natural language to precise formal specification remains an arduous task. Our work addresses this by providing the NaturalLanguage2VerifiedCode (NL2VC)-60 dataset: a collection of 60 complex algorithmic problems. We evaluate 11 randomly selected problem sets across seven open-weight LLMs using a tiered prompting strategy: contextless prompts, signature prompts providing structural anchors, and self-healing prompts utilizing iterative feedback from the Dafny verifier. To address vacuous verification, where models satisfy verifiers with trivial specifications, we integrate the uDebug platform to ensure functional validation. Our results show that while contextless prompting leads to near-universal failure, structural signatures and iterative self-healing facilitate a dramatic performance turnaround. Specifically, Gemma 4-31B achieved a 90.91\% verification success rate, while GPT-OSS 120B rose from zero to 81.82\% success with signature-guided feedback. These findings indicate that formal verification is now attainable for open-weight LLMs, which serve as effective apprentices for synthesizing complex annotations and facilitating high-assurance software development.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑