arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2407.14838cs.CRcs.AI
收藏

检索增强生成集成大语言模型在智能合约漏洞检测中的应用

Retrieval Augmented Generation Integrated Large Language Models in Smart Contract Vulnerability Detection

San Francisco State University(旧金山州立大学)

Jeffy Yu

AI总结:

本研究将检索增强生成与大语言模型结合,构建RAG-LLM流水线用于智能合约漏洞检测,在引导和盲审设置下分别取得62.7%和60.71%的成功率,为低成本审计提供概念验证。

摘要:

去中心化金融(DeFi)的快速发展伴随着因智能合约漏洞而导致的巨额财务损失,凸显了有效安全审计的迫切需求。随着攻击日益频繁,审计服务的必要性和需求不断升级。这尤其给独立开发者和中小企业带来了财务负担,他们往往缺乏足够的资金来获取这些服务。我们的研究在现有框架基础上,将检索增强生成(RAG)与大语言模型(LLM)相结合,具体采用GPT-4-1106,利用其128k token的上下文窗口。我们构建了一个包含830个已知漏洞合约的向量存储库,利用Pinecone进行向量存储,使用OpenAI的text-embedding-ada-002进行嵌入,并借助LangChain构建RAG-LLM流水线。提示词被设计为提供漏洞检测的二元答案。我们首先对52个智能合约针对给定的漏洞类型各测试40次,验证RAG-LLM的可复现性和一致性。观察到了令人鼓舞的结果,在引导式漏洞检测中成功率达到62.7%。其次,我们在“盲审”设置下挑战模型,即提示词中不提供漏洞类型,在此设置下219个合约各接受40次测试。该设置评估了在没有提示上下文辅助情况下的通用漏洞检测能力。在这些条件下,观察到的成功率为60.71%。尽管结果令人鼓舞,我们仍强调目前需要人工审计。我们将本研究作为具有成本效益的智能合约审计流程的概念验证,朝着安全访问民主化的方向迈进。

英文摘要:

The rapid growth of Decentralized Finance (DeFi) has been accompanied by substantial financial losses due to smart contract vulnerabilities, underscoring the critical need for effective security auditing. With attacks becoming more frequent, the necessity and demand for auditing services has escalated. This especially creates a financial burden for independent developers and small businesses, who often have limited available funding for these services. Our study builds upon existing frameworks by integrating Retrieval-Augmented Generation (RAG) with large language models (LLMs), specifically employing GPT-4-1106 for its 128k token context window. We construct a vector store of 830 known vulnerable contracts, leveraging Pinecone for vector storage, OpenAI's text-embedding-ada-002 for embeddings, and LangChain to construct the RAG-LLM pipeline. Prompts were designed to provide a binary answer for vulnerability detection. We first test 52 smart contracts 40 times each against a provided vulnerability type, verifying the replicability and consistency of the RAG-LLM. Encouraging results were observed, with a 62.7% success rate in guided detection of vulnerabilities. Second, we challenge the model under a "blind" audit setup, without the vulnerability type provided in the prompt, wherein 219 contracts undergo 40 tests each. This setup evaluates the general vulnerability detection capabilities without hinted context assistance. Under these conditions, a 60.71% success rate was observed. While the results are promising, we still emphasize the need for human auditing at this time. We provide this study as a proof of concept for a cost-effective smart contract auditing process, moving towards democratic access to security.

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

↑