用对抗协作机制自动修复C转Rust时的未测输入错误。
Adversarial Agent Collaboration for Correctness Improvements of C to Safe Rust Translation
- 设计双代理循环:翻译器与鉴别器对抗生成新测试用例。
- 在63个真实命令行工具上实现超90%测试通过率,无需人工干预。
- 可适配多种模型,显著提升现有工具的正确性,适合自动化迁移场景。
将C语言代码转换为内存安全语言(如Rust)能有效防止遗留C程序中的严重内存安全漏洞。尽管近期基于大语言模型(LLM)和工具增强的转换器已取得进展,其生成的Rust代码在训练测试集外的输入上仍常出现行为偏差,这一未测输入下的正确性差距仍是实现可靠自动转换的主要障碍。本文提出ACToR(Adversarial C To Rust),一种简单的LLM代理循环机制,通过对抗性搜索找出导致翻译差异的新输入,并利用这些输入驱动后续迭代优化。受生成对抗网络(GAN)启发,ACToR将翻译代理与鉴别代理协同工作:每轮中,翻译代理在已有测试集上生成并优化Rust代码,随后鉴别代理通过构建并精炼差分模糊器,在C与Rust二进制间发现新失败测试。在63个真实世界命令行工具上(平均473行代码,最长达数千行),ACToR实现超过90%的测试通过率,且全程无需人工干预。在微基准测试中,该方法对七种不同代理-LLM配置均有效,表明其对底层模型选择不敏感。相比非对抗性、覆盖率驱动的测试生成基线,正确性提升最高达36.7%;当应用于最新工具C2SaferRust时,验证通过率进一步提升16.6%。
原文摘要 · Abstract (English)
Translating C to memory-safe languages, like Rust, prevents critical memory safety vulnerabilities that are prevalent in legacy C software. Even with recent LLM-based and tool-augmented translators, the resulting Rust code frequently diverges from the C source on inputs absent from the test suite used during translation; this correctness gap on unseen inputs remains a dominant obstacle to reliable, automatic C-to-Rust translation. In this work, we present ACToR (Adversarial C To Rust), a simple LLM-agent loop that closes this gap by adversarially searching for inputs on which the translation diverges from the C source, and using them to drive subsequent refinements. Inspired by GANs, ACToR pits a translator agent against a discriminator agent that collaborate to iteratively refine the Rust translation. On each iteration, the translator agent synthesizes and refines a Rust translation to pass an existing suite of tests, and then the discriminator agent finds new failing tests by constructing and refining a differential fuzzer over the C and Rust binaries. Across 63 real-world command-line C utilities, with an average size of 473 lines of code and the longest reaching thousands of lines in size, ACToR achieves over 90% test pass rate with zero human intervention. The improvement holds across seven agent-LLM configurations on our micro-benchmark, indicating that the loop is largely independent of the choice of underlying translator and LLM. Compared to a non-adversarial, coverage-driven test-generation baseline, ACToR improves correctness by up to 36.7%. When applied on top of one recent translator, C2SaferRust, ACToR further improves the validation pass rate by 16.6%.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。