Retrieval Augmented Generation Integrated Large Language Models in Smart Contract Vulnerability Detection
作者: Jeffy Yu
分类: cs.CR, cs.AI
发布日期: 2024-07-20
备注: 17 pages, 3 figures, 4 tables
💡 一句话要点
提出基于检索增强生成的大语言模型智能合约漏洞检测方法,降低安全审计成本。
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 智能合约 漏洞检测 检索增强生成 大语言模型 安全审计
📋 核心要点
- 现有智能合约安全审计服务成本高昂,独立开发者和小企业难以负担,限制了DeFi生态的安全发展。
- 利用检索增强生成(RAG)技术,结合大语言模型(LLM),构建智能合约漏洞检测系统,降低审计成本。
- 实验结果表明,该方法在引导式和盲审式检测中均取得较好效果,验证了其在智能合约漏洞检测中的潜力。
📝 摘要(中文)
智能合约漏洞导致去中心化金融(DeFi)领域遭受巨大经济损失,有效安全审计需求迫切。针对独立开发者和小企业审计服务费用高昂的问题,本研究提出一种集成检索增强生成(RAG)与大语言模型(LLM)的框架。该框架使用GPT-4-1106(128k token上下文窗口),构建包含830个已知漏洞合约的向量存储,利用Pinecone进行向量存储,OpenAI的text-embedding-ada-002进行嵌入,LangChain构建RAG-LLM流水线。提示语设计为二元漏洞检测。实验分为两部分:一是引导式检测,针对52个合约,每个合约测试40次,成功率62.7%;二是盲审式检测,针对219个合约,每个合约测试40次,成功率60.71%。结果表明该方法具有潜力,但仍需人工审计。本研究旨在为经济高效的智能合约审计提供概念验证,推动安全服务的普及。
🔬 方法详解
问题定义:论文旨在解决智能合约安全审计成本高昂的问题。现有方法依赖人工审计或复杂的静态/动态分析工具,成本高,效率低,难以满足快速增长的DeFi应用需求。特别是对于资金有限的开发者和小企业,安全审计成为一项沉重的负担。
核心思路:论文的核心思路是利用检索增强生成(RAG)技术,结合大语言模型(LLM)的强大推理能力,构建一个低成本、高效率的智能合约漏洞检测系统。通过检索与目标合约相似的已知漏洞合约,为LLM提供上下文信息,提高其漏洞检测的准确性。
技术框架:整体框架包含以下几个主要模块:1) 向量存储构建:收集830个已知漏洞的智能合约,使用OpenAI的text-embedding-ada-002模型生成合约代码的向量嵌入,并存储在Pinecone向量数据库中。2) RAG-LLM流水线:使用LangChain构建RAG流水线,接收待审计的智能合约代码作为输入,在向量数据库中检索相似的漏洞合约,将检索结果与原始代码一起作为上下文信息输入到GPT-4-1106模型中。3) 漏洞检测:GPT-4-1106模型根据上下文信息判断待审计合约是否存在漏洞,输出二元结果(存在/不存在)。
关键创新:最重要的技术创新点在于将RAG技术与LLM相结合,用于智能合约漏洞检测。与传统的静态/动态分析方法相比,该方法无需复杂的规则定义和特征提取,而是利用LLM的自然语言理解和推理能力,直接从代码中识别漏洞。同时,RAG技术通过检索相似的漏洞合约,为LLM提供额外的上下文信息,提高了检测的准确性。
关键设计:关键设计包括:1) 使用GPT-4-1106模型,利用其128k token的上下文窗口处理较长的智能合约代码。2) 使用OpenAI的text-embedding-ada-002模型生成高质量的向量嵌入,提高检索的准确性。3) 设计合适的提示语,引导LLM进行漏洞检测,并输出二元结果。4) 实验分为引导式和盲审式两种模式,评估模型在不同条件下的性能。
🖼️ 关键图片
📊 实验亮点
实验结果显示,在引导式漏洞检测中,该方法取得了62.7%的成功率;在更具挑战性的盲审式漏洞检测中,成功率也达到了60.71%。这些结果表明,基于RAG-LLM的智能合约漏洞检测方法具有良好的潜力,可以作为人工审计的辅助工具,降低审计成本,提高审计效率。
🎯 应用场景
该研究成果可应用于智能合约安全审计、DeFi应用安全评估等领域。通过降低审计成本,可以帮助更多开发者和小企业进行安全审计,提高DeFi生态的整体安全性。未来,该方法可以进一步扩展到其他软件安全领域,例如Web应用安全、移动应用安全等。
📄 摘要(原文)
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.