Profile

Settings

Loading…

← Papers

Help

FAQ

Which features require signing in?

You can read the commentary, paper info, Model Structure and related papers of public papers without signing in. Sign in to manage your account or contact us about your inquiries.

Can I upload a PDF file?

Upload papers with an arXiv or DOI link; the commentary is public to everyone. Papers whose source and terms of use can't be verified, so the commentary can't be made public, can't be uploaded. Uploading PDF files and keeping papers private are for subscribers only, and a paper uploaded as a file is saved as private only. Searching for official info by title runs only when you press the button.

Are the figures and AI commentary accurate?

Figures come only from the original paper, and only those whose terms of use are verified are shown. The commentary is written by AI and may be wrong. Check important claims, numbers and figure context against the evidence in the original paper.

I want to report a copyright issue.

Terms of use and the source of the original paper are on the Paper info tab. If there's a problem, choose "Paper content, figures and copyright" under Contact us and send the paper link, the part in question, and evidence that you hold the rights. Receiving your report doesn't confirm any rights or remove anything right away. You can see the result of the review under My inquiries.

I forgot my password.

If you signed up with email, use Forgot password in the sign-in window to reset it with your verified email. If you signed up with Google, Naver or Kakao, change your password with that service.

What should I include in an inquiry?

Tell us which screen you were on and what you were doing when the problem happened, along with the paper link. Don't include personal information such as passwords, API keys, verification codes or phone numbers. Inquiries and replies are stored in Refivu and you can see them under My inquiries.

How do I delete my account?

In Settings, under My account, press Delete account. Review what will be deleted and complete identity verification to delete your account. For other requests, choose "Account" under Contact us.

Paper commentary

Crustify: Repository-Level Generation of Safe Rust Bindings with LLM Agents and Coverage-Guided Testing

Crustify wraps C libraries in safe Rust bindings using LLM agents and coverage-guided tests

  • Problem Hand-written safe Rust bindings over C are tedious and error-prone, because Rust's compiler does not check the unsafe code inside them. A single mistake can cause undefined behavior, and no shared primitives exist for C pointers.
  • Method Crustify is an agentic co-translator that binds C repositories in dependency-ordered waves. Agents derive each pointer's ownership, check bindings with equivalence and sanitizer tests, and a reviewer audits each wave.
  • Results On libgit2, Crustify wrapped 41.9% of the public API in about 51.9 hours with one developer in the loop. Its tests reached 98.92% line coverage of the Rust bindings.

Why safe C bindings keep breaking soundness

A safe binding has to meet two demands at once. It must be sound, so no caller who writes only safe code can cause undefined behavior (UB). It must also be ergonomic, so consumers never handle raw pointers or release C objects by hand. The Rust compiler does not verify soundness at the FFI boundary, so the implementer carries the whole proof.

Most such bindings are still written by hand, and no widely adopted set of primitives exists for C pointers in safe Rust.

The core friction is that Rust's smart pointers assume ownership and aliasing rules that C objects don't follow. A Box adopted from C is released by Rust's allocator rather than the library's own destructor. The same Box hands out &T and &mut T references that the C side may still alias, and the compiler cannot enforce that. Arc keeps its count in a header it allocates itself, while many C objects count references through their own library routines.

Replacing these references with lifetime-bound handles doesn't work, because Deref and DerefMut must return a plain reference. So the problem is a mismatch between Rust's ownership model and C's lifecycle conventions, not one isolated bug pattern.

Testing tools cover only part of this gap. Miri detects UB in Rust code, but it doesn't check the foreign code that it calls.

A pointer layer that never forms a reference into C memory

Owners that mirror Box, Arc, and Vec hand out handles instead, so the C-specific parts stay inside the binding. Consumers then use the familiar Rust idioms, while the C-specific parts stay inside the binding.

Each owner takes a policy that names the release routine and, where they exist, the allocate and clone routines. Because the routines attach to the policy rather than to the type, one type can carry several policies, each a pair of constructor and destructor. Table 1 lists each ffibox primitive beside the standard-library type whose interface it mirrors.

Table 1: ffiboxprimitives and the standard-library counterparts whose interfaces they mirror

Table 1 .ffiboxprimitives and the standard-library counterparts whose interfaces they mirror.

Original paper · CC BY 4.0 · Marius Momeu, Marius Arvinte, Cory Cornelius, Koushik Sen · Crustify: Repository-Level Generation of Safe Rust Bindings with LLM Agents and Coverage-Guided Testing · Original paper figure · Extracted the figure area from page 8 of the original PDF.

For borrowed access, every layout type defines FooRef and FooMut handles, each one pointer wide and tied to the memory it points to. A native &mut would assert uniqueness that C doesn't respect, which is UB.

