用自适应专家混合提升大模型检测智能合约漏洞的准确率
SAEL: Leveraging Large Language Models with Adaptive Mixture-of-Experts for Smart Contract Vulnerability Detection
- 设计针对性提示词引导大模型生成漏洞检测特征
- 融合代码、解释与大模型预测,综合性能超越现有方法
- 适合需要高精度漏洞检测的研究者和开发者
随着区块链安全问题日益突出,智能合约漏洞检测成为研究热点。现有方法存在局限:静态分析难以应对复杂场景;专用预训练模型在特定数据集表现好但泛化能力弱。通用大语言模型(LLM)虽能适应新漏洞模式,但在特定漏洞类型上表现不如专用模型。我们发现,通用LLM生成的解释可提供细粒度代码理解信息,有助于提升检测效果。受此启发,提出SAEL框架:首先设计针对性提示词,引导LLM识别漏洞并生成解释,作为预测特征;其次对CodeT5和T5进行提示调优,增强任务适配性;最后引入自适应专家混合架构,通过门控网络动态调整特征权重,结合TopK筛选与Softmax归一化,并引入多头自注意力机制强化特征间关联,实现梯度优化下的多源特征融合。损失函数同时考虑各特征独立表现与加权整体预测。实验表明,SAEL在多种漏洞类型上均优于现有方法。
原文摘要 · Abstract (English)
With the increasing security issues in blockchain, smart contract vulnerability detection has become a research focus. Existing vulnerability detection methods have their limitations: 1) Static analysis methods struggle with complex scenarios. 2) Methods based on specialized pre-trained models perform well on specific datasets but have limited generalization capabilities. In contrast, general-purpose Large Language Models (LLMs) demonstrate impressive ability in adapting to new vulnerability patterns. However, they often underperform on specific vulnerability types compared to methods based on specialized pre-trained models. We also observe that explanations generated by general-purpose LLMs can provide fine-grained code understanding information, contributing to improved detection performance. Inspired by these observations, we propose SAEL, an LLM-based framework for smart contract vulnerability detection. We first design targeted prompts to guide LLMs in identifying vulnerabilities and generating explanations, which serve as prediction features. Next, we apply prompt-tuning on CodeT5 and T5 to process contract code and explanations, enhancing task-specific performance. To combine the strengths of each approach, we introduce an Adaptive Mixture-of-Experts architecture. This dynamically adjusts feature weights via a Gating Network, which selects relevant features using TopK filtering and Softmax normalization, and incorporates a Multi-Head Self-Attention mechanism to enhance cross-feature relationships. This design enables effective integration of LLM predictions, explanation features, and code features through gradient optimization. The loss function jointly considers both independent feature performance and overall weighted predictions. Experiments show that SAEL outperforms existing methods across various vulnerabilities.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。