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

可信软件项目生成:以交互式定理证明器为例的案例研究

Trustworthy Software Project Generation : a Case Study with an Interactive Theorem Prover

Key Laboratory of High Confidence Software Technologies (Peking University), Ministry of Education(教育部高可信软件技术重点实验室;北京大学计算机学院);School of Computer Science Peking University

Jian Fang, Yingfei Xiong

AI总结:

本文研究利用交互式定理证明器(ITP)从自然语言需求自动生成大规模可信软件项目,通过将纯逻辑与有副作用的代码分离,在Rocq中完成验证并提取C++代码,成功生成一个RISC-V RV32I CPU解释器,证明了ITP作为LLM生成软件验证后端的可行性。

摘要:

从自然语言需求生成代码已成为LLM辅助软件开发的主要途径。尽管LLM能成功完成小型编程任务,但生成整个复杂项目仍不可靠,因为细微错误可能通过编译和测试。验证编程通过要求生成的实现满足机器检查的规范来降低此风险。现有探索主要针对面向验证的语言和工具链(如Dafny和Frama-C),但直接用这些系统生成项目规模的可验证代码仍然困难。本文研究交互式定理证明器(ITP)能否支持大规模软件生成。由于ITP处理纯全函数但不处理I/O等副作用,我们的代理将有副作用的代码与纯逻辑分离:它在目标语言中实现副作用,在ITP中证明纯逻辑,并提取代码以集成到最终项目中。我们通过完全自动开发一个支持非特权RISC-V RV32I基础所有47条指令的CPU解释器来研究这一路线:在提供需求后,合成、证明修复、提取或集成过程中无需人工干预。以Rocq为后端,代理在30分钟内完成项目,生成1,859行已验证的Rocq代码,并提取2,848行C++代码。生成的解释器通过了所有265个LLM生成的覆盖47条指令的测试,并在12小时的AFL++模糊测试中零崩溃、零挂起。在相同配置下,基于Dafny的后端未能完成验证。我们的观察是,当证明尝试失败时,Rocq会暴露具体的证明状态,为代理提供可操作的修复反馈。这些结果提供了经验证据,表明基于ITP的验证编程是LLM生成软件项目的可行路线。

英文摘要:

Generating code from natural-language requirements has become a primary route for LLM-assisted software development. Although LLMs can successfully complete small programming tasks, generating an entire complex project remains unreliable because subtle errors may survive compilation and testing. Verified programming can reduce this risk by requiring generated implementations to satisfy machine-checked specifications. Existing explorations mostly target verification-oriented languages and toolchains such as Dafny and Frama-C, but directly generating project-scale verified code with these systems remains difficult. This paper studies whether interactive theorem provers (ITPs) can support large-scale software generation. Because ITPs handle pure total functions but not effects such as I/O, our agent separates effectful code from pure logic: it implements the effects in the target language, proves the pure logic in an ITP, and extracts it for integration into the final project. We study this route through the fully automatic development of a CPU interpreter for all 47 instructions of the unprivileged RISC-V RV32I base: after the requirements are supplied, no human intervenes in synthesis, proof repair, extraction, or integration. With Rocq as the backend, the agent completes the project within 30 minutes, producing 1,859 lines of verified Rocq and extracting 2,848 lines of C++. The resulting interpreter passes all 265 LLM-generated tests covering the 47 instructions and exhibits zero crashes and zero hangs during 12 hours of AFL++ fuzzing. Under the same configuration, a Dafny-based backend fails to complete verification. Our observation is that Rocq exposes a concrete proof state when a proof attempt fails, giving the agent actionable feedback for repair. These results provide empirical evidence that ITP-based verified programming is a feasible route for LLM-generated software projects.

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

↑