CCell ties a layout type to its C type and its handles, so generic code reaches C objects only through handles.

How a campaign orders, binds and reviews a C repository

A campaign first decides the order, because a binding can use a type's safe wrapper only after that type is wrapped. C hides many of these dependencies behind casts between struct types and type-erased void * slots, which project-level translators tend to miss. It breaks cycles and places the items into waves of mutually independent, size-bounded batches, and it does no data-flow analysis itself.

Binders wrap and test each batch, and reviewers audit each landed wave. Batches within a wave run concurrently as isolated sessions in separate worktrees.

Before wrapping, each batch derives the ownership and lifecycle properties of its items from the code paths that store, transfer, clone or free each pointer. Where one pointer has several semantics, the batch forks it into one Rust form per semantics. For example, ffmpeg's av_dict_set takes ownership of its strings only when the caller sets a flag.

Each form fixes ownership, mutability, nullability and cardinality in its type, so the compiler checks every use.

Each batch writes equivalence tests that run the C implementation and the Rust API on equivalent inputs. These tests run under Miri, AddressSanitizer, UndefinedBehaviorSanitizer, ThreadSanitizer and BorrowSanitizer, and each instrument checks a different obligation. Line coverage is measured on both sides of the boundary, and tests are added for reachable paths that remain uncovered.

Each binding wave is followed by a review wave that finishes before any dependent wave starts. The reviewers look for undefined behavior, equivalence drift and coverage gaps, and Miri runs over the whole workspace in each review wave. The authors review between waves because a flawed binding would otherwise force breaking changes in every binding that depends on it.

Coverage and defects on libgit2 and ffmpeg

Crustify's two campaigns ran over libgit2 and ffmpeg, whose public APIs have 165 and 210 types and 981 and 1,128 symbols. Crustify wrapped 41.9% of the libgit2 API and 42.8% of the ffmpeg API. The campaigns ran for about 51.9 and 58.9 hours, with one developer checking in between sub-campaigns. They cost $2,308 and $2,120 in tokens, about 5.1 and 4.5 billion of them.

The tests cover 98.92% of the libgit2 Rust bindings and 99.07% of the ffmpeg ones. Against these, git2-rs reached 60.59% Rust line coverage, and the ffmpeg community crates scored at most 18.73%. The authors measured every crate with the same coverage method over the same C, so the numbers share one protocol. Table 2 lists the Rust and C line coverage of each crate side by side.

On the C side, the tests covered 46.78% of libgit2 with its bundled xdiff and llhttp, compared to 45.12% for git2-rs. The ffmpeg C figure of 67.20% covers libavutil alone, the only ffmpeg library wrapped so far. So that figure doesn't describe all of ffmpeg, and the 45.95% libgit2 figure uses libgit2 alone.

Review agents found and fixed 8 defects in the libgit2 bindings and 13 in the ffmpeg bindings. Each of these defects caused UB reachable from Rust, and a reproducer confirmed each one. The paper treats these counts as a lower bound, because review is not exhaustive.

How much unsafe surface remains for consumers

Crustify's bindings keep unsafe code off the interface that consumers use, and Table 2 places them beside git2-rs, ffmpeg-the-third, and ffmpeg-next. On the interface consumers are expected to use, 1.6% and 0.4% of the public functions are unsafe for libgit2 and ffmpeg. That count leaves out the seams and the methods of ffibox's traits that declare unsafe.

Counted over every public function, the libgit2 bindings declare 3.8% unsafe, against 4.1% for git2-rs. The ffmpeg bindings declare 2.4% unsafe, against 3.7% for ffmpeg-the-third and 5.7% for ffmpeg-next.

Table 2: Generated versus community-maintained bindings. Baseline API coverage is an upper bound that
counts every C item the crate’s source names, enums exclu…

Table 2 . Generated versus community-maintained bindings. Baseline API coverage is an upper bound that counts every C item the crate’s source names, enums excluded as for ours; ours counts wrapped items only. libgit2’s C line coverage is over libgit2 with its bundled xdiff and llhttp, which both crates compile, against 45.95% over libgit2 alone (Table 4). Public functions include the methods of trait implementations.

Original paper · CC BY 4.0

Only 0.1% and 0.6% of the public functions have a raw pointer in their signature. For ffmpeg, 14 of those raw-pointer positions store or return opaque user data. The bindings keep that user data visible on purpose, since a bare pointer would otherwise reach the interface without ffibox's primitives. Two libgit2 functions take a raw pointer to a C type the bindings don't wrap yet.

Among the community ffmpeg-next functions, safe constructors such as codec::video::RateIter::new dereference the pointer they receive.

