A blockchain smart contract multi-vulnerability detection method and system based on an improved graph convolution network
By improving the graph structure features of smart contracts using graph convolutional networks, the problem of existing technologies being unable to detect complex vulnerabilities is solved, achieving efficient and accurate multi-vulnerability detection of smart contracts and enhancing their security.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SOUTH CHINA UNIV OF TECH
- Filing Date
- 2023-01-18
- Publication Date
- 2026-05-12
AI Technical Summary
Existing smart contract detection methods are ineffective at detecting complex vulnerabilities, and attackers can bypass existing rules, leading to frequent security incidents. Existing formal verification methods are also struggling to cope with the ever-increasing number and types of smart contracts.
An improved graph convolutional network is adopted to generate nodes and edges by constructing the graph structure features of smart contracts, outputting multi-dimensional feature vectors, and training a multi-vulnerability graph convolutional network classification model to achieve multi-vulnerability detection of smart contracts.
It improves the accuracy and efficiency of smart contract vulnerability detection, enhances the security of smart contracts, and is suitable for detecting large batches of multiple vulnerability types.
Smart Images

Figure CN116150003B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of distributed application security technology of blockchain, and in particular to a method and system for detecting multiple vulnerabilities in blockchain smart contracts based on an improved graph convolutional network. Background Technology
[0002] Smart contracts are automatically running, self-sufficient, and decentralized programs that handle transactions between two parties without the need for a centralized intermediary. In other words, they are distributed, trusted, shared code deployed on a blockchain. The parties signing a smart contract must agree on the contract details, default conditions, liabilities for breach of contract, and external verification data sources (oracles), and then deploy it on the blockchain in the form of a smart contract, thereby automatically executing the contract on behalf of the signatories. With the development of blockchain technology, more and more developers have noticed these advantages of smart contracts and are applying smart contract technology to numerous fields, including finance, art transactions, and venture capital.
[0003] However, smart contract developers, lacking experience and vigilance, can easily write vulnerable smart contract code and hastily deploy it without sufficient testing, ultimately leading to serious security incidents. In 2016, an attack on the DAO contract resulted in the loss of over 3,600,000 Ether. The attack stemmed from a reentrancy vulnerability introduced in a critical contract within DAO. In 2017, a vulnerability in the Parity multi-signature wallet resulted in the locking of over 513,701 Ether. In 2020, the decentralized finance project bZx lending protocol suffered two smart contract vulnerability attacks, resulting in losses of $350,000 and $640,000 respectively. Besides the typical cases mentioned above, there are many other vulnerability cases in the smart contract field worthy of study, and various new attack methods are constantly emerging, making the detection of multiple vulnerabilities in smart contracts an urgent need.
[0004] In the past, smart contract detection mainly relied on certain rules defining logical semantics. However, these rules were largely ineffective against complex smart contracts, and attackers could easily bypass them once they learned them. Faced with the ever-increasing variety of smart contract vulnerabilities and the growing number of smart contracts, existing formal verification methods are struggling to keep up.
[0005] Graph Convolutional Networks (GCNNs) are a framework that has emerged in recent years, utilizing deep learning to directly learn from graph-structured data. Their superior performance has attracted significant attention and in-depth exploration by researchers. By formulating specific strategies for nodes and edges in a graph, graph-structured data is transformed into a standardized representation, which is then fed into various neural networks for training. This has yielded excellent results in tasks such as node classification, edge information propagation, and graph clustering. In recent years, GCNNs have also been widely applied in natural language processing.
[0006] Therefore, developing an accurate and efficient method and system for detecting multiple vulnerabilities in smart contracts using graph convolutional networks is of significant practical importance. Summary of the Invention
[0007] To address the technical problems existing in the prior art, this invention provides a method and system for detecting multiple vulnerabilities in blockchain smart contracts based on an improved graph convolutional network, which enables accurate and efficient detection of multiple vulnerabilities in smart contracts and enhances the security of smart contracts.
[0008] The method of this invention is implemented using the following technical solution: a method for detecting multiple vulnerabilities in blockchain smart contracts based on improved graph convolutional networks, comprising the following steps:
[0009] S1. Construct a dataset of smart contract vulnerability samples;
[0010] S2. Model the semantics of the source code in the smart contract, generate nodes and edges, and form a complete graph structure feature;
[0011] S3. Process the graph structure features to obtain multi-dimensional feature vector output;
[0012] S4. Calculate and train the feature vectors of various vulnerability samples to obtain a multi-vulnerability graph volume integral class model with optimal parameters.
[0013] S5. Input the smart contract to be tested into the multi-label classification model, and the model outputs the vulnerability detection result of the smart contract.
[0014] The present invention employs the following technical solution: a blockchain smart contract multi-vulnerability detection system based on an improved graph convolutional network, comprising:
[0015] Build modules: Used to build a dataset of smart contract vulnerability samples;
[0016] Graph structure feature acquisition module: used to model the semantics of the source code in smart contracts, generate nodes and edges, and form complete graph structure features;
[0017] Multidimensional feature vector acquisition module: used to process graph structure features and obtain multidimensional feature vector output;
[0018] Classification model acquisition module: used to calculate and train the feature vectors of various vulnerability samples to obtain a multi-vulnerability graph volume integral class model with optimal parameters;
[0019] The detection result acquisition module is used to input the smart contract to be detected into the multi-label classification model, and the model outputs the vulnerability detection result of the smart contract.
[0020] The present invention also proposes a storage medium on which a computer program is stored, wherein when the computer program is executed by a processor, the steps of the blockchain smart contract multi-vulnerability detection method of the present invention are implemented.
[0021] The present invention also proposes a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the blockchain smart contract multi-vulnerability detection method of the present invention.
[0022] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0023] 1. This invention addresses the characteristics of the Solidity language for smart contracts by modeling various keywords and variables to obtain a connected graph of code nodes; it also classifies the semantics and syntax of Solidity language keywords as features of edges in the graph structure, thus compensating for the loss of semantic and syntactic structural features in existing methods.
[0024] 2. Based on the graph structure characteristics of smart contracts, this invention normalizes the graph structure characteristics to simplify them. While retaining the key semantic graph structure paths, it prunes paths irrelevant to identifying and classifying vulnerabilities, removing redundant points, thereby improving the detection efficiency and accuracy of smart contract vulnerabilities.
[0025] 3. This invention uses a variety of smart contract vulnerability sample sets as datasets, and inputs the normalized graph structure into an improved graph convolutional model for parameter learning. In the improved graph convolutional model, the internal and external features of the smart contract graph structure are constructed, and vulnerability classification parameters are learned by adding a self-connected adjacency matrix. The improved graph convolutional model can adapt to various smart contract vulnerability features, expand the application scope, and improve the robustness of the method. Attached Figure Description
[0026] Figure 1 This is a flowchart of the method of the present invention;
[0027] Figure 2 This is a schematic diagram of graph structure feature generation according to the present invention. Detailed Implementation
[0028] The present invention will be further described in detail below with reference to the embodiments and accompanying drawings, but the embodiments of the present invention are not limited thereto.
[0029] Example
[0030] like Figure 1 As shown in the figure, this embodiment presents a method for detecting multiple vulnerabilities in blockchain smart contracts based on improved graph convolutional networks, including the following steps:
[0031] S1. Construct a dataset of smart contract vulnerability samples;
[0032] S2. Model the semantics of the source code in the smart contract, generate nodes and edges, and form a complete graph structure feature;
[0033] S3. Process the graph structure features to obtain multi-dimensional feature vector output;
[0034] S4. Calculate and train the feature vectors of various vulnerability samples to obtain a multi-vulnerability graph volume integral class model with optimal parameters.
[0035] S5. Input the smart contract to be tested into the multi-label classification model, and the model outputs the vulnerability detection result of the smart contract.
[0036] Specifically, in this embodiment, the specific process of step S1 is as follows:
[0037] S11. Obtain the set of smart contract addresses deployed on Ethereum from the Google BigQuery database and obtain the corresponding smart contract source code from the Etherscan platform; in practical applications, by obtaining 149,363 Ethereum smart contract addresses, a script was written to query and obtain 4,037 smart contract source codes.
[0038] S12. Using the widely validated smart contract vulnerability detection tools Oyente and Mythril, we conducted multi-type vulnerability detection. For smart contract samples with detected vulnerabilities, we wrote contract transaction test cases, deployed and debugged the transactions in Remix IDE, manually verified the accuracy of the smart contract vulnerabilities, and classified and organized the samples according to the results. In practical application, the types of samples obtained, the labels marked in the SWC Registry smart contract vulnerability database, and the number of samples are shown in Table 1.
[0039] Table 1
[0040]
[0041] like Figure 2 As shown in this embodiment, in step S2, feature graphs are extracted from the collected smart contract vulnerability sample dataset, processed into a graph structure, and the graph structure feature set of the samples is obtained.
[0042] In this embodiment, the specific process of step S2 includes:
[0043] S21. Considering the program elements in the source code of a smart contract with different functions and importance, and the relationships between them, divide the nodes into the following three categories: primary nodes, secondary nodes, and fallback nodes; construct the edges connecting the nodes through the logical semantic rules of the code, including sequential edges, fallback edges, semantic edges, and data edges.
[0044] S22. Use the main node to call all functions except the fallback function; use the secondary nodes to represent some key global variables, intermediate variables, or passed addresses; use the fallback node to represent the fallback function separately.
[0045] S23. The logical semantic rules of the code for constructing edges are shown in Table 2.
[0046] Table 2
[0047]
[0048]
[0049] Specifically, in this embodiment, the specific implementation process of step S3 includes node feature transfer and node feature update.
[0050] Specifically, node feature transfer will transfer the secondary node. Alternatively, the characteristics of the fallback node F can be transferred to the corresponding master node. The specific steps to simplify the node graph structure are as follows:
[0051] S311, Eliminate secondary nodes All secondary nodes The feature is assigned to its nearest master node. If S i There are two or more nearest master nodes. Then pass its characteristics to all nearest master nodes.
[0052] S312. Eliminate the fallback node F and pass the characteristics of the fallback node F to the two corresponding master nodes.
[0053] S313. Edges connected to deleted nodes will be retained, but their characteristics with respect to the start or end node will be moved to the corresponding master node.
[0054] Specifically, since some primary nodes have incorporated features from secondary and fallback nodes after the node feature transfer process, an update is required. The specific steps for updating node features are as follows:
[0055] S321. Define the updated master nodes as V1, V2, ..., V m ;
[0056] S322. The characteristics of the updated node are divided into three parts:
[0057] 1) Its own node characteristics;
[0058] 2) Internal features, namely secondary nodes and backtracking nodes. Pointing to master node M i directional characteristics, and corresponding Pointing to master node M i Path features, and using To indicate;
[0059] 3) External features, i.e., master node M i Point to the next node, back node The directional characteristics, and have a corresponding master node M. i point to Path features, and using To express.
[0060] Specifically, in this embodiment, the multi-vulnerability graph convolutional model in step S4 includes two parts: an improved graph convolutional computation layer and an output layer; the improved graph convolutional model is used to learn and calculate the parameters of the path features of the sample graph structure, and the predicted probability value is generated by the voting. The predicted probability value is evaluated using the F1 score metric; based on the classification results of the samples output by the multi-label classification model, the classification results of each multi-label classification model are judged and output.
[0061] Specifically, the improved graph convolution computation layer is based on the classic graph convolution structure expression, with mathematical improvements. Considering that the node graph of the samples has already been normalized, and in order to highlight the features of the normalized node graph, the improved graph convolution structure expression is as follows:
[0062]
[0063] Let the number of nodes in the node graph be N, and the feature vectors of the nodes be D-dimensional. The input to the l-th layer of the graph neural network is the initial layer H. (0) =X, To add self-connected adjacency matrices, For degree matrix, The parameters to be trained are σ is the corresponding activation function, such as the ReLU function.
[0064] Specifically, the output layer adopts a One-Versus-One strategy to output prediction results from the perspective of multi-label classification model; there are k smart contract vulnerabilities, and the data of each pair of the k categories are combined, and then a model is trained using the combined data to generate k(k-1) / 2 classifiers. The results of these classifiers are fused, and the prediction results of the classifiers are output as the final prediction result value using a majority voting method.
[0065] Specifically, if the prediction result shows that only the probability value of a certain vulnerability type V1 is higher than 60%, while the prediction probability values of all other vulnerability types V2...Vk are lower than 60%, then only the vulnerability type V1 will be reported. If the result shows that the prediction probability values of multiple vulnerability types V1...Vm are higher than 60%, while the prediction probability values of all other vulnerability types Vm+1...Vk are lower than 60%, then the vulnerability types V1...Vm will be reported. If the result shows no prediction probability value for any vulnerability type, then the smart contract will be reported as not containing any of the k vulnerability types.
[0066] Specifically, in this embodiment, the vulnerability detection results of the smart contract in step S5 include which vulnerabilities the Ethereum smart contract has or does not have, and the detected vulnerabilities include integer overflow / underflow vulnerabilities, infinite loop vulnerabilities, return value vulnerabilities, and code reentrancy vulnerabilities, etc.
[0067] Specifically, the detection performance of the smart contract multi-vulnerability detection method proposed in this embodiment for different vulnerabilities is shown in Table 3.
[0068] Table 3
[0069] Vulnerability types Detection performance / F1 score% Integer overflow vulnerability 98.34% Infinite loop vulnerability 83.57% Return value vulnerability 95.60% Reentrancy vulnerability 93.53%
[0070] Therefore, the multi-label classification and vulnerability detection method proposed in this embodiment achieves accurate and efficient automatic detection of four types of smart contract vulnerabilities by extracting path features of graph structures and utilizing an improved graph convolution smart contract multi-vulnerability detection method. This method is more suitable for application scenarios involving large-scale smart contract vulnerability detection with multiple vulnerability types.
[0071] Based on the same inventive concept, this invention also proposes a blockchain smart contract multi-vulnerability detection system based on an improved graph convolutional network, comprising:
[0072] Build modules: Used to build a dataset of smart contract vulnerability samples;
[0073] Graph structure feature acquisition module: used to model the semantics of the source code in smart contracts, generate nodes and edges, and form complete graph structure features;
[0074] Multidimensional feature vector acquisition module: used to process graph structure features and obtain multidimensional feature vector output;
[0075] Classification model acquisition module: used to calculate and train the feature vectors of various vulnerability samples to obtain a multi-vulnerability graph volume integral class model with optimal parameters;
[0076] The detection result acquisition module is used to input the smart contract to be detected into the multi-label classification model, and the model outputs the vulnerability detection result of the smart contract.
[0077] Furthermore, this invention also proposes a storage medium and a computer device. The storage medium stores a computer program, which, when executed by a processor, implements steps S1-S5 of the blockchain smart contract multi-vulnerability detection method of this invention. The computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the blockchain smart contract multi-vulnerability detection method of this invention, which includes the aforementioned steps S1-S5.
[0078] The above embodiments are preferred embodiments of the present invention, but the embodiments of the present invention are not limited to the above embodiments. Any changes, modifications, substitutions, combinations, or simplifications made without departing from the spirit and principle of the present invention shall be considered equivalent substitutions and shall be included within the protection scope of the present invention.
Claims
1. A method for detecting multiple vulnerabilities in blockchain smart contracts based on improved graph convolutional networks, characterized in that, Includes the following steps: S1. Construct a dataset of smart contract vulnerability samples; S2. Model the semantics of the source code in the smart contract, generate nodes and edges, and form a complete graph structure feature; S3. Process the graph structure features to obtain multi-dimensional feature vector output; S4. Calculate and train the feature vectors of various vulnerability samples to obtain a multi-vulnerability graph volume integral class model with optimal parameters. S5. Input the smart contract to be detected into the multi-label classification model, and the model outputs the vulnerability detection result of the smart contract. The specific process of step S2 includes: S21. Divide the nodes into the following three categories: primary nodes, secondary nodes, and fallback nodes; construct the edges connecting the nodes through the logical semantic rules of the code, including sequential edges, fallback edges, semantic edges, and data edges; S22. Use the main node to call all functions except the fallback function; use the secondary node to represent key global variables, intermediate variables, or passed addresses; use the fallback node to represent the fallback function separately. S23. Logical semantic rules for constructing edges; The specific implementation process of step S3 includes node feature transfer and node feature update; Node feature transfer, transferring the secondary node Or rollback node Features are transferred to the corresponding master node To simplify the structure of the node graph, the specific steps are as follows: S311, Eliminate secondary nodes All secondary nodes The feature is assigned to its nearest master node. ,like There are two or more nearest master nodes. Then its characteristics are passed to all the nearest master nodes. ; S312, Eliminate rollback node , will roll back the node The features are passed to the two corresponding master nodes. ; S313. Edges connected to deleted nodes will be retained, but their characteristics with respect to the start or end node will be moved to the corresponding master node. ; The specific steps for updating node features are as follows: S321. Define the updated master node as... ; S322. The characteristics of the updated node are divided into three parts: 1) Its own node characteristics; 2) Internal features, namely secondary nodes and backtracking nodes. Point to the master node directional characteristics, and corresponding { Point to the master node Path features, and using To indicate; 3) External characteristics, i.e. Point to the next node, back node directional characteristics, and corresponding point to Path features, and using To express.
2. The method for detecting multiple vulnerabilities in blockchain smart contracts based on improved graph convolutional networks according to claim 1, characterized in that, The specific process of step S1 is as follows: S11. Obtain the set of smart contract addresses deployed on Ethereum from the Google BigQuery database, and obtain the corresponding smart contract source code from the Etherscan platform; S12. Use the widely validated smart contract vulnerability detection tools Oyente and Mythril to detect multiple types of vulnerabilities. For smart contract samples with detected vulnerabilities, write contract transaction test cases, deploy and debug the transactions in Remix IDE, manually verify the accuracy of the smart contract vulnerabilities, and classify and organize the samples according to the results.
3. The method for detecting multiple vulnerabilities in blockchain smart contracts based on improved graph convolutional networks according to claim 1, characterized in that, The multi-vulnerability graph convolutional model in step S4 consists of two parts: an improved graph convolutional computation layer and an output layer. The improved graph convolutional model is used to learn and calculate the parameters of the path features of the sample graph structure. The predicted probability value is generated by voting and evaluated using the F1 score. Based on the classification results of the samples output by the multi-label classification model, the classification results of each multi-label classification model are judged and output.
4. The method for detecting multiple vulnerabilities in blockchain smart contracts based on improved graph convolutional networks according to claim 3, characterized in that, The improved graph convolution structure expression for the improved graph convolution computation layer is as follows: Let the number of nodes in the node graph be... The feature vector of the node is dimension, For the first Input to a layered graph neural network, initial layer , To add self-connected adjacency matrices, Let be the degree matrix, and the parameters to be trained are . , This is the corresponding activation function.
5. The method for detecting multiple vulnerabilities in blockchain smart contracts based on improved graph convolutional networks according to claim 3, characterized in that, The output layer adopts a One-Versus-One strategy to output prediction results from the perspective of multi-label classification model; there are k smart contract vulnerabilities. The data of each pair of the k categories are combined, and a model is trained using the combined data to generate k(k-1) / 2 classifiers. The results of these classifiers are fused, and the prediction results of the classifiers are output as the final prediction result value using the majority voting method. If the prediction result shows that only the probability value of a certain vulnerability type V1 is higher than 60%, while the prediction probability values of all other vulnerability types V2...Vk are lower than 60%, then only vulnerability type V1 will be reported. If the result shows that the prediction probability values of multiple vulnerability types V1...Vm are higher than 60%, while the prediction probability values of all other vulnerability types Vm+1...Vk are lower than 60%, then vulnerability types V1...Vm will be reported. If the result shows no prediction probability value for any vulnerability type, then the result will be reported that this smart contract does not contain any of the k vulnerability types.
6. A blockchain smart contract multi-vulnerability detection system based on the improved graph convolutional network-based blockchain smart contract multi-vulnerability detection method described in claim 1, characterized in that, include: Build modules: used to build a dataset of smart contract vulnerability samples; Graph structure feature acquisition module: used to model the semantics of the source code in smart contracts, generate nodes and edges, and form complete graph structure features; Multidimensional feature vector acquisition module: used to process graph structure features and obtain multidimensional feature vector output; Classification model acquisition module: used to calculate and train the feature vectors of various vulnerability samples to obtain a multi-vulnerability graph volume integral class model with optimal parameters; The detection result acquisition module is used to input the smart contract to be detected into the multi-label classification model, and the model outputs the vulnerability detection result of the smart contract.
7. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the blockchain smart contract multi-vulnerability detection method according to any one of claims 1-5.
8. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the blockchain smart contract multi-vulnerability detection method according to any one of claims 1-5.