# 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, 등가성 편차와 커버리지 공백에 대해 감사합니다. 배치는 서로 독립이므로 격리된 세션에서 동시에 처리됩니다. 이 과정은 세 도구와 공통 사양에 의해 뒷받침됩니다. 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 코드에서는 캐스트와 type-erased void \* 슬롯이 타입 사이의 의존성을 숨기고, 큰 저장소에서는 의존성 순환도 생깁니다. Wavefront는 CodeQL 데이터베이스에서 필드 타입, 시그니처, 호출, 구조체 간 직접 캐스트 같은 관계를 추출해 타입과 심볼의 방향 그래프를 만듭니다. 이 그래프에서 강연결 성분을 찾아 순환을 끊고, 모듈 그래프를 최장 경로로 계층화하여 웨이브를 만듭니다. 한 웨이브의 배치들은 상호 독립이라 동시에 처리할 수 있습니다. 판단이 필요한 관계는 에이전트가 보정 표로 추가하거나 제거하는데, Wavefront는 이 행이 형식적으로 올바른지만 확인하고 관계 자체가 맞는지는 확인하지 않습니다.

그래서 잘못된 행이 있더라도 필드와 시그니처 간선에 의해 정의된 순서를 어기지는 못합니다.

## ffimap: 공개 인터페이스의 unsafe 표면 측정

ffimap은 rustc가 타입 검사 후 읽는 HIR과 추론된 타입을 사용하여, 매크로 확장과 cfg 선택 이후의 크레이트를 세고 실제 외부 가시성으로 공개 항목을 구분합니다. 일반 카운터는 어떤 Rust 크레이트에도 적용되며 공개 unsafe 함수와 공개 인터페이스의 raw 포인터를 셉니다. ffibox 카운터는 ffibox 기본 요소의 사용 정도를 측정합니다. 저자들은 ffimap이 sound하거나 complete하지 않으며 측정 지점을 찾는 린터로 쓰인다고 밝힙니다. 특히 raw 포인터를 통한 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쪽에서 그림 영역을 추출했습니다.

## 테스트와 sanitizer로 건전성 근거를 모으는 방법

각 배치는 wrapper된 항목에 대해 등가성 테스트, 안전 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 평가 결과

두 캠페인은 libgit2의 165개 타입과 981개 심볼, ffmpeg의 210개 타입과 1,128개 심볼 등 공개 API를 대상으로 했습니다. 한 명의 개발자가 두 캠페인을 감독했으며 캠페인은 대부분 자율적으로 진행되었습니다. 원문은 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와 raw 포인터

원문은 소비자가 사용하는 공개 인터페이스에서 바인딩 공개 함수 중 unsafe인 비율이 libgit2에서 1.6%, ffmpeg에서 0.4%라고 보고합니다. raw 포인터가 시그니처에 있는 비율은 각각 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 밖의 기본 요소를 모두 놓칠 수 있습니다. 리뷰는 결함을 찾지만 그 부재를 보이지 않습니다. 프롬프트와 게이트는 캠페인 중에도 수정되었고 한 명의 개발자가 감독했으므로, 초기 웨이브는 더 느슨한 규칙에서 실행되었습니다. 각 배치는 한 번만 실행되었으며 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)

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

## 이 논문의 용어

- [wavefront](https://refivu.com/terms/0711b922b4b9-wavefront)

## 다른 논문 해설

- [ENGRAM: From Agent Experience to Weights through Verified Consolidation](https://refivu.com/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/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/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/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/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/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/papers/0bd6d771-d8cc-4509-b0e6-0634c7f25539-policy-over-purpose-auditing-llm-content-moderation-of.md)
- [Do large language models rank moral values? A transitivity test of moral competence](https://refivu.com/papers/29f72fc7-e4da-43f9-b5ac-537ccc003552-do-large-language-models-rank-moral-values-a.md)
- [ScreenProof: Where Is This Screen Wrong? Finding UI Faults Without a Reference](https://refivu.com/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/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/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/papers/04b68ddc-9ed8-4013-9cd0-43c33d59ed84-all-quiet-on-the-neural-front-language-models.md)

---

AI 해설에는 오류가 있을 수 있습니다. [Refivu](https://refivu.com/papers/0a929076-bec9-4572-90ad-a8b133795903-crustify-repository-level-generation-of-safe-rust-bindings)
