arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2401.08807cs.SE
收藏

SpecGen:通过大型语言模型自动生成形式化程序规范

SpecGen: Automated Generation of Formal Program Specifications via Large Language Models

Lezhi Ma, Shangqing Liu, Yi Li, Xiaofei Xie, Lei Bu

AI总结:

SpecGen利用大型语言模型通过对话生成和变异选择两阶段方法,自动生成形式化程序规范,在基准测试中优于现有方法。

摘要:

形式化程序规范在软件开发的各个阶段都扮演着至关重要的角色。然而,手动编写形式化程序规范相当困难,使得这项工作既耗时又费力。编写能够正确且全面地描述复杂程序语义的规范更具挑战性。为了减轻软件开发人员的负担,自动规范生成方法应运而生。然而,现有方法通常依赖于预定义模板或语法,导致它们难以准确描述复杂真实世界程序的行为和功能。为应对这一挑战,我们引入了SpecGen,一种基于大型语言模型的形式化程序规范生成新技术。我们的关键洞察在于通过利用LLM的代码理解能力来克服现有方法的局限性。SpecGen的过程包括两个阶段。第一阶段采用对话式方法,引导LLM为给定程序生成适当的规范。第二阶段针对LLM未能生成正确规范的情况,对模型生成的规范应用四种变异算子,并通过一种新颖的启发式选择策略从变异后的规范中选出可验证的规范。我们在两个数据集上评估了SpecGen,包括SV-COMP Java类别基准和手动构建的数据集。实验结果表明,SpecGen成功为385个程序中的279个生成了可验证的规范,优于现有的纯基于LLM的方法以及Houdini和Daikon等传统规范生成工具。对生成规范质量的进一步调查表明,SpecGen能够全面阐述输入程序的行为。

英文摘要:

Formal program specifications play a crucial role in various stages of software development. However, manually crafting formal program specifications is rather difficult, making the job time-consuming and labor-intensive. It is even more challenging to write specifications that correctly and comprehensively describe the semantics of complex programs. To reduce the burden on software developers, automated specification generation methods have emerged. However, existing methods usually rely on predefined templates or grammar, making them struggle to accurately describe the behavior and functionality of complex real-world programs. To tackle this challenge, we introduce SpecGen, a novel technique for formal program specification generation based on Large Language Models. Our key insight is to overcome the limitations of existing methods by leveraging the code comprehension capability of LLMs. The process of SpecGen consists of two phases. The first phase employs a conversational approach that guides the LLM to generate appropriate specifications for a given program. The second phase, designed for where the LLM fails to generate correct specifications, applies four mutation operators to the model-generated specifications and selects verifiable specifications from the mutated ones through a novel heuristic selection strategy. We evaluate SpecGen on two datasets, including the SV-COMP Java category benchmark and a manually constructed dataset. Experimental results demonstrate that SpecGen succeeds in generating verifiable specifications for 279 out of 385 programs, outperforming the existing purely LLM-based approaches and conventional specification generation tools like Houdini and Daikon. Further investigations on the quality of generated specifications indicate that SpecGen can comprehensively articulate the behaviors of the input program.

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

↑