一句话:用 LLM 将 C 代码转译为 Rust,并通过差分符号测试验证转译结果与原代码的语义等价性。
将 C 等不安全内存语言的既有代码库转译为 Rust 是获得内存安全保证的前提,但仅靠传统单元测试或模糊测试难以发现 LLM 自动转译所产生的细微语义错误。RustAssure 提出一套基于大语言模型的自动 C-to-Rust 转译系统:一方面通过提示工程(prompt engineering)引导 LLM 生成惯用且安全的 Rust 代码,另一方面在原始 C 函数与转译后的 Rust 函数之间执行差分符号测试,以建立两者的语义相似性,从而捕捉传统测试遗漏的语义偏差。作者在五个真实应用与库上评估该系统,结果显示其能为 89.8% 的 C 函数生成可编译的 Rust 函数,其中 72% 的函数在符号返回值上与原 C 函数等价。
Rust is a memory-safe programming language that significantly improves software security. Existing codebases written in unsafe memory languages, such as C, must first be transpiled to Rust to take advantage of Rust’s improved safety guarantees. RustAssure presents a system that uses Large Language Models (LLMs) to automatically transpile existing C code-bases to Rust. RustAssure uses prompt engineering techniques to maximize the chances of the LLM generating idiomatic and safe Rust code. Moreover, because LLMs often generate code with subtle bugs that can be missed under traditional unit or fuzz testing, RustAssure performs differential symbolic testing to establish the semantic similarity between the original C and LLM-transpiled Rust code. We evaluated RustAssure with five real-world applications and libraries, and showed that our system is able to generate compilable Rust functions for 89.8% of all C functions, of which 72% produced equivalent symbolic return values for both the C and Rust functions.
DOI 原文 ·
@inproceedings{paperbot9561,
title = {RustAssure: Differential Symbolic Testing for LLM-Transpiled C-to-Rust Code},
author = {Yubo Bai and Tapti Palit},
booktitle = {ASE},
year = {2025},
doi = {10.1109/ase63991.2025.00051}
}