A multi-feature fusion blockchain smart contract vulnerability detection method, device, computer and storage medium based on graph neural network
Through the multi-feature fusion method based on graph neural network, the smart contract structure diagram and expert pattern features are extracted, feature fusion and vulnerability prediction are performed, and the problem of existing tools being difficult to detect vulnerabilities in multiple versions of smart contracts is solved, and efficient and accurate vulnerability detection is achieved.
Patent Information
- Application Number
- CN202210988222.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-17
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2042-08-17
AI Technical Summary
Existing smart contract vulnerability detection tools are difficult to detect vulnerabilities in multi-version smart contracts, and the detection efficiency and accuracy are not high.
A multi-feature fusion method based on graph neural network is adopted, and the smart contract data set on the blockchain is crawled and converted into a smart contract structure chart. The graph neural network and multi-layer perceptron are used to extract features, and feature fusion is performed to predict vulnerabilities.
It realizes efficient vulnerability detection of multiple versions of smart contracts, improves the accuracy and efficiency of detection, and can detect more smart contract vulnerabilities.
Smart Images

Figure CN115499164B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of blockchain security detection, and in particular to a multi-feature fusion smart contract vulnerability detection method based on graph neural network. Background Art
[0002] At present, the tools for vulnerability detection of smart contracts are mainly divided into five categories: formal verification, symbolic execution, fuzz testing, intermediate representation, and deep learning. Through experiments on these five categories of smart contract vulnerability detection tools, the tools that use formal verification and intermediate representation to detect smart contracts in existing detection tools can detect more vulnerabilities. This may be related to the early development of formal verification and intermediate representation, but the accuracy of vulnerability detection is not high. The deep learning method is a research direction that has developed rapidly in recent years. Due to its late development, it detects fewer types of smart contract vulnerabilities, but the accuracy of vulnerability detection is higher than that of the other four types of detection tools. However, there are relatively few tools that can detect vulnerabilities in all versions of smart contracts. Tools such as Oyente, TMP, and AME can only detect smart contracts of version 0.4, Securify can detect smart contracts of versions 0.5 and 0.6, and Slither and Mythril can detect all versions of smart contracts. However, combined with research, it is found that their efficiency and accuracy are not high.
[0003] The current mainstream smart contract is version 0.8, so a smart contract multi-version vulnerability detection method is needed to detect whether there are vulnerabilities in the current mainstream smart contract version, so as to improve the detection efficiency of blockchain smart contracts. Summary of the invention
[0004] The present invention solves the problem of needing a smart contract multi-version vulnerability detection method to detect whether there are vulnerabilities in the current mainstream smart contract version, so as to improve the detection efficiency of blockchain smart contracts.
[0005] The present invention provides a multi-feature fusion blockchain smart contract vulnerability detection method based on graph neural network, the method comprising:
[0006] Crawl the smart contracts deployed on the blockchain and obtain the smart contract data set;
[0007] Process the smart contract dataset according to the smart contract vulnerability detection tool, obtain the smart contracts with vulnerabilities, and mark all smart contracts;
[0008] Determine the type of the obtained smart contract with the vulnerability;
[0009] Convert all the smart contract source codes into smart contract structure diagrams;
[0010] Using a graph neural network to extract the smart contract structure diagram, and using a multi-layer perceptron to extract expert pattern features in the smart contract source code;
[0011] Fusing the extracted features of the smart contract structure diagram and the expert mode features, learning the fused features through a neural network, and performing vulnerability prediction for different smart contract vulnerability types;
[0012] Determine whether there is a vulnerability based on the vulnerability prediction results.
[0013] Furthermore, a preferred implementation manner is provided, wherein the smart contract vulnerability detection tool includes: Slither, Oyente or Securify.
[0014] Furthermore, a preferred implementation manner is provided, wherein all the smart contract source codes are converted into a smart contract structure diagram, specifically, functions in the smart contract code are defined as nodes, and calling relationships between functions are defined as edges.
[0015] Furthermore, a preferred implementation is provided, in which a graph neural network is used to extract the smart contract structure diagram, and the graph neural network includes: a Graph Attention Network, a Graph Isomorphic Network, or a Temporal Message Propagation Graph Neural Network.
[0016] The present invention also provides a multi-feature fusion blockchain smart contract vulnerability detection device based on graph neural network, the device comprising:
[0017] A smart contract data set acquisition unit is used to crawl the smart contracts deployed on the blockchain and obtain the smart contract data set;
[0018] The smart contract vulnerability unit is used to process the smart contract data set according to the smart contract vulnerability detection tool, obtain smart contracts with vulnerabilities, and mark all smart contracts;
[0019] A vulnerability type determination unit, used to determine the type of the acquired smart contract with the vulnerability;
[0020] A smart contract structure diagram acquisition unit, used to convert all the smart contract source codes into a smart contract structure diagram;
[0021] A feature extraction unit, used to extract the smart contract structure diagram using a graph neural network, and to extract expert mode features in the smart contract source code using a multi-layer perceptron;
[0022] A vulnerability prediction unit, used to fuse the features of the extracted smart contract structure diagram and the expert mode features, learn the fused features through a neural network, and perform vulnerability prediction for different smart contract vulnerability types;
[0023] The vulnerability result acquisition unit is used to determine whether a vulnerability exists according to the vulnerability prediction result.
[0024] Furthermore, a preferred implementation is provided, wherein the smart contract vulnerability detection tool includes but is not limited to: Slither, Oyente or Securify.
[0025] Furthermore, a preferred implementation is provided, wherein the smart contract structure diagram obtaining unit is specifically:
[0026] Functions in the smart contract code are defined as nodes, and the calling relationships between functions are defined as edges.
[0027] Furthermore, a preferred implementation is provided, wherein the graph neural network in the feature extraction unit includes: a Graph Attention Network, a Graph Isomorphic Network, and a Temporal Message Propagation Graph Neural Network.
[0028] The present invention also provides a computer device, comprising a memory and a processor, wherein a computer program is stored in the memory. When the processor runs the computer program stored in the memory, the processor executes a multi-feature fusion blockchain smart contract vulnerability detection method based on graph neural network as described in any one of the above items.
[0029] The present invention also provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, a multi-feature fusion blockchain smart contract vulnerability detection method based on a graph neural network as described above is executed.
[0030] The present invention is beneficial in that:
[0031] The present invention solves the problem of needing a smart contract multi-version vulnerability detection method to detect whether there are vulnerabilities in the current mainstream smart contract version, so as to improve the detection efficiency of blockchain smart contracts.
[0032] The multi-feature fusion blockchain smart contract vulnerability detection method based on graph neural network described in the present invention uses graph neural network and multi-layer perceptron to extract smart contract features. The extracted features can express the characteristics of general multi-version smart contract vulnerabilities in a higher order and can detect more smart contract vulnerabilities.
[0033] A preferred implementation provided by the present invention can extract seven smart contract vulnerability features, including reentrancy vulnerabilities, timestamp dependency, expired compiler version, incorrect constructor name, use of outdated Solidity functions, use of tx.origin authorization, and unlocked pragma declarations. The extracted features can express the characteristics of different vulnerabilities at a higher level, making their features more recognizable. The smart contract vulnerability detection method solves the problem of detecting vulnerabilities in different versions of smart contracts and has a very high accuracy rate.
[0034] The present invention is applicable to the field of contract vulnerability detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 A detection flow chart of a multi-feature fusion blockchain smart contract vulnerability detection method based on graph neural network described in implementation mode 1;
[0036] Figure 2 The multi-layer perceptron described in the eleventh embodiment extracts the expert mode feature map.
[0037] Figure 3 This is an architecture diagram of the multi-feature fusion smart contract vulnerability detection method described in Implementation Method 11.
[0038] Figure 4 This is a diagram showing the effect of the experiment for reentrancy vulnerability and timestamp dependency vulnerability described in Implementation 11.
[0039] Figure 5 This is a diagram showing the effect of the experiment on other vulnerabilities described in Implementation Mode 11. DETAILED DESCRIPTION
[0040] In order to make the technical solutions and advantages of the present invention more clearly described, several embodiments of the present invention are now described in further detail in conjunction with the accompanying drawings. However, the various embodiments described below are only several preferred embodiments of the present invention and are not intended to limit the invention.
[0041] Implementation method 1, see Figure 1 This embodiment describes a multi-feature fusion blockchain smart contract vulnerability detection method based on a graph neural network, the method comprising:
[0042] Crawl the smart contracts deployed on the blockchain and obtain the smart contract data set;
[0043] Process the smart contract dataset according to the smart contract vulnerability detection tool, obtain the smart contracts with vulnerabilities, and mark all smart contracts;
[0044] Determine the type of the obtained smart contract with the vulnerability;
[0045] Convert all the smart contract source codes into smart contract structure diagrams;
[0046] Using a graph neural network to extract the smart contract structure diagram, and using a multi-layer perceptron to extract expert pattern features in the smart contract source code;
[0047] Fusing the extracted features of the smart contract structure diagram and the expert mode features, learning the fused features through a neural network, and performing vulnerability prediction for different smart contract vulnerability types;
[0048] Determine whether there is a vulnerability based on the vulnerability prediction results.
[0049] In practical applications, smart contract files written in Solidity can be crawled from Ethereum blockchain browsers, including but not limited to Ethereum blockchain browsers.
[0050] This embodiment describes the fusion of the extracted features of the smart contract structure graph and the expert mode features, learning the fused features through a neural network and performing vulnerability prediction for different smart contract vulnerability types; in fact, the graph neural network and the multi-layer perceptron are used to extract the features of the smart contract structure graph and the expert mode features, and the fused features are finally learned and predicted through the ReLU layer and the Sigmoid layer in the neural network.
[0051] The detection method described in this embodiment uses a graph neural network and a multi-layer perceptron to extract smart contract features. The extracted features can express the characteristics of general multi-version smart contract vulnerabilities at a higher level, and can detect more smart contract vulnerabilities, thereby improving the detection efficiency of blockchain smart contracts.
[0052] Implementation method 2. This implementation method further limits the multi-feature fusion blockchain smart contract vulnerability detection method based on graph neural network described in implementation method 1. The smart contract vulnerability detection tools include but are not limited to: Slither, Oyente and Securify.
[0053] Slither described in this embodiment is a static analysis framework for smart contracts, which is used to provide relevant information about Ethereum smart contracts. By converting Solidity smart contracts into an intermediate representation called Slither, Slither can obtain the inheritance graph and control flow graph of the smart contract, and perform vulnerability analysis on Slither through a predefined analysis list. It can automatically perform program analysis, data flow and taint tracking, and can be mainly applied to automatic vulnerability detection, automatic optimization detection, assisting users to understand smart contracts and assisting code review; Oyente is a symbolic execution tool that can be used directly with the Ethereum virtual machine without accessing high-level language forms. It can not only detect unsafe errors, but also analyze the actual execution path of each code; Secruify is a smart contract security analysis tool that can automatically analyze and prove whether a given smart contract is safe. Secruity mainly includes two steps. First, the dependency graph of the smart contract is analyzed, and the precise semantic information is analyzed from it. Then, a specific code pattern for calculating asset owners is checked, and the security analysis results of the smart contract are given accordingly. This implementation method uses a variety of smart contract vulnerability detection tools to label the smart contract data set, obtain smart contracts with vulnerabilities, and vote on the final labeling results through a multiple-vote election mechanism to ensure the accuracy of the data.
[0054] In actual applications, the smart contract vulnerability detection tools include but are not limited to the tools described above to detect vulnerabilities.
[0055] Implementation method three: This implementation method is a further limitation of the multi-feature fusion blockchain smart contract vulnerability detection method based on graph neural network described in implementation method one. The method converts all the smart contract source codes into a smart contract structure diagram, specifically: defining the functions in the smart contract code as nodes, and defining the calling relationships between functions as edges.
[0056] Specifically, by scanning the smart contract code that has been determined to have vulnerabilities, the qualified functions in the smart contract are defined as nodes, where the nodes are divided into primary nodes and secondary nodes. The mutual calling relationships between functions are defined as edges, and the smart contract graph is constructed through nodes and edges.
[0057] Implementation method 4. This implementation method is a further limitation of the multi-feature fusion blockchain smart contract vulnerability detection method based on graph neural network described in implementation method 1. The graph neural network and multi-layer perceptron extraction are used to extract features of the smart contract structure diagram. The graph neural network includes but is not limited to: Graph Attention Network (GAT for short), Graph Isomorphic Network (GIN for short) and Temporal Message Propagation Graph Neural Network (TMP for short).
[0058] Specifically, this implementation uses three graph neural network models, GIN, GAT, and TMP, to extract features from the smart contract graph for reentrancy vulnerabilities and timestamp dependency vulnerabilities, and uses a multi-layer perceptron to extract expert mode features from the smart contract code. For vulnerabilities such as expired compiler versions, incorrect constructor names, use of outdated Solidity functions, use of tx.origin authorization, and unlocked pragma declarations, it is impossible to construct a smart contract graph because there is no mutual call relationship between functions. It is only necessary to extract the corresponding pattern features according to the expert mode.
[0059] Implementation method 5: A multi-feature fusion blockchain smart contract vulnerability detection device based on graph neural network described in this implementation method, the device includes:
[0060] A smart contract data set acquisition unit is used to crawl the smart contracts deployed on the blockchain and obtain the smart contract data set;
[0061] The smart contract vulnerability unit is used to process the smart contract data set according to the smart contract vulnerability detection tool, obtain smart contracts with vulnerabilities, and mark all smart contracts;
[0062] A vulnerability type determination unit, used to determine the type of the acquired smart contract with the vulnerability;
[0063] A smart contract structure diagram acquisition unit, used to convert all the smart contract source codes into a smart contract structure diagram;
[0064] A feature extraction unit, used to extract the smart contract structure diagram using a graph neural network, and to extract expert mode features in the smart contract source code using a multi-layer perceptron;
[0065] A vulnerability prediction unit, used to fuse the features of the extracted smart contract structure diagram and the expert mode features, learn the fused features through a neural network, and perform vulnerability prediction for different smart contract vulnerability types;
[0066] The vulnerability result acquisition unit is used to determine whether a vulnerability exists according to the vulnerability prediction result.
[0067] The detection device described in this embodiment uses a graph neural network and a multi-layer perceptron to extract smart contract features. The extracted features can express the characteristics of general multi-version smart contract vulnerabilities at a higher level, and can detect more smart contract vulnerabilities, thereby improving the detection efficiency of blockchain smart contracts.
[0068] Implementation method six. This implementation method is a further limitation of the multi-feature fusion blockchain smart contract vulnerability detection device based on graph neural network described in implementation method five. The smart contract vulnerability detection tools include but are not limited to: Slither, Oyente or Securify.
[0069] Implementation VII: This implementation is a further limitation of the multi-feature fusion blockchain smart contract vulnerability detection device based on graph neural network described in Implementation 5. The smart contract structure diagram acquisition unit is specifically:
[0070] Functions in the smart contract code are defined as nodes, and the calling relationships between functions are defined as edges.
[0071] Implementation method eight. This implementation method is a further limitation of the multi-feature fusion blockchain smart contract vulnerability detection device based on graph neural network described in implementation method five. The graph neural network in the feature extraction unit includes but is not limited to: Graph Attention Network, Graph Isomorphic Network and Temporal Message Propagation Graph Neural Network.
[0072] Embodiment 9. A computer device described in this embodiment includes a memory and a processor, wherein a computer program is stored in the memory. When the processor runs the computer program stored in the memory, the processor executes a multi-feature fusion blockchain smart contract vulnerability detection method based on graph neural network as described in any one of embodiments 1 to 4.
[0073] Implementation method ten, a computer-readable storage medium as described in this implementation method, on which a computer program is stored, and when the computer program is executed by a processor, a multi-feature fusion blockchain smart contract vulnerability detection method based on a graph neural network as described in any one of implementation methods one to four is executed.
[0074] Implementation Method 11: See Figure 2 , Figure 3 , Figure 4 and Figure 5This embodiment provides a specific implementation of the multi-feature fusion blockchain smart contract vulnerability detection method based on graph neural network described in Implementation 1, and has explanations of Implementation 1 to Implementation 4, specifically:
[0075] Taking the smart contract code crawled from the Ethereum blockchain browser as an example, the method includes:
[0076] Step 1: Build a smart contract test set and crawl the smart contract data set from the Ethereum blockchain browser. This implementation method obtains 40,932 Ethereum smart contracts, with a total of approximately 307,396 functions. After processing the unqualified smart contracts through an automated tool written in Python, it was detected that approximately 5,013 of these functions called the call.value method at least once, making them potentially vulnerable to reentrancy vulnerabilities. Approximately 4,833 functions contain block.timestamp statements, which makes them vulnerable to timestamp dependency vulnerabilities. This implementation method detects 5,013 smart contracts for reentrancy vulnerabilities, 4,833 smart contracts for timestamp dependency vulnerabilities, and approximately 5,000 smart contracts containing the remaining five vulnerabilities.
[0077] Step 2: Use smart contract vulnerability detection tools such as Slither, Oyente, and Securify to mark the smart contract test set, and then vote on the final marking result through a multiple-vote mechanism.
[0078] Step 3: Use the specified vulnerability type for detection, and only detect whether there are vulnerabilities of the specified type in the smart contract at a time.
[0079] Step 4: Scan the smart contract code and define the qualified functions in the smart contract as nodes. The nodes are divided into primary nodes and secondary nodes. The mutual calling relationship between functions is defined as edges. The smart contract graph is constructed through nodes and edges.
[0080] Step 5: For reentrancy vulnerabilities and timestamp dependency vulnerabilities, first use the three graph neural network models GIN, GAT, and TMP to extract features from the smart contract graph, and then use Figure 2The multi-layer perceptron 3-100-250 shown in the figure extracts expert mode features from the smart contract source code. For vulnerabilities such as expired compiler versions, incorrect constructor names, use of outdated Solidity functions, use of tx.origin authorization, and unlocked pragma declarations, it is impossible to build a smart contract graph because there is no mutual call relationship between functions. It is only necessary to extract the corresponding mode features according to the expert mode. Among them, 3-100-250 represents 3 expert mode dimensions, which are trained with 100 hidden layer nodes and then output 250-dimensional features.
[0081] Step 6: The features extracted by the three graph neural networks GIN, GAT, and TMP and the features extracted by the three expert modes are firstly processed as follows: Figure 3 The 250-1-200 ReLU activation function layer shown in the figure is then passed through a 200-1-1 Sigmoid layer, and then the vector output by the ReLU activation function layer is multiplied by the weight output by the Sigmoid layer through a 1-1-200 Multiply layer, and then the six products are input into a 1200-6-200 Concatenate layer for fusion. After the fusion features are flattened, they are passed through a 1200-100 ReLU activation function layer and a 100-1 Sigmoid layer for vulnerability detection. Among them, the 250-1-200 form represents a 250-dimensional input, 1 hidden layer node, and a 200-dimensional output. The 1200-100 form represents a 1200-dimensional input and a 100-dimensional output.
[0082] Step 7: Determine whether there are related vulnerabilities based on the prediction results. The final classification result accuracy is as follows: Figure 4 As shown. The detection method proposed in this embodiment has an accuracy rate of 75.68% when identifying reentrancy vulnerabilities, which is the highest accuracy rate in the prior art and is better than the previous neural network smart contract vulnerability detection tool. The detection method proposed in this embodiment has an accuracy rate of 81.09% when identifying timestamp dependency vulnerabilities, which is also the highest detection accuracy rate and is better than the prior art. Figure 5 As shown, the accuracy of detecting the remaining five vulnerabilities is also extremely high. When detecting vulnerabilities in expired compiler versions, the accuracy is 71.74%; when detecting vulnerabilities in incorrect constructor names, the detection accuracy is as high as 95.74%; when detecting vulnerabilities in the use of outdated Solidity functions, the detection accuracy is as high as 99.67%; when detecting vulnerabilities in the use of tx.origin authorization, the detection accuracy is as high as 93.48%; when detecting vulnerabilities in unlocked pragma declarations, the detection accuracy is 73.91%.
[0083] The present application is described in detail above through specific implementation methods, but the above is only a preferred implementation method of the present application and is not intended to limit the present application. Any modifications, combinations of implementation methods, equivalent substitutions and improvements made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A multi-feature fusion blockchain smart contract vulnerability detection method based on graph neural network, characterized in that: The method comprises: Crawl the smart contracts deployed on the blockchain and obtain the smart contract data set; Process the smart contract dataset according to the smart contract vulnerability detection tool, obtain the smart contracts with vulnerabilities, and mark all smart contracts; Determine the type of the obtained smart contract with the vulnerability; Convert all the smart contract source codes into smart contract structure diagrams; The smart contract structure diagram is extracted using a graph neural network, including: extracting features of the smart contract diagram using three graph neural network models, GIN, GAT, and TMP, for reentrancy vulnerabilities and timestamp dependency vulnerabilities, and extracting expert mode features in the smart contract source code using a multi-layer perceptron; The extracted features of the smart contract structure diagram and the expert mode features are fused, and the fused features are learned by the ReLU layer and the Sigmoid layer in the neural network to predict vulnerabilities for different smart contract vulnerability types; Determine whether there is a vulnerability based on the vulnerability prediction results.
2. According to claim 1, a multi-feature fusion blockchain smart contract vulnerability detection method based on graph neural network is characterized in that: The smart contract vulnerability detection tools include: Slither, Oyente and Securify.
3. According to claim 1, a multi-feature fusion blockchain smart contract vulnerability detection method based on graph neural network is characterized in that: The converting of all the smart contract source codes into a smart contract structure diagram specifically includes: defining functions in the smart contract code as nodes, and defining calling relationships between functions as edges.
4. A multi-feature fusion blockchain smart contract vulnerability detection device based on graph neural network, characterized in that: The device comprises: A smart contract data set acquisition unit is used to crawl the smart contracts deployed on the blockchain and obtain the smart contract data set; The smart contract vulnerability unit is used to process the smart contract data set according to the smart contract vulnerability detection tool, obtain smart contracts with vulnerabilities, and mark all smart contracts; A vulnerability type determination unit, used to determine the type of the acquired smart contract with the vulnerability; A smart contract structure diagram acquisition unit, used to convert all the smart contract source codes into a smart contract structure diagram; A feature extraction unit is used to extract the smart contract structure diagram using a graph neural network, including: extracting features of the smart contract diagram using three graph neural network models, GIN, GAT, and TMP, for reentrancy vulnerabilities and timestamp dependency vulnerabilities, and extracting expert mode features in the smart contract source code using a multi-layer perceptron; A vulnerability prediction unit, used to fuse the features of the extracted smart contract structure diagram and the expert mode features, learn the fused features through the ReLU layer and the Sigmoid layer in the neural network, and predict vulnerabilities for different smart contract vulnerability types; The vulnerability result acquisition unit is used to determine whether a vulnerability exists according to the vulnerability prediction result.
5. According to claim 4, a multi-feature fusion blockchain smart contract vulnerability detection device based on graph neural network is characterized in that: The smart contract vulnerability detection tools include: Slither, Oyente or Securify.
6. According to claim 4, a multi-feature fusion blockchain smart contract vulnerability detection device based on graph neural network is characterized in that: The smart contract structure diagram acquisition unit is specifically: Functions in the smart contract code are defined as nodes, and the calling relationships between functions are defined as edges.
7. A computer device, characterized in that: It includes a memory and a processor, wherein a computer program is stored in the memory. When the processor runs the computer program stored in the memory, the processor executes a multi-feature fusion blockchain smart contract vulnerability detection method based on graph neural network as described in any one of claims 1 to 3.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which, when executed by a processor, executes a multi-feature fusion blockchain smart contract vulnerability detection method based on a graph neural network as described in any one of claims 1 to 3.
Citation Information
Patent Citations
Intelligent contract vulnerability detection method based on expert rules and serialized modeling
CN112035841A
Codec-based intelligent contract vulnerability detection interpretability method
CN112035842A