arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2501.18160cs.SEcs.PL
收藏

RepoAudit:用于仓库级代码审计的自主 LLM-Agent

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

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

AI总结:

本文提出自主 LLM 智能体 RepoAudit,通过按需探索代码库并验证数据流事实与路径条件来缓解幻觉,实现高效且低成本的仓库级代码审计,在真实项目中精准检出大量已知与新 bug。

摘要:

代码审计是以识别 bug 为目的的代码审查过程。大型语言模型(LLMs)在此任务中展现出了可期的能力,无需编译即可运行,同时支持用户友好的定制。然而,使用 LLMs 审计代码仓库面临重大挑战:有限的上下文窗口和幻觉会降低 bug 报告的质量,且分析大规模仓库会产生大量的时间和 token 成本,阻碍了效率和可扩展性。本工作引入了一个基于 LLM 的智能体 RepoAudit,旨在执行自主的仓库级代码审计。RepoAudit 配备了智能体记忆,通过分析单个函数内可行程序路径上的数据流事实,按需探索代码库。它还进一步整合了验证器模块,通过验证数据流事实并检查与潜在 bug 相关的路径条件的可满足性来缓解幻觉,从而减少误报。RepoAudit 在 15 个真实世界基准项目中检测出 40 个真实 bug,准确率为 78.43%,平均每个项目仅需 0.44 小时和 2.54 美元。此外,它还在知名项目中检测出 185 个新 bug,其中 174 个已被确认或修复。我们已在 https://github.com/PurCL/RepoAudit 开源了 RepoAudit。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