Smart Contract Vulnerability Detection (SCVD) is crucial to guarantee the quality of blockchain-based systems. Graph neural networks have been shown to be effective in learning semantic representations of smart contract code and are commonly adopted by existing deep learning-based SCVD. However, the current methods still have limitations in their utilization of graph sampling or subgraph pooling based on predefined rules for extracting crucial components from structure graphs of smart contract code. These predefined rule-based strategies, typically designed using static rules or heuristics, demonstrate limited adaptability to dynamically adjust extraction strategies according to the structure and content of the graph in heterogeneous topologies of smart contract code. Consequently, these strategies may not possess universal applicability to all smart contracts, potentially leading to false positives or omissions. To address these problems, we propose AFPNet, a novel vulnerability detection model equipped with a feature perception module that has dynamic weights for comprehensive scanning of the entire smart contract code and automatic extraction of crucial code snippets (the $P$ snippets with the largest weights). Subsequently, the relationship perception attention module employs an attention mechanism to learn dependencies among these code snippets and detect smart contract vulnerabilities. The efforts made by AFPNet consistently enable the capture of crucial code snippets and enhance the performance of SCVD optimization. We conduct an evaluation of AFPNet in the several large-scale datasets with vulnerability labels. The experimental results show that our AFPNet significantly outperforms the state-of-the-art approach by 6.38\%-14.02\% in term of F1-score. The results demonstrate the effectiveness of AFPNet in dynamically extracting valuable information and vulnerability detection.
翻译:智能合约漏洞检测对于保障基于区块链的系统质量至关重要。图神经网络已被证明能有效学习智能合约代码的语义表示,并被现有基于深度学习的SCVD方法广泛采用。然而,当前方法在利用基于预定义规则的图采样或子图池化从智能合约代码结构图中提取关键组件方面仍存在局限。这些基于预定义规则的策略通常采用静态规则或启发式方法设计,在智能合约代码的异构拓扑结构中,其根据图结构与内容动态调整提取策略的适应性有限。因此,这些策略可能不具备对所有智能合约的普适性,可能导致误报或漏报。为解决这些问题,我们提出AFPNet,这是一种配备特征感知模块的新型漏洞检测模型。该模块通过动态权重对整个智能合约代码进行全面扫描,并自动提取关键代码片段(权重最大的$P$个片段)。随后,关系感知注意力模块采用注意力机制学习这些代码片段间的依赖关系,以检测智能合约漏洞。AFPNet的设计持续保障了关键代码片段的捕获能力,并提升了SCVD优化的性能。我们在多个带漏洞标签的大规模数据集上对AFPNet进行了评估。实验结果表明,我们的AFPNet在F1分数指标上显著优于现有最优方法,提升幅度达6.38\%-14.02\%。这些结果证明了AFPNet在动态提取有价值信息和漏洞检测方面的有效性。