计算机工程与应用 ›› 2025, Vol. 61 ›› Issue (20): 315-326.DOI: 10.3778/j.issn.1002-8331.2406-0313

• 网络、通信与安全 • 上一篇    下一篇

基于路径融合的智能合约漏洞检测方法

范亚生,谢春丽,魏家劲,曾友   

  1. 江苏师范大学 计算机科学与技术学院,江苏 徐州 221116
  • 出版日期:2025-10-15 发布日期:2025-10-15

Vulnerability Detection Method for Smart Contract Based on Path Fusion

FAN Yasheng,  XIE Chunli, WEI Jiajin, ZENG You   

  1. School of Computer Science and Engineering, Jiangsu Normal University, Xuzhou, Jiangsu 221116, China
  • Online:2025-10-15 Published:2025-10-15

摘要: 随着去中心化互联网的发展,智能合约因其不可修改性而需要在部署前确保安全性,以防范潜在的漏洞风险。尽管已有一些基于深度学习的方法用于智能合约的漏洞检测,但仍然存在以下两个问题:一是缺乏对合约结构和语义信息的充分理解;二是神经网络模型受输入长度的制约,对长合约性能不佳。针对这两个问题,提出基于语法控制流图的合约分解和路径融合方法。基于抽象语法树构建智能合约的语法控制流图,并采用贪心策略将语法控制流图分解为多条结构简单的路径;使用预训练的代码模型学习路径的向量表示。融合不同路径的特征向量以实现漏洞检测。为验证模型的有效性,构建了一个包含7 511个真实世界智能合约的数据集,实验结果表明,和主流方法相比该方法能够有效提高智能合约漏洞检测的精确率、召回率和F1值。

关键词: 智能合约, 漏洞检测, 控制流图, 预训练模型

Abstract: With the development of decentralized internet, smart contracts need to ensure security before deployment due to their immutability to prevent potential vulnerabilities. Despite some deep learning-based methods for vulnerability detection in smart contracts, two main issues persist: insufficient understanding of contract structure and semantic information, and poor performance on long contracts due to the input length limitations of neural network models. To address these issues, a method based on syntax control flow graph decomposition and path fusion is proposed. Firstly, for a smart contract, a syntax control flow graph is constructed based on its abstract syntax tree, and a greedy strategy is used to decompose the graph into multiple paths from entry nodes to exit nodes. Secondly, a pre-trained code model is used to learn the vector representation of these paths. Finally, the feature vectors of different paths are fused to achieve vulnerability detection. A dataset containing 7 511 real-world smart contracts is constructed to validate the model’s effectiveness. Experimental results show that the decomposed paths effectively improve the precision, recall, and F1 score of smart contract vulnerability detection.

Key words: smart contract, vulnerability detection, control flow graph, pre-trained models