VERT:利用大语言模型作为少样本学习者的等价 Rust 转译验证
VERT: Verified Equivalent Rust Transpilation with Large Language Models as Few-Shot Learners
AI总结:
VERT 结合 Web Assembly 编译器生成的 oracle 与 LLM 候选,通过迭代验证生成可读且形式化正确的 Rust 转译,显著提升属性测试和模型检查通过率。
摘要:
Rust 是一种结合了内存安全与底层控制的编程语言,在提供类似 C 语言性能的同时,默认保证不存在未定义行为。Rust 日益增长的受欢迎程度促使了关于将现有代码库安全且正确地转译为 Rust 的研究。现有工作分为两类:基于规则的方法和基于大语言模型(LLM)的方法。基于规则的方法理论上可以生成保持与原程序输入输出等价性的正确转译结果,但通常会产生使用 Rust 语言不安全子集的难以阅读的代码。另一方面,基于 LLM 的方法通常生成更可读、可维护且安全的代码,但不提供任何正确性保证。在这项工作中,我们提出了 VERT,一个能够生成具有形式化正确性保证的可读 Rust 转译代码的工具。VERT 的唯一要求是源语言存在 Web Assembly 编译器,这对于大多数主流语言都是成立的。VERT 首先使用 Web Assembly 编译器获取一个 oracle Rust 程序。与此同时,VERT 使用 LLM 生成一个可读的候选 Rust 程序。该候选程序会与 oracle 进行验证,如果验证失败,则重新生成新的候选转译,直到验证成功。我们通过转译一组来自竞争性编程风格基准的 1,394 个程序来评估 VERT。结合 Anthropic 的 Claude-2 和 VERT,与单独使用 Claude 相比,通过基于属性的测试的 Rust 转译比例从 31% 提高到 54%,通过有界模型检查的比例从 1% 提高到 42%。此外,我们评估了 VERT 在来自真实世界 C 项目(大量使用指针)的程序上生成非平凡安全 Rust 的能力。我们的结果提供了对 LLM 编写安全 Rust 局限性的洞察。
英文摘要:
Rust is a programming language that combines memory safety and low-level control, providing C-like performance while guaranteeing the absence of undefined behaviors by default. Rust's growing popularity has prompted research on safe and correct transpiling of existing code-bases to Rust. Existing work falls into two categories: rule-based and large language model (LLM)-based. While rule-based approaches can theoretically produce correct transpilations that maintain input-output equivalence to the original, they often yield unreadable Rust code that uses unsafe subsets of the Rust language. On the other hand, while LLM-based approaches typically produce more readable, maintainable, and safe code, they do not provide any guarantees about correctness. In this work, we present VERT, a tool that can produce readable Rust transpilations with formal guarantees of correctness. VERT's only requirement is that there is Web Assembly compiler for the source language, which is true for most major languages. VERT first uses the Web Assembly compiler to obtain an oracle Rust program. In parallel, VERT uses an LLM to generate a readable candidate Rust program. This candidate is verified against the oracle, and if verification fails, we regenerate a new candidate transpilation until verification succeeds. We evaluate VERT by transpiling a suite of 1,394 programs taken from competitive programming style benchmarks. Combining Anthropic's Claude-2 and VERT increases Rust transpilations passing property-based testing from 31% to 54% and bounded model-checking from 1% to 42% compared to using Claude alone. In addition, we evaluate VERT's ability to generate non-trivial safe Rust on programs taken from real-world C projects that make significant use of pointers. Our results provide insights into the limitations of LLMs to write safe Rust.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。