基于大模型推理增强的智能合约漏洞检测研究Smart contract vulnerability detection with large language model reasoning enhancement
陈芸,肖海林,田波,孙泽宇
摘要(Abstract):
针对区块链系统安全中智能合约漏洞筛查在处理高复杂度逻辑时存在误报漏报率高,检测结果缺乏直观可解释性的问题,提出一种基于大模型推理增强的智能合约漏洞检测方法。该方法通过数据构建、模型改进、推理优化三个关键阶段展开。首先,从公开渠道采集四类典型漏洞数据并完成数据清洗,为模型训练奠定可靠数据基础。接着,采用LoRA高效参数微调策略改进Qwen Code模型。最后,提出多任务动态加权损失函数以同步增强模型的推理及分类能力。实验数据结果表明,在Reentrancy漏洞的检测上,该方法准确率达86.54%、F1分数为80.08%。相较于传统静态检测方法Sailfish,分别提升了10%和19%。在混合漏洞的检测上,该方法准确率为85.17%,F1分数为78.96%,相较于主流的大语言模型iAudit,分别提升了9%和12%,且该方法参数量更小。进一步与深度学习方法相比,其检测结果更具可解释性。该方法有效提高了智能合约漏洞检测的准确性,显著增强了其实际应用价值,为区块链系统安全提供了更高效的技术支撑。
关键词(KeyWords): 大语言模型;区块链;智能合约;漏洞检测
基金项目(Foundation): 广西重大专项项目(桂科AA24263034);; 广西重点研发计划(桂科AB2506934);; 湖北省重点研发项目(2025BAB002)资助
作者(Author): 陈芸,肖海林,田波,孙泽宇
参考文献(References):
- [1] 李家骏,肖芳雄,梅丁益.基于大语言模型的智能合约漏洞检测研究综述[J].金陵科技学院学报,2025,41(2):17-25.
- [2] GHALEB A,RUBIN J,PATTABIRAMAN K.AChecker:statically detecting smart contract access control vulnerabilities[C]//2023 IEEE/ACM 45th International Conference on Software Engineering (ICSE).Melbourne,2023:945-956.
- [3] 王化群,张帆,李甜,等.智能合约中的安全与隐私保护技术[J].南京邮电大学学报(自然科学版),2019,39(4):63-71.
- [4] 王润六,吴怀广,何亚琼.智能合约的形式化验证方法综述[J].网络空间安全,2021,12(S2):73-79.
- [5] SUN Y,WU D,XUE Y,et al.Llm4vuln:a unified evaluation framework for decoupling and enhancing llms’ vulnerability reasoning[J].arXiv preprint arXiv:2401.16185,2024.
- [6] JIN Y,LI C,FAN P,et al.LLM-BSCVM:an LLM-based blockchain smart contract vulnerability management framework[J].arXiv preprint arXiv:2505.17416,2025.
- [7] ZAAZAA O,EL BAKKALI H.SmartLLMSentry:a comprehensive LLM based smart contract vulnerability detection framework[J].J Metaverse,2024,4(2):126-137.
- [8] 林型双,王琴应,纪守领.大模型赋能漏洞自动化挖掘[J].计算.2025 (2):16-22.
- [9] YU L,CHEN S,YUAN H,et al.Smart-LLaMA-DPO:reinforced large language model for explainable smart contract vulnerability detection [EB/OL].(2024-10-15) [2025-09-26].https://doi.org/10.48550/arXiv.2506.18245.
- [10] YU L,CHEN S,YUAN H,et al.Smart-LLaMA:two-stage post-training of large language models for smart contract vulnerability detection and explanation [EB/OL].(2024-11-09) [2025-09-26].arXiv:2411.06221v1.
- [11] HU E J,SHEN Y,WALLIS P,et al.LoRA:low-rank adaptation of large language models [EB/OL].https://arxiv.org/pdf/2411.06221.
- [12] BAHEL V,PILLAI S,MALHOTRA M.A comparative study on various binary classification algorithms and their improved variant for optimal performance[C]//2020 IEEE Region 10 Symposium (TENSYMP).Dhaka.2020:495-498.
- [13] BOSE P,DAS D,CHEN Y J,et al.SAILFISH:vetting smart contract state-inconsistency bugs in seconds[C]//2022 IEEE Symposium on Security and Privacy (SP).San Francisco,2022:161-178.