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

Crustify：LLMエージェントとカバレッジ誘導テストによる、リポジトリ単位の安全なRustバインディング生成

Marius Momeu, Marius Arvinte, Cory Cornelius, Koushik Sen · arXiv · 2026年11月7日

- **課題** Cライブラリの安全なRustバインディングは、unsafeな内部実装がUBを起こしやすいため、これまで手作業で書かれてきました。
- **手法** Crustifyは、依存関係の順序に沿ったバッチを複数のエージェントが同時にバインディングする手法です。ffiboxの基本要素、Wavefrontのスケジューリング、ffimapの測定を組み合わせ、カバレッジ誘導テストとレビューで検証します。
- **結果** libgit2とffmpegの評価では、公開APIの41.9%と42.8%をラップしました。利用者向けインターフェースのunsafe関数の割合は、libgit2が1.6%、ffmpegが0.4%でした。

## 安全なRustバインディングが難しい理由

Cライブラリを安全なRustインターフェースで包むことで、Rustアプリケーションは、unsafeなコードを直接書かずにCのコードを使えるようになります。しかし、このようなバインディングは書くのが難しく、誤りも起きやすいです。内部実装ではRustコンパイラが検査しないunsafeなコードを使うため、一度の誤りで未定義動作（UB）が起きることがあります。これまで、こうしたバインディングの多くは手作業で書かれてきました。論文では、既存のオープンソースのバインディングは数年にわたって作られてきたものの、元のAPI全体はカバーできていないと報告しています。さらに、FFI境界を越える型やポインタを表現する、広く採用された共通の基本要素もないため、プロジェクトごとに独自の変種が書かれています。

## Crustifyの構成とエージェントのワークフロー

Crustifyは、Cのリポジトリから安全なRustクレートを作る、エージェントによる共同変換器です。ユーザーとやり取りするアシスタントエージェントがキャンペーンを進めます。プランナーは対象をモジュールに分け、型とシンボルを依存関係の順序でウェーブと、サイズを制限したバッチにスケジュールします。バインダーは各バッチをバインディングしてテストし、レビュアーは完了したウェーブについて、UB、等価性の逸脱、カバレッジの空白を監査します。バッチは互いに独立しているため、隔離されたセッションで同時に処理されます。この過程は、3つのツールと共通の仕様が支えています。ffiboxは、Cのメモリを指すRustの参照を作らないという不変条件に従う、C/Rust相互運用の基本要素です。

Wavefrontは、CodeQLで抽出した関係とエージェントの補正表からスケジュールを作る分析器です。ffimapは、バインディングのunsafeな表面を測定する、rustcベースの分析器です。

## ffibox：参照を使わずに所有権を表す基本要素

ffiboxは、Box、Arc、Vecに対応する、C言語のオブジェクト用の所有者を提供します。CBoxはポインタの先にあるオブジェクトの単独の所有者です。CArcは複数の所有者が共有する参照カウントの所有者です。CValはオブジェクトをインラインで保持し、ドロップ時にリソースを解放します。各ポリシーPは、オブジェクトを解放するCのルーチンと、必要に応じて割り当てと複製のルーチンの組を名前で指定します。借用は、Fooの参照ではなく、ライフタイムを持つハンドルFooRefとFooMutで表し、このハンドルは生ポインタを通してフィールドにアクセスします。したがって、Cがエイリアスを持ちうるメモリに対する&や&mutは生成されません。

スレッド間の共有（SendとSync）はデフォルトで禁止されており、明示的な安全性の論証でのみ許可されます。