Drop implementations written by hand release C objects in 28.3%, 8.5%, and 10.6% of the community crates' public types. The authors' bindings do this in 5 public libgit2 types, which is 1.3% of them. In ffmpeg, 3 public types, or 0.9%, implement Drop by hand. Those hand-written Drop types are guards over C state, Rust storage that C reads, and collections that CVec cannot represent.

Fewer consumer-facing types release C memory themselves, so consumers don't need to manage C objects by hand.

Behind this interface, unsafe blocks account for 16.6% of the non-test code in each set of bindings. The bindings wrap 86.8% and 95.3% of the C functions that libgit2-sys and libavutil-sys declare. The unsafe surface therefore covers only what the bindings wrap, not the whole C API.

Limitations of the evidence for Crustify's bindings

The ffimap counts are a lower bound, because ffimap is a linter and not a verifier.

Sanitizers and Miri detect undefined behavior only on the paths that the tests execute. A clean run is therefore bounded by the test coverage that the campaigns measure, which is 98.92% and 99.07% of the Rust bindings. Repeated runs may produce different bindings, tests, and review findings, so the authors report one campaign per target rather than averages.

Review finds defects but doesn't show their absence, so the 8 and 13 defects reported are a lower bound.

The authors didn't run a campaign without the developer, so they don't measure how much their checks contributed. The authors stopped using the GPT models because their safety guardrails kept interrupting agents that wrote tests and reproducers for memory-safety violations.

The evaluation covers only libavutil of ffmpeg, the only ffmpeg library wrapped so far. C++ targets and incremental porting remain future work, and ffibox doesn't yet represent vectors whose elements own memory.

Paper info

Authors
Marius Momeu, Marius Arvinte, Cory Cornelius, Koushik Sen
Venue
arXiv · Preprint
First published
2026-11-7
Added
2026-11-10
Updated
2026-11-7
Version
v1
arXiv
2611.10394
Category
cs.PL · cs.AI · cs.CR · cs.SE
Original paper terms
CC BY 4.0
What we show
Paper info, commentary and permitted figures from the original paper

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

Abstract

Wrapping C code in a safe Rust interface lets Rust applications use it without writing unsafe code, until the code itself is migrated to Rust. Such bindings are tedious and error-prone to write, however: their internals use unsafe code that the Rust compiler does not check, so a single mistake can introduce undefined behavior (UB), and they have so far been written mostly by hand. We present Crustify, an agentic co-translator that generates safe Rust bindings for repository-level C libraries. Crustify schedules a target's types and symbols into dependency-ordered waves of independent batches that agents bind concurrently. Its agents derive the ownership and lifecycle contract of every pointer and type they wrap, check each binding with coverage-guided equivalence and UB tests under sanitizers and Miri, and review every wave. They build on three tools that we contribute: (a) ffibox, Rust primitives for C/Rust interop that mirror Box, Arc, and Vec for C objects without ever forming a reference to memory that C may alias; (b) Wavefront, a neuro-symbolic static analyzer that orders a target's items by their dependencies, including those that casts and type-erased pointers hide; and (c) ffimap, a rustc-based analysis that maps the unsafe surface of bindings. On libgit2 and ffmpeg, with one developer in the loop, Crustify generated safe bindings for 41.9% and 42.8% of their public APIs in about 51.9 and 58.9 hours. On the interface consumers are expected to use, only 1.6% and 0.4% of the bindings' public functions are unsafe, and only 0.1% and 0.6% have a raw pointer in their signature. Their tests cover 98.92% and 99.07% of the Rust code and 45.95% and 67.20% of libgit2 and of ffmpeg's libavutil, and the reviewers fixed 8 and 13 defects that caused UB reachable from Rust. To our knowledge, this is the first work to automate the generation of safe Rust bindings for C libraries.

Quote from the paper

Marius Momeu, Marius Arvinte, Cory Cornelius, Koushik Sen (2026). Crustify: Repository-Level Generation of Safe Rust Bindings with LLM Agents and Coverage-Guided Testing. arXiv:2611.10394v1. https://arxiv.org/abs/2611.10394v1

BibTeX
@misc{momeu2026crustify,
  title = {{Crustify: Repository-Level Generation of Safe Rust Bindings with LLM Agents and Coverage-Guided Testing}},
  author = {Marius Momeu and Marius Arvinte and Cory Cornelius and Koushik Sen},
  year = {2026},
  eprint = {2611.10394},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.10394v1}
}

See related papersBrowse other papers

Paper preview
Account security

Connect Google account

If you connect a Google account, you can sign in with it too.

Refivu

Delete account

Refivu
Refivu

Sign up