Fuzz Driver Synthesis for Rust Generic APIs

Yehong Zhang, Jun Wu, Hui Xu

Abstract

Rust's sophisticated type system, particularly its use of generics and trait bounds, poses a significant hurdle for automated fuzzing. This paper presents RULF+, a tool designed to synthesize valid fuzz drivers for Rust generic APIs. By constructing a Generic API Dependency Graph (GADG) and employing similarity-based pruning, RULF+ effectively navigates the "monomorphic explosion" of types. Evaluation across 29 popular libraries resulted in the discovery of 23 new bugs and a 70% reduction in the search space for monomorphic APIs.

Introduction

Fuzzing is a critical technique for identifying software vulnerabilities by providing random inputs to a program. For libraries, this requires a "fuzz driver"—a small program that interfaces with the library's API. While automated synthesis of these drivers is common for languages like C++, Rust presents unique challenges due to its extensive use of generics. A single generic function can represent an infinite number of concrete monomorphizations, making exhaustive testing impossible and type-correct synthesis difficult.

The Challenge: Generics and Monomorphization

Existing fuzzing tools often struggle with Rust's strict trait bounds. If a tool selects a concrete type that does not satisfy the required traits for a generic parameter, the resulting driver fails to compile. Furthermore, the sheer volume of possible type combinations leads to a "monomorphic explosion," where the computational cost of testing every version of a generic API becomes prohibitive.

The RULF+ Methodology

To address these issues, RULF+ introduces a two-stage approach to generate valid and efficient fuzz drivers.

The RULF+ pipeline for generating monomorphic API dependency graphs and pruning redundant implementations.

Modeling Dependencies with GADG

The first stage involves a Reachable Monomorphic API Search. RULF+ constructs a Generic API Dependency Graph (GADG) to model the relationships between APIs and types. Unlike standard dependency graphs, the GADG incorporates "match edges" that link concrete types to the generic parameters they can satisfy based on trait bounds.

The Generic API Dependency Graph (GADG) structure, illustrating producer, consumer, and match edges.

This graph allows the tool to identify "reachable" types—those that can actually be instantiated using the library's existing APIs. By chaining these calls, RULF+ ensures that the generated fuzz drivers are not only type-correct but also executable within the library's intended usage patterns.

Similarity Pruning

The second stage tackles the monomorphic explosion through Similarity Pruning. The authors observed that many different concrete types share the same underlying implementation for a trait (e.g., via blanket or default implementations). Testing multiple types that trigger the same logic is redundant. RULF+ uses a greedy set-cover algorithm to select a minimal set of monomorphic APIs that cover all unique trait implementations, significantly streamlining the fuzzing process.

Experimental Evaluation

The researchers evaluated RULF+ on 29 popular open-source Rust libraries, including high-profile crates like serde_json, regex, and axum-core. The tool demonstrated remarkable effectiveness:

  • Bug Discovery: RULF+ identified 23 previously unknown bugs, 18 of which were specific to generic APIs. These included critical issues such as arithmetic overflows and infinite loops.
  • Efficiency: Similarity pruning reduced the number of monomorphic APIs by 70% (from 6,371 to 1,911) without compromising bug-finding capabilities.
  • Validity: 96% of the generated drivers compiled successfully, despite the complexity of Rust's type system.

Key Insights and Limitations

A major insight of this work is that reachability is as important as type correctness; a fuzzer must be able to produce the types it consumes. Additionally, focusing on trait implementations rather than concrete types provides a powerful heuristic for pruning the search space.

However, RULF+ has limitations. It currently struggles with "third-party type blindness," where it cannot instantiate types defined in external crates. It also employs an "unsound" trait bound checker—a deliberate trade-off that allows for broader API exploration at the cost of a small percentage (4%) of compilation failures. Future work will focus on cross-crate analysis to improve coverage for complex frameworks.

Conclusion

RULF+ represents a significant advancement in automated testing for Rust. By specifically addressing the complexities of generics and trait bounds, it enables deep fuzzing of libraries that were previously difficult to test automatically, ultimately contributing to a more secure and robust Rust ecosystem.

Summary updated

BibTeX
@article{zhang2025fuzz,
  author = {Yehong Zhang and Jun Wu and Hui Xu},
  title = {{Fuzz Driver Synthesis for Rust Generic APIs}},
  journal = {ACM Trans. Softw. Eng. Methodol.},
  year = {2025},
  doi = {10.1145/3709359},
}
Figure