![Table 1: ffiboxprimitives and the standard-library counterparts whose interfaces they mirror](https://refivu.com/papers/0a929076-bec9-4572-90ad-a8b133795903/figures/figure-a79a5930fbd4a5f304eeb7472c5edc51.png?thumb=512)

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

[出典](https://arxiv.org/abs/2611.10394v1) · [CC BY 4.0](https://creativecommons.org/licenses/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 · 論文の図を引用 · 元のPDFの8ページ目から図の部分を抽出しています。

## Wavefront：隠れた依存関係をたどるバッチのスケジューリング

Cのコードでは、キャストと型消去されたvoid \*スロットが型どうしの依存関係を隠しており、大きなリポジトリでは依存関係の循環も生じます。Wavefrontは、CodeQLのデータベースから、フィールドの型、シグネチャ、呼び出し、構造体間の直接キャストといった関係を抽出し、型とシンボルの有向グラフを作ります。このグラフで強連結成分を見つけて循環を断ち、モジュールグラフを最長経路で階層化してウェーブを作ります。ひとつのウェーブのバッチどうしは互いに独立しているため、同時に処理できます。判断が必要な関係は、エージェントが補正表に追加または削除します。Wavefrontは、この行が形式的に正しいかだけを確認し、関係そのものが正しいかは確認しません。

そのため、誤った行があっても、フィールドとシグネチャのエッジで定義された順序を破ることはありません。

## ffimap：公開インターフェースのunsafe表面の測定

ffimapは、rustcが型検査の後に読むHIRと推論された型を使い、マクロ展開とcfgによる選択の後のクレートを数えます。また、実際の外部可視性によって公開項目を区別します。一般カウンターは任意のRustクレートに適用でき、公開のunsafe関数と、公開インターフェースの生ポインタを数えます。ffiboxカウンターは、ffiboxの基本要素の使用度合いを測定します。著者らは、ffimapはsoundでもcompleteでもなく、測定箇所を見つけるリンターとして使われると説明しています。特に、生ポインタを通したautoref参照のように見落とすケースがあります。また、seam、as\_ref、as\_mutは名前で照合されるため、名前が異なると数えられないことがあります。

![Table 7: Counts of ffimap and other scanners on our libgit2 bindings and git2-rs.scandenotes cargo-scan, andscan -ecargo-scan with macro expansion](https://refivu.com/papers/0a929076-bec9-4572-90ad-a8b133795903/figures/figure-095a40a733b00b9adb151e9de996b486.png?thumb=512)

**Table 7** . Counts of ffimap and other scanners on our libgit2 bindings and git2-rs.scandenotes cargo-scan, andscan -ecargo-scan with macro expansion.

[出典](https://arxiv.org/abs/2611.10394v1) · [CC BY 4.0](https://creativecommons.org/licenses/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 · 論文の図を引用 · 元のPDFの35ページ目から図の部分を抽出しています。

## テストとサニタイザで健全性の根拠を集める方法

各バッチでは、ラップされた項目について、等価性テスト、安全なコードのUBテスト、unsafeのUBテスト、単体テストを作成します。等価性テストは、C実装とRust APIに対して独立しつつ同等の入力を与え、戻り値や出力引数などを比較します。カバレッジは、C側は計測ビルドで、Rust側は同じテストの実行で測定します。テストコード自体は集計から除外されます。ASan、TSan、UBSanは、テストが実行した経路でメモリエラー、データレースとUBを検出し、MiriはRustコードのUBを、BorrowSanitizerは境界を越えたエイリアス違反を確認します。これらのツールは、テストが実行した経路でのみUBを検出するため、報告がないことは測定されたテストカバレッジによって制限されます。

## レビューのウェーブと欠陥の報告

各バインディングのウェーブの後にはレビューのウェーブが続き、次のウェーブが始まる前に、UB、等価性の逸脱、カバレッジの空白を監査します。レビューは、バインダーとは別のモデルで実行されることがあります。UBや等価性の候補は、Rust APIを通して再現された場合にのみ欠陥と認められます。再現器は修正前にコミットされ、修正後は回帰テストになります。欠陥は、lifecycle、unsafe、obligations、UB、equivalence、internal、conventions、miscのカテゴリに分類されます。カバレッジの空白は報告ではなく、テストで埋められます。レビューは所有権とライフサイクルの記録も検査します。

ただし論文では、このレビューは完全ではないため、残った記録が正しいことを証明するものではないと述べられています。

![Table 5: Review reports per category.UB (safe)andUB (unsafe)are reachable from the safe API and from the unsafeAPI within its contract](https://refivu.com/papers/0a929076-bec9-4572-90ad-a8b133795903/figures/figure-b313ed1074bcb3864a99b062ec440cc1.png?thumb=512)

**Table 5** . Review reports per category.UB (safe)andUB (unsafe)are reachable from the safe API and from the unsafeAPI within its contract.

[出典](https://arxiv.org/abs/2611.10394v1) · [CC BY 4.0](https://creativecommons.org/licenses/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 · 論文の図を引用 · 元のPDFの23ページ目から図の部分を抽出しています。

## libgit2とffmpegの評価結果

2つのキャンペーンは、libgit2の165個の型と981個のシンボル、ffmpegの210個の型と1,128個のシンボルなど、公開APIを対象としました。1人の開発者が両キャンペーンを監督し、キャンペーンはほとんど自律的に進められました。論文は、libgit2では公開APIの41.9%を、ffmpegでは42.8%をラップし、それぞれ約51.9時間と58.9時間かかったと報告しています。テストはRustバインディングのコードの98.92%と99.07%をカバーし、C側では、libgit2の45.95%とlibavutilの67.20%をカバーしました。これらの数値は著者らが両キャンペーンで報告したもので、独立した再測定ではありません。

![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…](https://refivu.com/papers/0a929076-bec9-4572-90ad-a8b133795903/figures/figure-c6df0c05e9c421a38f12cf540045efa3.png?thumb=512)

**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.

[出典](https://arxiv.org/abs/2611.10394v1) · [CC BY 4.0](https://creativecommons.org/licenses/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 · 論文の図を引用 · 元のPDFの19ページ目から図の部分を抽出しています。

![Table 4: Line coverage per test suite at the campaign tips, over the bindings’ non-test sources (Rust) and over libgit2 and libavutil, the only ffmpeg library…](https://refivu.com/papers/0a929076-bec9-4572-90ad-a8b133795903/figures/figure-306652e73ceace042aa2d1126c8174d8.png?thumb=512)

**Table 4** . Line coverage per test suite at the campaign tips, over the bindings’ non-test sources (Rust) and over libgit2 and libavutil, the only ffmpeg library wrapped so far (C).Allis the union of all suites.

[出典](https://arxiv.org/abs/2611.10394v1) · [CC BY 4.0](https://creativecommons.org/licenses/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 · 論文の図を引用 · 元のPDFの22ページ目から図の部分を抽出しています。

## 公開インターフェースのunsafeと生ポインタ

論文は、利用者が使う公開インターフェースで、バインディングの公開関数のうちunsafeの割合が、libgit2では1.6%、ffmpegでは0.4%だったと報告しています。シグネチャに生ポインタを含む割合は、それぞれ0.1%と0.6%です。この測定では、値を変換するseamと、ffiboxのトレイトがunsafeとして宣言したメソッドを除外しています。著者らは、この結果はバインディングがffiboxの基本要素の上に構築されていることを示していると解釈しています。ただし、ラップされていない残りのC関数は、この表面には含まれません。

![Table 3: ffiboxuse in the bindings, over the C functions and structs of the wrapped library’s-syscrate](https://refivu.com/papers/0a929076-bec9-4572-90ad-a8b133795903/figures/figure-3b8a3f3c5aa3c42286547dbe47e228fa.png?thumb=512)

**Table 3** .ffiboxuse in the bindings, over the C functions and structs of the wrapped library’s-syscrate.

[出典](https://arxiv.org/abs/2611.10394v1) · [CC BY 4.0](https://creativecommons.org/licenses/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 · 論文の図を引用 · 元のPDFの21ページ目から図の部分を抽出しています。

## 適用範囲と限界

著者らは、Crustifyの安全性と健全性の根拠は経験的なものであり、テストカバレッジによって制限されると説明しています。ffimapはリンターなので、参照の数とffibox以外の基本要素を、いずれも見落とすことがあります。レビューは欠陥を見つけますが、欠陥がないことは示せません。プロンプトとゲートはキャンペーンの途中でも修正され、1人の開発者が監督したため、初期のウェーブはより緩いルールで実行されました。各バッチは一度だけ実行されており、LLMエージェントは非決定的なので、繰り返すと別のバインディングが生成されることがあります。また、ffiboxは、ベクターの要素がメモリを所有する場合や、Cがポインタとカウントで配列をその場で拡張する場合を、まだ表現できません。

## 論文情報

- **著者**: Marius Momeu, Marius Arvinte, Cory Cornelius, Koushik Sen
- **学会・ジャーナル**: arXiv · プレプリント
- **公開日**: 2026年11月7日
- **登録日**: 2026年11月10日
- **更新日**: 2026年11月7日
- **バージョン**: v1
- **arXiv**: 2611.10394
- **カテゴリ**: cs.PL · cs.AI · cs.CR · cs.SE
- **ライセンス**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **掲載内容**: 論文情報・解説・論文の図

[元論文 ↗](https://arxiv.org/abs/2611.10394v1) · [PDF ↗](https://arxiv.org/pdf/2611.10394v1)

この解説は、Refivuの韓国語解説をAIで翻訳したものです。不正確な翻訳や誤りが含まれる可能性があります。論文と図の利用条件は各出典に従います。

## アブストラクト

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.

## この論文を引用

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}
}
```

## ほかの論文解説

- [ENGRAM: From Agent Experience to Weights through Verified Consolidation](https://refivu.com/ja/papers/92981c9d-bb4e-4de2-a3a5-e8f34c36711e-engram-from-agent-experience-to-weights-through-verified.md)
- [ToolDex: An Ego-Exo Human Demonstration Dataset for Creative Physical Tool Use](https://refivu.com/ja/papers/f7963d76-af51-4278-9dce-c11b52ed3598-tooldex-an-ego-exo-human-demonstration-dataset-for.md)
- [Nudging Decision Models: Do Digital Nudges Steer Fast, Generation-Free AI Agents?](https://refivu.com/ja/papers/1fea3858-f024-4874-86e7-716dc535b549-nudging-decision-models-do-digital-nudges-steer-fast.md)
- [Authorization Drift in LLM Agents: Evaluating Boundary Compliance in Multi-Step Tool Use](https://refivu.com/ja/papers/a4c68078-7f50-4a42-8a7d-338f8d11d103-authorization-drift-in-llm-agents-evaluating-boundary.md)
- [Test-Time Compute Scales Better with Parallel Agent Teams](https://refivu.com/ja/papers/64aa4da2-a253-4014-ad8f-766a6ed0fbee-test-time-compute-scales-better-with-parallel-agent.md)
- [Knowing When to Intervene: Causal Evaluation of AI Agents](https://refivu.com/ja/papers/9bf91b2d-0310-4784-8e07-bc56e3e1a1a6-knowing-when-to-intervene-causal-evaluation-of-ai.md)
- [Policy Over Purpose: Auditing LLM Content Moderation of Reclaimed Slur Usage](https://refivu.com/ja/papers/0bd6d771-d8cc-4509-b0e6-0634c7f25539-policy-over-purpose-auditing-llm-content-moderation-of.md)
- [ScreenProof: Where Is This Screen Wrong? Finding UI Faults Without a Reference](https://refivu.com/ja/papers/0dcfcae6-d73a-4ed2-99f5-ffc88e29026b-screenproof-where-is-this-screen-wrong-finding-ui.md)
- [BO-Arena: An Evolving Benchmark for High-Dimensional Bayesian Optimisation](https://refivu.com/ja/papers/ac0c04c7-34c7-4776-83da-4025fd35cf2c-bo-arena-an-evolving-benchmark-for-high-dimensional.md)
- [Enmo Safety: External, Non-invasive, Model-agnostic Oversight for Off-the-Shelf Language Models](https://refivu.com/ja/papers/43a652d5-97dd-4387-96e9-9b8608824ca2-enmo-safety-external-non-invasive-model-agnostic-oversight.md)
- [All Quiet on the Neural Front: Language Models Do Not Report Injected Pain States](https://refivu.com/ja/papers/04b68ddc-9ed8-4013-9cd0-43c33d59ed84-all-quiet-on-the-neural-front-language-models.md)
- [Homeopathic Learning: Diluting poisoned fine-tuning data can strengthen its effect](https://refivu.com/ja/papers/bb9e7cb2-b5b7-422c-9ec7-d1cc5d9456c2-homeopathic-learning-diluting-poisoned-fine-tuning-data-can.md)

---

AI解説には誤りが含まれることがあります。 [Refivu](https://refivu.com/ja/papers/0a929076-bec9-4572-90ad-a8b133795903-crustify-repository-level-generation-of-safe-rust-bindings)
