Abstract: Smart contract vulnerability detection draws extensive attention in recent years due to the substantial losses caused by hacker attacks. Existing efforts for contract security analysis heavily rely on rigid rules defined by experts, which are labor-intensive and non-scalable. More importantly, expert-defined rules tend to be error-prone and suffer the inherent risk of being cheated by crafty attackers. Recent researches focus on the symbolic execution and formal analysis of smart contracts for vulnerability detection, yet to achieve a precise and scalable solution. Although several methods have been proposed to detect vulnerabilities in smart contracts, there is still a lack of effort that considers combining expert-defined security patterns with deep neural networks. In this paper, we explore using graph neural networks and expert knowledge for smart contract vulnerability detection. Specifically, we cast the rich control- and data- flow semantics of the source code into a contract graph. To highlight the critical nodes in the graph, we further design a node elimination phase to normalize the graph. Then, we propose a novel temporal message propagation network to extract the graph feature from the normalized graph, and combine the graph feature with designed expert patterns to yield a final detection system. Extensive experiments are conducted on all the smart contracts that have source code in Ethereum and VNT Chain platforms. Empirical results show significant accuracy improvements over the state-of-the-art methods on three types of vulnerabilities, where the detection accuracy of our method reaches 89.15%, 89.02%, and 83.21% for reentrancy, timestamp dependence, and infinite loop vulnerabilities, respectively.
Introduction: The Vulnerability Landscape
Smart contracts hold billions of dollars in virtual assets, making them highly lucrative targets for hackers. The infamous $60M DAO hack serves as a stark reminder of the risks involved. Because smart contracts are immutable once deployed on a blockchain, developers cannot simply "patch" a bug after the fact; pre-deployment vulnerability checking is absolutely critical.
Traditionally, developers have relied on static and dynamic analysis tools (like Oyente, Securify, or Slither) that flag bugs based on rigid, expert-defined rules. However, these rules are labor-intensive to create and prone to false positives/negatives. Recent attempts to use deep learning have often treated source code as a flat text sequence, missing crucial structural context and failing to highlight critical variables in the data flow.
The CGE Architecture
To address these limitations, we propose CGE (Combining Graph feature and Expert patterns), a hybrid architecture that leverages both human domain knowledge and graph neural networks. The pipeline consists of three main phases designed to capture the deep semantics of contract code.
1. Expert Pattern Extraction
The system uses syntax and taint analysis to extract specific, known vulnerability patterns from the code. For example, it might check if a user's balance is deducted before a money transfer occurs. These patterns are processed by a feed-forward neural network to create a "pattern feature" ($P_r$).
2. Contract Graph Construction & Normalization
The source code is converted into a graph capturing control-flow, data-flow, and smart contract-specific "fallback" edges. We introduce a graph normalization step where nodes are categorized as core (critical variables/invocations), normal, or fallback. Normal nodes are eliminated, and their features are aggregated into core nodes. This prevents the GNN from treating all lines of code as equally important, focusing the model on the logic most likely to contain vulnerabilities.
3. Vulnerability Detection
A novel Temporal Message Propagation (TMP) network processes the normalized graph, passing messages along edges in their actual temporal execution order to extract a "graph feature" ($G_r$). Finally, a fusion network combines $G_r$ with $P_r$ to predict whether the contract is vulnerable.
Experimental Evaluation
We evaluated CGE on two real-world datasets: ESC (Ethereum Smart Contracts), containing over 300,000 functions, and VSC (VNT Chain Smart Contracts), containing over 13,000 functions. The method established new state-of-the-art benchmarks across three major vulnerability types:
- Reentrancy: Achieved 89.15% accuracy, a 12.03% improvement over the best conventional tool, Slither.
- Timestamp Dependence: Reached 89.02% accuracy, representing a 14.82% improvement over Slither.
- Infinite Loop: Hit 83.21% accuracy, significantly outperforming the specialized tool Looper (59.56%).
Ablation studies confirmed that removing either the expert pattern module or the graph normalization module noticeably degraded performance, proving that the synergy of human knowledge and structural graph analysis is essential.
Conclusion and Future Work
CGE demonstrates that deep learning does not have to replace expert knowledge; instead, fusing conventional security patterns with GNN-extracted features consistently outperforms pure neural networks. This approach successfully detects complex, obfuscated attacks—like "sharing-variable reentrancy"—that bypass traditional tools by tracking deep data dependencies.
While currently reliant on source code, future work will focus on extending this methodology to analyze smart contract bytecode, enabling the detection of vulnerabilities in closed-source contracts deployed on the blockchain.
Summary updated