Scylla: Translating an Applicative Subset of C to Safe Rust
2024/12/19 by Aymeric Fromherz, Jonathan Protzenko, Fromherz, Aymeric +1 · 21 voices · 1 citation
#cs.PL
paper · pdf · doi:10.48550/arxiv.2412.15042
Abstract
The popularity of the Rust language continues to explode; yet, many critical codebases remain authored in C. Automatically translating C to Rust is thus an appealing course of action. Several works have gone down this path, handling an ever-increasing subset of C through a variety of Rust features, such as unsafe. While the prospect of automation is appealing, producing code that relies on unsafe negates the memory safety guarantees offered by Rust, and therefore the main advantages of porting existing codebases to memory-safe languages. We instead advocate for a different approach, where the programmer iterates on the original C, gradually making the code more structured until it becomes eligible for compilation to safe Rust. This means that redesigns and rewrites can be evaluated incrementally for performance and correctness against existing test suites and production environments. Compiling structured C to safe Rust relies on the following contributions: a type-directed translation from (a subset of) C to safe Rust; a novel static analysis based on "split trees" which allows expressing C's pointer arithmetic using Rust's slices and splitting operations; an analysis that infers which borrows need to be mutable; and a compilation strategy for C pointer types that is compatible with Rust's distinction between non-owned and owned allocations. We evaluate our approach on real-world cryptographic libraries, binary parsers and serializers, and a file compression library. We show that these can be rewritten to Rust with small refactors of the original C code, and that the resulting Rust code exhibits similar performance characteristics as the original C code. As part of our translation process, we also identify and report undefined behaviors in the bzip2 compression library and in Microsoft's implementation of the FrodoKEM cryptographic primitive.
Cited by
Discussions
- Compiling C to Safe Rust, Formalized [hn, 291 points, 157 comments]
- Compiling C to Safe Rust, Formalized [lobsters, 23 points, 0 comments]
- This will be my birthday gift! A tool written by a french from Inria and someone from Microsoft that can convert C to safe Rust. arxiv.org/abs/2412.15042 [bsky, 5 points, 0 comments]
- Compiling C to Safe Rust, Formalized by Aymeric Fromherz (INRIA), Jonathan Protzenko (Microsoft Research) arxiv.org/abs/2412.15042 [bsky, 5 points, 0 comments]
- arxiv.org/abs/2412.15042 を読んでたらKaRaMeLとかいうトランスレータを知ったのだが、もともとKReMLinという名前だったらしく、あまりにも外聞が悪いということで3年前に改名されたっぽい github.com/FStarLang/ka... [bsky, 2 points, 0 comments]
- Compiling C to Safe #RustLang: arxiv.org/abs/2412.15042 [bsky, 2 points, 0 comments]
- Compiling C to Safe Rust, Formalized (arxiv.org) Main Link | Discussion [bsky, 2 points, 0 comments]
- Aymeric Fromherz and Jonathan Protzenko - Compiling C to Safe Rust, Formalized arxiv.org/abs/2412.15042 [bsky, 2 points, 0 comments]
- 論文はこれ。 [2412.15042] Compiling C to Safe Rust, Formalized arxiv.org/abs/2412.15042 [bsky, 1 points, 0 comments]
- Compiling C to Safe Rust, Formalized https://arxiv.org/abs/2412.15042 [comments] [87 points] [bsky, 0 points, 0 comments]
- Compiling C to Safe Rust, Formalized https://arxiv.org/abs/2412.15042 (https://news.ycombinator.com/item?id=42476192) [bsky, 0 points, 0 comments]
- Compiling C to Safe Rust, Formalized https://lobste.rs/s/1xised #c #rust #compilers [bsky, 0 points, 0 comments]
- arxiv.org/abs/2412.15042 [bsky, 0 points, 0 comments]
- https://arxiv.org/abs/2412.15042 BIG news in the #rust space [bsky, 0 points, 0 comments]
- Compiling #CLang to Safe #Rust, Formalized arxiv.org/abs/2412.15042 [bsky, 0 points, 0 comments]
- Compiling C to Safe Rust, Formalized https://arxiv.org/abs/2412.15042 (https://news.ycombinator.com/item?id=42476192) [bsky, 0 points, 0 comments]
- Compiling C to Safe Rust, Formalized | arxiv.org/abs/2412.15042 [bsky, 0 points, 0 comments]
- Compiling C to Safe Rust, Formalized [Discussion] [bsky, 0 points, 0 comments]
- Compiling C to Safe Rust, Formalized [bsky, 0 points, 0 comments]
- Compiling C to Safe Rust, Formalized https://arxiv.org/abs/2412.15042 https://news.ycombinator.com/item?id=42476192 [bsky, 0 points, 0 comments]
- Compiling C to Safe Rust, Formalized https://arxiv.org/abs/2412.15042 arxiv.org [bsky, 0 points, 0 comments]
Related