about
Syzygy: Dual Code-Test C to Rust Translation Using LLMs and Dynamic Analysis (arxiv.org)
7 points by belter on Dec 30, 2024 | hide | past | pdf | 2 comments on HN

In plain words: It converts C to memory-safe Rust by having an AI translate code and tests together, guided by traces from running the original. It handled a 3,000-line compression library whose behavior matched the C version on test inputs, the largest automated, test-checked conversion yet.

Abstract · Syzygy: Dual Code-Test C to (safe) Rust Translation using LLMs and Dynamic Analysis

Despite extensive usage in high-performance, low-level systems programming applications, C is susceptible to vulnerabilities due to manual memory management and unsafe pointer operations. Rust, a modern systems programming language, offers a compelling alternative. Its unique ownership model and type system ensure memory safety without sacrificing performance. In this paper, we present Syzygy, an automated approach to translate C to safe Rust. Our technique uses a synergistic combination of LLM-driven code and test translation guided by dynamic-analysis-generated execution information. This paired translation runs incrementally in a loop over the program in dependency order of the code elements while maintaining per-step correctness. Our approach exposes novel insights on combining the strengths of LLMs and dynamic analysis in the context of scaling and combining code generation with testing. We apply our approach to successfully translate Zopfli, a high-performance compression library with ~3000 lines of code and 98 functions. We validate the translation by testing equivalence with the source C program on a set of inputs. To our knowledge, this is the largest automated and test-validated C to safe Rust code translation achieved so far.

Manish Shetty, Naman Jain, Adwait Godbole, Sanjit A. Seshia, Koushik Sen
arXiv:2412.14234 · cs.SE, cs.AI, cs.LG, cs.PL · submitted Dec 18, 2024 · updated Dec 21, 2024
abstract · pdf · html · Project webpage at https://syzygy-project.github.io/. Preliminary version accepted at LLM4Code 2025, 34 pages

add comment on HN
Also discussed: Dec 2024 (4 points, 0 comments)

Very interesting. I am wondering about the "level of translation". Is it using plain safe Rust or is it full of unsafe functions everywhere.

I planned to port LMDB to Rust by hand "just to see" and it was an awful work. There are too many defines and conditional compilations due to the nature of the work: interfacing different OS to write an on-disk B+Tree...

Hi, I'm one of the authors on the paper! The translation is to safe Rust and is expected to not contain any `unsafe` constructs. Regarding, rewriting LMDB: seems like an interesting case study to consider for us in the future.