SafeTrans: LLM-assisted Transpilation from C to Rust
Muhammad Farrukh, Baris Coskun, Tapti Palit, Michalis Polychronakis

TL;DR
This paper explores using large language models to automate the translation of C code into Rust, improving success rates through iterative error repair and analyzing security implications.
Contribution
It introduces SafeTrans, a framework utilizing LLMs with guided repair techniques for C-to-Rust transpilation, and evaluates its effectiveness on large codebases.
Findings
Iterative repair increases successful translation rate from 54% to 80%.
SafeTrans effectively leverages LLMs for automated code transpilation.
Some C vulnerabilities persist in the translated Rust code.
Abstract
Rust is a strong contender for a memory-safe alternative to C as a "systems" language, but porting the vast amount of existing C code to Rust remains daunting. In this paper, we evaluate the potential of large language models (LLMs) to automate the transpilation of C code to idiomatic Rust. We present SafeTrans, a generic framework that leverages LLMs to i) transpile C code into Rust, and ii) iteratively repair compilation and runtime errors. A key novelty of our approach is a few-shot guided repair technique for translation errors, which provides contextual information and example code snippets for specific error types, guiding the LLM toward the correct solution. Another novel aspect of our work is the evaluation of the security implications of the transpilation process, showing how some vulnerability classes in C persist in the translated Rust code. SafeTrans was evaluated with six…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
