[论文解读] Neuro-Symbolic Generation and Validation of Memory-Aware Formal Function Specifications
该论文提出一种神经符号工作流,从自然语言和函数签名生成内存感知的正式 C 函数规格,并通过符号证明器与基于 Coq 的反例驱动推理框架进行迭代 refined,在一个来自 LeetCode 的基准上进行了评估。
Formal verification of memory-manipulating programs critically depends on precise function specifications that capture memory states written by experts. This requirement has become a major bottleneck as large language models (LLMs) increasingly generate low-level systems code whose correctness cannot be assumed. To enable scalable formal verification, we focus exclusively on function specification generation, deliberately avoiding the synthesis of complex loop invariants that are central to traditional verification pipelines. We propose a neuro-symbolic framework for automatically generating memory-aware formal function specifications for C programs from natural language problem descriptions and function signatures. The pipeline first produces candidate specifications via in-context learning, and then iteratively refines them using compiler diagnostics from symbolic provers and the verification toolchain. In particular, we validate candidate specifications by constructing a proof for the negation of the specification with concrete examples, enabling machine-checked rejection of plausible-but-incorrect specifications. To support systematic evaluation, we introduce LeetCode-C-Spec, a new benchmark of 200 C programming problems for generating memory-aware formal function specifications. Experiments show that iterative refinement substantially improves syntactic validity, while symbolic prover-based refutation significantly enhances correctness assessment by filtering false positives that LLM-only judges frequently accept. Our results demonstrate that combining neural generation with symbolic feedback provides an effective approach to formal specification synthesis for memory-safe systems software.
研究动机与目标
- 解决因为为 C 程序编写内存感知函数规格而引发的形式化验证瓶颈。
- 开发一种神经符号的两阶段工作流,从自然语言和函数签名生成并 refined 内存感知函数规格。
- 通过使用 Coq 和符号证明器的反例驱动推理实现对规格的自动验证。
- 创建并发布 LeetCode-C-Spec-200,一个包含 200 道 C 题目的内存感知规格生成基准。
提出的方法
- 两阶段管线:阶段 1 使用带有 curated prompts 的 in-context learning 生成 QCP 兼容的内存感知 C 函数规格。
- 阶段 2 使用来自 Coq 与 QCP 的编译器诊断,以及反例驱动推理,迭代地 refine 规格以修复语法和语义错误。
- 验证将 LLM 语义检查与形式方法相结合:生成否定后的后置条件,实例化具体的 Coq 测试用例,并尝试通过 Coq hammer 与自动定理证明器来消解。
- 反例生成工作流将自然语言示例转换为带类型的 Coq 表示,再转化为反驳测试用例,以形式化反驳不正确的规格。
- 数据集与转换:构建 LeetCode-C-Spec-200(200 道 LeetCode 题目)用于内存感知规格生成,并映射到 QCP 谓词和 Coq 导入。
- 该方法强调在函数级别的规格优于循环不变式,以便实现基于测试的验证和分层的验证。
实验结果
研究问题
- RQ1是否可以从自然语言问题描述和函数签名中自动生成 C 的内存感知功能规格?
- RQ2通过符号反馈的迭代 refine 是否能提高 LLM 生成的规格的句法有效性?
- RQ3基于 Coq 的反例驱动推理是否能有效过滤 LLM 仅判定接受的假阳性?
- RQ4LeetCode-C-Spec-200 是否是一个适合用于 C 语言内存感知正式规格生成的基准?
- RQ5将神经生成与符号验证结合对正确性和可验证性有何影响?
主要发现
- 迭代 refine 显著提高了 LLM 生成规格的句法有效性。
- 通过 Coq 的符号证明器进行的反驳显著提升了正确性评估,能够过滤假阳性。
- 集成的神经符号工作流提升了 C 程序的内存感知函数规格生成。
- LeetCode-C-Spec-200 提供了一个具有多样数据结构和算法复杂性的具有挑战性的基准用于评估。
- Coq hammer 与自动定理证明器帮助验证后置条件并发现规格错误。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。