SmartC2Rust: 基于大语言模型的迭代反馈驱动C到Rust翻译用于安全性和等价性
SmartC2Rust: Iterative, Feedback-Driven C-to-Rust Translation via Large Language Models for Safety and Equivalence
AI总结:
SmartC2Rust通过迭代反馈机制利用大语言模型实现C到Rust的翻译,提升内存安全性和语义等价性。
摘要:
当今软件系统中内存安全漏洞仍然普遍存在,采用内存安全语言如Rust是缓解这些问题的一种有希望的解决方案。由于遗留代码是用内存不安全的C语言编写的,因此将遗留C代码转换为Rust具有强烈动机。先前的工作已经展示了使用大语言模型(LLMs)进行此类翻译的潜力。然而,基于LLM的翻译仍然存在显著挑战:翻译的代码往往无法编译,更不用说减少不安全语句并保持语义功能,这归因于LLM固有的限制,如有限的token大小和不一致的输出。在本文中,我们设计了一个自动的C到Rust翻译系统,称为SmartC2Rust,用于将C代码分割并转换为Rust,以实现内存安全和语义等价性。关键的洞察是通过迭代细化输出的Rust代码,并利用额外的反馈,例如编译错误、分割上下文、语义差异和内存不安全语句。此类反馈将逐渐提高生成的Rust代码的质量,从而缓解不安全、不一致和语义问题。我们的评估显示,SmartC2Rust显著减少了不安全语句,并在安全性和语义等价性方面优于先前的工作。
英文摘要:
Memory safety vulnerabilities remain prevalent in today's software systems and one promising solution to mitigate them is to adopt memory-safe languages such as Rust. Due to legacy code written in memory unsafe C, there is strong motivation to translate legacy C code into Rust. Prior works have already shown promise in using Large Language Models (LLMs) for such translations. However, significant challenges persist for LLM-based translation: the translated code often fails to compile, let alone reduce unsafe statements and maintain the semantic functionalities due to inherent limitations of LLMs such as limited token size and inconsistent outputs. In this paper, we design an automated C-to-Rust translation system, called SmartC2Rust, to segment and convert the C code to Rust with memory safety and semantic equivalence. The key insight is to iteratively refine the output Rust code with additional feedback, e.g., compilation errors, segmentation contexts, semantic discrepancies, and memory unsafe statements. Such feedback will gradually improve the quality of generated Rust code, thus mitigating unsafety, inconsistency, and semantic issues. Our evaluation shows that SmartC2Rust significantly decreases the unsafe statements and outperforms prior works in security and semantic equivalence.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。