Skip to main content
QUICK REVIEW

[论文解读] SpecGen: Automated Generation of Formal Program Specifications via Large Language Models

Lezhi Ma, Shangqing Liu|arXiv (Cornell University)|Jan 16, 2024
Software Engineering ResearchComputer Science被引用 6
一句话总结

SpecGen 使用两阶段方法(基于对话的生成与基于变异的 refinement)结合 LLMs 生成可验证的 Java/JML 规范,在 120 个程序上超越 Houdini、Daikon,以及纯 LLM 基线。

ABSTRACT

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.

研究动机与目标

  • 利用 LLM 代码理解来生成高质量的形式化规范。
  • 克服 prior 工具(Houdini, Daikon)在复杂程序上的模板/语法限制。
  • 引入基于变异的生成以通过可验证的改进修复 LLM 的不足。
  • 提出一种启发式选择策略以高效验证变异后的规范。
  • 提供一个包含专家编写规范的 120 个 Java 程序数据集用于评估。

提出的方法

  • 通过对话驱动的规范生成,在初始提示和验证反馈的引导下生成 JML 规范。
  • 验证器反馈用于在多轮对话中改进后续的 LLM 输出。
  • 基于变异的规范生成,通过四类运算符族(谓词性、逻辑、比较、算术)对失败的 LLM 输出进行变异。
  • 启发式选择以权重选择经过变异的变体以高效通过验证。
  • 使用 120 个 Java 程序和 OpenJML 验证器的评估设置,与 Houdini、Daikon、以及纯 LLM 基线进行比较。

实验结果

研究问题

  • RQ1与基线规范生成方法相比,SpecGen 的表现如何?
  • RQ2每种变异类型对 SpecGen 的有效性贡献是什么?
  • RQ3候选人选择策略如何影响 SpecGen 的效率?
  • RQ4生成的规范在多大程度上捕捉了输入程序的语义行为?

主要发现

  • SpecGen 可以对 120 个程序中的 100 个生成可验证的规范,优于 Houdini(42)和纯 LLM 基线方法(72 次对话,4-shot 设置下最高 70)。
  • 基于对话的生成加上基于变异的 refinement 相对于纯 LLM 或基于模板的方法有显著改进。
  • 启发式选择策略在变异验证中相较于随机选择提高了 20.22% 的效率。
  • 一个消融研究证实所有四种变异操作符的有效性。
  • 数据集包含 120 个带有专家撰写的 Oracle 规范的 Java 程序,便于稳健评估。

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。