CRUST-Bench: Un Benchmark Completo per la Traspilazione da C a Rust Sicuro
CRUST-Bench: A Comprehensive Benchmark for C-to-safe-Rust Transpilation
April 21, 2025
Autori: Anirudh Khatry, Robert Zhang, Jia Pan, Ziteng Wang, Qiaochu Chen, Greg Durrett, Isil Dillig
cs.AI
Abstract
La transpilazione da C a Rust è essenziale per modernizzare il codice legacy in C, migliorando al contempo la sicurezza e l'interoperabilità con gli ecosistemi moderni di Rust. Tuttavia, attualmente non esiste un dataset per valutare se un sistema sia in grado di transpilare C in Rust sicuro che superi una serie di test case. Introduciamo CRUST-Bench, un dataset di 100 repository in C, ciascuno abbinato a interfacce scritte manualmente in Rust sicuro e a test case che possono essere utilizzati per validare la correttezza della transpilazione. Considerando interi repository piuttosto che funzioni isolate, CRUST-Bench cattura le sfide della traduzione di progetti complessi con dipendenze tra più file. Le interfacce in Rust fornite offrono specifiche esplicite che garantiscono l'aderenza a pattern idiomatici e sicuri per la memoria, mentre i test case associati impongono la correttezza funzionale. Valutiamo i modelli linguistici di ultima generazione (LLM) su questo compito e scopriamo che la generazione di Rust sicuro e idiomatico rimane un problema impegnativo per vari metodi e tecniche all'avanguardia. Forniamo anche approfondimenti sugli errori che gli LLM commettono solitamente nella transpilazione del codice da C a Rust sicuro. Il modello con le migliori prestazioni, OpenAI o1, è in grado di risolvere solo 15 task in un'impostazione single-shot. Miglioramenti su CRUST-Bench porterebbero a sistemi di transpilazione più avanzati in grado di ragionare su scenari complessi e aiutare nella migrazione di codebase legacy da C a linguaggi come Rust che garantiscono la sicurezza della memoria. È possibile trovare il dataset e il codice all'indirizzo https://github.com/anirudhkhatry/CRUST-bench.
English
C-to-Rust transpilation is essential for modernizing legacy C code while
enhancing safety and interoperability with modern Rust ecosystems. However, no
dataset currently exists for evaluating whether a system can transpile C into
safe Rust that passes a set of test cases. We introduce CRUST-Bench, a dataset
of 100 C repositories, each paired with manually-written interfaces in safe
Rust as well as test cases that can be used to validate correctness of the
transpilation. By considering entire repositories rather than isolated
functions, CRUST-Bench captures the challenges of translating complex projects
with dependencies across multiple files. The provided Rust interfaces provide
explicit specifications that ensure adherence to idiomatic, memory-safe Rust
patterns, while the accompanying test cases enforce functional correctness. We
evaluate state-of-the-art large language models (LLMs) on this task and find
that safe and idiomatic Rust generation is still a challenging problem for
various state-of-the-art methods and techniques. We also provide insights into
the errors LLMs usually make in transpiling code from C to safe Rust. The best
performing model, OpenAI o1, is able to solve only 15 tasks in a single-shot
setting. Improvements on CRUST-Bench would lead to improved transpilation
systems that can reason about complex scenarios and help in migrating legacy
codebases from C into languages like Rust that ensure memory safety. You can
find the dataset and code at https://github.com/anirudhkhatry/CRUST-bench.Summary
AI-Generated Summary