arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2510.12702cs.SEcs.AIcs.PL
收藏

超越后置条件:大型语言模型能否为自动软件验证推断形式化契约?

Beyond Postconditions: Can Large Language Models infer Formal Contracts for Automatic Software Verification?

Carl von Ossietzky Universität Oldenburg(奥尔登堡卡尔·冯·奥西茨基大学)

Cedric Richter, Heike Wehrheim

AI总结:

本文提出NL2Contract任务,利用大型语言模型将自然语言转换为形式化功能契约(含前置与后置条件),实验证明其生成契约健全且能减少验证误报,并有效捕获真实错误。

摘要:

自动软件验证器在根据(形式化)规范检查软件方面的能力日益增强。然而,由于现实世界代码中缺乏此类规范,其实际应用受到了阻碍。大型语言模型(LLMs)在从代码中嵌入的自然语言提示(如函数名、注释或文档)推断形式化后置条件方面显示出潜力。然而,将生成的后置条件用作后续验证中的规范,往往会导致验证器建议无效输入,暗示潜在问题,而这些最终被证明是误报。为解决这一问题,我们重新审视了在自动软件验证背景下从自然语言进行规范推断的问题。在此过程中,我们引入了NL2Contract,即利用LLMs将非正式自然语言转化为形式化功能契约(包括后置条件和前置条件)的任务。我们引入了度量标准来验证和比较不同的NL2Contract方法,以生成契约的健全性、错误判别能力及其在自动软件验证背景下的可用性作为关键指标。我们使用不同的LLMs评估NL2Contract,并将其与后置条件生成任务nl2postcond进行比较。我们的评估表明:(1)LLMs通常能有效生成对所有可能输入都健全的功能契约;(2)生成的契约具有足够的表达能力来区分错误行为与正确行为;(3)与仅提供后置条件相比,配备LLM推断功能契约的验证器产生的误报更少。进一步研究表明,LLM推断的前置条件通常与开发者的意图高度一致,这使我们能够利用自动软件验证器捕获现实世界中的错误。

英文摘要:

Automatic software verifiers have become increasingly effective at the task of checking software against (formal) specifications. Yet, their adoption in practice has been hampered by the lack of such specifications in real world code. Large Language Models (LLMs) have shown promise in inferring formal postconditions from natural language hints embedded in code such as function names, comments or documentation. Using the generated postconditions as specifications in a subsequent verification, however, often leads verifiers to suggest invalid inputs, hinting at potential issues that ultimately turn out to be false alarms. To address this, we revisit the problem of specification inference from natural language in the context of automatic software verification. In the process, we introduce NL2Contract, the task of employing LLMs to translate informal natural language into formal functional contracts, consisting of postconditions as well as preconditions. We introduce metrics to validate and compare different NL2Contract approaches, using soundness, bug discriminative power of the generated contracts and their usability in the context of automatic software verification as key metrics. We evaluate NL2Contract with different LLMs and compare it to the task of postcondition generation nl2postcond. Our evaluation shows that (1) LLMs are generally effective at generating functional contracts sound for all possible inputs, (2) the generated contracts are sufficiently expressive for discriminating buggy from correct behavior, and (3) verifiers supplied with LLM inferred functional contracts produce fewer false alarms than when provided with postconditions alone. Further investigations show that LLM inferred preconditions generally align well with developers intentions which allows us to use automatic software verifiers to catch real-world bugs.

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

↑