Why C-to-Rust validation matters

Migrating C codebases to Rust is a promising approach to securing legacy software, but existing translators do not guarantee that a translated Rust program preserves the behavior of the C program. Neither rule-based nor large language model based translators have been formally verified, and existing approaches to checking translation correctness are limited to testing and bounded checks, which cannot reason about all possible executions.

The R2C2 approach

In this work, we present R2C2, which validates C-to-Rust translation by proving in Rocq that the Rust program refines the C program, i.e., every behavior on the Rust side is also a behavior on the C side. Since no formal semantics defines the behaviors of C and Rust programs in the same terms, we prove refinement between the two programs compiled to the LLVM intermediate representation LLVM IR. In addition, to resolve the discrepancies between the data representations of C and Rust, we introduce a common abstraction that relates two corresponding representations through an abstract value, and specify the behavior of each library function over abstract values.

How the proof works

We construct the refinement proof as a chain of refinement relations, where only one relation is program-specific and proved at validation time, while the others are proved for all programs in advance. Proof construction is automated by AI agents, and since Rocq checks the proofs, the agents need not be trusted. This approach differs from both purely rule-based translators and LLM-based translators that lack formal guarantees.

Results from the benchmark

We evaluate R2C2 on LLM translations of 519 C programs drawn from a benchmark suite used in prior work on C-to-Rust translation validation. R2C2 proves the translations of 486 programs correct without bounding their executions and discovers three incorrect translations, providing valid counterexamples that existing translation validation tools cannot find. The evaluation demonstrates that the method can handle a substantial portion of a typical benchmark suite while identifying errors that testing and bounded checks miss.

Real-world case study

We also conduct a case study on a small real-world image compression library and demonstrate how R2C2 can handle file operations. The method proves correct the translation of library functions when expressed over abstract values, showing it is not limited to simple benchmark programs.

What this means for developers

For teams migrating C codebases to Rust, R2C2 provides a way to validate that translated programs preserve the semantics of the original C code without requiring bounded test coverage. The method’s ability to discover incorrect translations with valid counterexamples means it can catch bugs that would otherwise remain hidden until runtime or later. The AI-assisted proof construction combined with Rocq verification means the resulting guarantees do not depend on trusting the LLM that generated the translation. As more C codebases undergo migration to Rust, tools like R2C2 could become part of the validation pipeline, giving developers confidence that the migration does not silently change program behavior.