CRUST-Bench: A Comprehensive Benchmark for C-to-safe-Rust Transpilation

Anirudh Khatry, Robert Zhang, Jia Pan, Ziteng Wang, Qiaochu Chen, Greg Durrett, Isil Dillig

TL;DR

Migrating C code to safe Rust is crucial for modernizing software and improving security, but existing benchmarks fall short. This paper introduces CRUST-Bench, a new dataset of 100 C repositories with Rust interfaces and tests, designed to rigorously evaluate C-to-Rust transpilation. Even state-of-the-art LLMs struggle with this task, highlighting the complexity of generating safe and idiomatic Rust from legacy C code.

What Problem Does This Paper Address?

The world runs on C code, but C's notorious memory safety issues make it a liability. Rust offers a compelling alternative with its strong compile-time guarantees, but migrating existing C codebases to safe Rust is a significant challenge. Current C-to-Rust transpilation tools and benchmarks often focus on isolated functions, lack robust correctness validation, or produce "unsafe" Rust that bypasses Rust's safety features. This leaves a critical gap: a lack of comprehensive evaluation methods for generating safe, idiomatic Rust from real-world, multi-file C projects with dependencies.

Methods

The core of this work is the creation of CRUST-Bench, a new benchmark designed to address the limitations of prior efforts. It consists of:

  • 100 C repositories: These are real-world projects, not just isolated functions, chosen for their diversity and compilability.
  • Manually-written safe Rust interfaces: These act as formal specifications, defining function signatures, types, and ownership rules that the transpiled Rust code must adhere to. This ensures idiomatic and memory-safe Rust output.
  • Corresponding Rust test cases: These validate the functional correctness of the transpiled code, ensuring it behaves as expected.

The authors then use this benchmark to evaluate various Large Language Models (LLMs), including single-shot attempts and iterative "self-repair" strategies (compiler repair and test repair). They also explore agent-based approaches like SWE-agent.

Datasets

The primary contribution is the introduction of CRUST-Bench, a new benchmark comprising 100 C repositories. This dataset is unique in its focus on:

  • Repository-scale projects: Unlike previous benchmarks that used isolated functions, CRUST-Bench includes entire projects with inter-file dependencies.
  • Explicit safe Rust interfaces: These are crucial for guiding LLMs towards idiomatic and memory-safe Rust, a key differentiator from benchmarks that might accept any valid Rust output.
  • Correctness-enforcing test cases: These ensure functional equivalence and adherence to the specified Rust interfaces.

Key Insights and Ideas

  • "Safe Rust" is the hard part: While transpiling C to any Rust is becoming more feasible with LLMs, generating safe and idiomatic Rust that adheres to strict interfaces remains a significant hurdle.
  • Repository-scale is crucial: Isolated function transpilation doesn't capture the complexity of real-world projects with dependencies, which CRUST-Bench aims to address.
  • Iterative repair helps, but has limits: Self-repair strategies (using compiler errors and test failures) significantly boost success rates for LLMs, but performance plateaus. Test repair offers further gains but can sometimes decrease build stability.
  • Agent-based systems show promise but don't outperform: Pipelined SWE-agent can navigate and attempt repairs, but in this context, it didn't consistently outperform a well-tuned LLM with test repair.
  • Common LLM errors are predictable: Mismatch, borrowing, and type-related errors are prevalent, highlighting LLMs' ongoing struggles with Rust's strict type system and ownership rules.

Key Results

  • Low single-shot performance: Even the best LLM (OpenAI o3) could only solve 19% of tasks in a single-shot setting. Claude Opus 4 achieved the highest pass@1 rate at 22%.
  • Self-repair significantly improves results: With three rounds of test repair, the best model (OpenAI o3) reached a 48% pass rate.
  • SWE-agent shows potential but not superiority: Pipelined SWE-agent improved performance to 32% (for Claude 3.7 Sonnet), but this matched the performance of Claude 3.7 Sonnet with test repair, not exceeding it.
  • Error analysis reveals challenges: Mismatch and borrowing errors were the most common, indicating LLMs struggle with Rust's strict type and ownership rules. Unimplemented functions were also frequent, often due to token limits.

Limitations and Future Work

  • LLM performance is still limited: Even the best models struggle to achieve high success rates, indicating that fully automated, safe C-to-Rust transpilation is still an open challenge.
  • Test coverage: While CRUST-Bench includes tests, achieving significantly higher coverage would require more extensive manual effort.
  • Future work directions: The authors suggest that incorporating static analysis signals into LLM fine-tuning could improve their ability to generate compilable, type-correct Rust code. Further research into more effective self-repair strategies and agent-based approaches is also warranted.

Summary updated

BibTeX
@inproceedings{khatry2025crust,
  author = {Anirudh Khatry and Robert Zhang and Jia Pan and Ziteng Wang and Qiaochu Chen and Greg Durrett and Isil Dillig},
  title = {{CRUST-Bench: A Comprehensive Benchmark for C-to-safe-Rust Transpilation}},
  booktitle = {COLM},
  year = {2025},
  url = {https://openreview.net/forum?id=8xofWL61S9},
}
Figure