RepoAudit: An Autonomous LLM-Agent for Repository-Level Code Auditing

Jinyao Guo, Chengpeng Wang, Xiangzhe Xu, Zian Su, Xiangyu Zhang

TL;DR

REPOAUDIT is a purely LLM-driven, compilation-free code auditing agent that mimics how human experts review large software repositories. By combining demand-driven graph traversal, localized program abstraction, and multi-perspective validation, it bypasses the context-window limitations and path-explosion problems that cripple standard LLM prompting. In testing, it uncovered 185 new bugs in high-profile open-source projects with high precision, costing just a few dollars per repository.

What Problem Does This Paper Address?

Finding critical vulnerabilities—like Null Pointer Dereferences (NPD), Memory Leaks (MLK), and Use-After-Free (UAF) errors—requires tracking how data flows across an entire software repository. Traditional static and dynamic analysis tools struggle here because they depend heavily on successful code compilation and execution, which is rarely guaranteed during active development.

While Large Language Models (LLMs) are great at understanding code snippets without compilation, they fail miserably when handed an entire repository. If you pass a whole codebase to an LLM, you run into context window limits, massive token costs, and severe hallucinations. Furthermore, repository-level code is essentially a massive graph of interconnected functions and statements. Trying to find bugs via direct prompting triggers a "path explosion" problem, where the number of possible execution paths grows exponentially, causing the LLM to lose track and report high rates of false positives.

Methods

REPOAUDIT solves this by abandoning the idea of feeding the whole repository to the LLM at once. Instead, it acts as an autonomous agent that navigates the codebase function-by-function on demand, mimicking a human auditor.

The architecture of REPOAUDIT, consisting of an Initiator, Explorer, Validator, and Agent Memory.

The system consists of three core components backed by an Agent Memory:

  1. The Initiator: Uses lightweight tree-sitter parsing to identify potential bug sources (e.g., where a pointer is initialized to NULL).
  2. The Explorer: Starting from a source, the Explorer queries the LLM to analyze one function at a time. It prompts the LLM to perform program abstraction (stripping away irrelevant code) and pointer handling to map out feasible data-flow paths. If the data-flow escapes the function boundary (via a return value or parameter), the Explorer dynamically follows the call graph to the next relevant function.
  3. The Validator: To eliminate LLM hallucinations, a dual-validation mechanism is used. First, a parsing-based tool ensures the LLM's reported data-flow aligns with the actual control flow. Second, the LLM is prompted to cross-examine the inter-procedural path conditions to ensure they are logically satisfiable and don't contradict each other.

An example of how REPOAUDIT tracks an NPD bug across multiple functions and files is illustrated below:

Figure 1. A simplified code snippet from the project sofa-pbrpc contains a real NPD bug found by REPOAUDIT. The blue dashed arrows indicate the edges in the call graph. The red solid arrows show the data-flow facts indicating the null value propagation. The call graph of the project contains 1,508 nodes and 6,196 edges, while its data dependence graph contains 160,875 nodes and 360,096 edges.

Datasets

The authors evaluated REPOAUDIT using two main datasets:

  • Historical Benchmark: A collection of 15 real-world open-source projects (averaging 251,000 lines of code each) containing previously documented NPD, MLK, and UAF bugs.
  • Wild Dataset: 9 actively maintained, high-profile open-source GitHub repositories spanning diverse domains, including clickhouse-odbc, htop, nginx, memcached, and Redis.

Key Insights and Ideas

  • Leveraging Local Strengths for Global Problems: LLMs are bad at global graph reasoning but remarkably good at localized intuition (like abstracting a single function or resolving pointer targets). REPOAUDIT structures the agent workflow so the LLM only ever has to reason within a single function scope at any given time.
  • Demand-Driven vs. Exhaustive Analysis: Previous LLM-based static analyzers tried to generate data-flow summaries for every function in a repository. REPOAUDIT only analyzes functions on a need-to-know basis, following the active propagation of a suspected bug. This makes it orders of magnitude cheaper and faster.
  • Neuro-Symbolic Synergy: Purely LLM-driven auditing suffers from hallucinations, while purely symbolic auditing suffers from rigid compilation requirements. By using lightweight syntax parsing to constrain and validate the LLM's semantic leaps, REPOAUDIT achieves industrial-grade precision without needing a compiler.

Key Results

REPOAUDIT was initially powered by Claude 3.5 Sonnet and compared against industrial tools and alternative LLM approaches:

  • Accuracy: On the historical benchmark, it successfully reproduced all 21 known bugs and found 19 new ones, achieving a precision of 78.43%.
  • Baselines: It significantly outperformed industrial static analyzers. Meta INFER only found 7 true bugs (and crashed on several projects due to compilation issues), while Amazon CodeGuru flagged 18 false positives and 0 true bugs. It also vastly outperformed naive single-function and multi-function LLM prompting baselines.
Comparison of REPOAUDIT against single-function and multiple-function LLM bug detectors.
  • Efficiency: Code auditing took an average of just 0.44 hours and cost $2.54 in API tokens per project.
  • Real-World Impact: When deployed on active repositories, REPOAUDIT discovered 185 new bugs, of which 95 have already been confirmed by developers and 79 fixed.
  • Reasoning Models: Upgrading the agent's brain to newer reasoning models like DeepSeek R1 and Claude 3.7 Sonnet pushed precision even higher, reaching 88.46% and 86.79% respectively.

Limitations and Future Work

Despite its success, REPOAUDIT has a few limitations:

  • Source Sensitivity: The tool's token cost and execution time scale with the number of initial starting points identified by the Initiator. A repository with thousands of potential sources will see a steep rise in overhead.
  • Bounded Context: To prevent infinite loops and excessive costs, the authors capped the inter-procedural analysis depth to 4 functions ($K=4$). Consequently, bugs buried across exceptionally long call chains may be missed.

Future work includes integrating compilation-free retrieval tools to better map out complex loops and branches, as well as fine-tuning smaller, open-source models specifically for the localized function abstraction tasks.

Summary updated

Abstract

Code auditing is the process of reviewing code with the aim of identifying bugs. Large Language Models (LLMs) have demonstrated promising capabilities for this task without requiring compilation, while also supporting user-friendly customization. However, auditing a code repository with LLMs poses significant challenges: limited context windows and hallucinations can degrade the quality of bug reports, and analyzing large-scale repositories incurs substantial time and token costs, hindering efficiency and scalability. This work introduces an LLM-based agent, RepoAudit, designed to perform autonomous repository-level code auditing. Equipped with agent memory, RepoAudit explores the codebase on demand by analyzing data-flow facts along feasible program paths within individual functions. It further incorporates a validator module to mitigate hallucinations by verifying data-flow facts and checking the satisfiability of path conditions associated with potential bugs, thereby reducing false positives. RepoAudit detects 40 true bugs across 15 real-world benchmark projects with a precision of 78.43%, requiring on average only 0.44 hours and $2.54 per project. Also, it detects 185 new bugs in high-profile projects, among which 174 have been confirmed or fixed. We have open-sourced RepoAudit at https://github.com/PurCL/RepoAudit.
BibTeX
@inproceedings{guo2025repoaudit,
  author = {Jinyao Guo and Chengpeng Wang and Xiangzhe Xu and Zian Su and Xiangyu Zhang},
  title = {{RepoAudit: An Autonomous LLM-Agent for Repository-Level Code Auditing}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=TXcifVbFpG},
}
Figure