arXiv:2506.18245cs.CRcs.AI2025-06中稿 · ISSTA 2025被引 41

用强化学习提升大模型对智能合约漏洞的解释能力。

Smart-LLaMA-DPO: Reinforced Large Language Model for Explainable Smart Contract Vulnerability Detection

  • 构建包含四类漏洞的高质量数据集,支持模型精调与偏好优化。
  • 在四项漏洞检测任务中,F1得分提升10.43%,准确率提高7.87%。
  • 适合区块链安全研究人员和智能合约审计开发者使用。

智能合约漏洞检测仍是区块链安全的重大挑战。现有方法存在两大问题:(1) 数据集覆盖不全且缺乏高质量解释用于偏好学习;(2) 大语言模型难以准确理解智能合约安全中的特定概念。实证分析显示,即使经过持续预训练(CPT)和监督微调(SFT),LLM仍可能误判状态变更的执行顺序,导致解释错误而检测结果正确。为此,我们提出基于LLaMA-3.1-8B的Smart-LLaMA-DPO。首先,构建涵盖四类主要漏洞及机器不可审计漏洞的综合数据集,包含精确标签、解释和位置信息用于SFT,以及高质量与低质量输出对用于直接偏好优化(DPO)。其次,使用大规模智能合约进行CPT以增强模型对安全实践的理解。随后进行SFT,并应用DPO,结合人类反馈和特殊设计的损失函数,提高优选解释概率,降低非优选输出可能性。我们在重入攻击、时间戳依赖、整数溢出/下溢和delegatecall漏洞,以及机器不可审计漏洞上评估该方法。结果表明,相比最先进基线,平均F1分数提升10.43%,准确率提升7.87%。模型评估与人工评估均证实,本方法生成的解释更准确、全面且清晰。

原文摘要 · Abstract (English)

Smart contract vulnerability detection remains a major challenge in blockchain security. Existing vulnerability detection methods face two main issues: (1) Existing datasets lack comprehensive coverage and high-quality explanations for preference learning. (2) Large language models (LLMs) often struggle with accurately interpreting specific concepts in smart contract security. Empirical analysis shows that even after continual pre-training (CPT) and supervised fine-tuning (SFT), LLMs may misinterpret the execution order of state changes, resulting in incorrect explanations despite making correct detection decisions. To address these challenges, we propose Smart-LLaMA-DPO based on LLaMA-3.1-8B. We construct a comprehensive dataset covering four major vulnerability types and machine-unauditable vulnerabilities, including precise labels, explanations, and locations for SFT, as well as high-quality and low-quality output pairs for Direct Preference Optimization (DPO). Second, we perform CPT using large-scale smart contract to enhance the LLM's understanding of specific security practices in smart contracts. Futhermore, we conduct SFT with our comprehensive dataset. Finally, we apply DPO, leveraging human feedback and a specially designed loss function that increases the probability of preferred explanations while reducing the likelihood of non-preferred outputs. We evaluate Smart-LLaMA-DPO on four major vulnerability types: reentrancy, timestamp dependence, integer overflow/underflow, and delegatecall, as well as machine-unauditable vulnerabilities. Our method significantly outperforms state-of-the-art baselines, with average improvements of 10.43% in F1 score and 7.87% in accuracy. Moreover, both LLM evaluation and human evaluation confirm that our method generates more correct, thorough, and clear explanations.

智能合约漏洞检测大模型可解释性

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。