EOSIO smart contract vulnerability detection method of adaptive multi-channel graph convolutional network
By applying an adaptive multi-channel graph convolution network and global fusion attention mechanism in EOSIO smart contracts, the problem that the existing technology cannot detect vulnerabilities in EOSIO smart contracts is solved, and efficient and accurate vulnerability detection effects are achieved.
Patent Information
- Application Number
- CN202411694613.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-25
- Publication Date
- 2025-03-07
AI Technical Summary
The existing technology cannot apply deep learning to EOSIO smart contracts for vulnerability detection, mainly due to significant differences in the network platform, which makes vulnerability detection methods developed by Ethereum smart contracts unable to be directly applied to EOSIO smart contracts.
Adaptive multi-channel graph convolution network (EAM-GCN) is used to combine global fusion attention mechanism, and the control flow graph (CFG) and data flow graph (DFG) of EOSIO smart contracts are generated through the wasma tool, and the content of these graphs is learned in the graph convolution network to identify vulnerabilities in the smart contract.
The vulnerability detection of EOSIO smart contracts is realized, which significantly improves the accuracy and efficiency of detection, reduces the dependence on expert knowledge, and can effectively capture the syntax and semantic characteristics of smart contracts.
Smart Images

Figure CN119583145A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a network vulnerability detection method, and more specifically to an EOSIO smart contract vulnerability detection method based on an adaptive multi-channel graph convolutional network. Background Art
[0002] Traditional vulnerability detection methods include symbolic execution, fuzz testing, and formal verification, each of which has its limitations in detecting smart contracts. Symbolic execution treats specific variables as symbolic variables and explores all program execution paths to analyze vulnerabilities. However, it faces the problem of path explosion. Fuzz testing generates a large number of test cases and executes them in the program. Due to the randomness and blindness of the test cases, it may not cover all execution paths, so there is a seed coverage problem. Formal verification is a mathematical and logical method used to verify the security of a system. However, this technology is highly dependent on mathematical derivation and verification processes.
[0003] Traditional vulnerability detection methods build application-specific logical rules that rely on domain experts, which is time-consuming and limited by expert knowledge. To address this challenge, deep learning-based methods have gradually become a promising approach. These methods generate initial embedding vectors by extracting rich features from source code, which are then input into a neural network to capture and identify potential vulnerability patterns through model learning. Ultimately, the neural network can autonomously generate classification results to achieve automatic detection of vulnerabilities. This approach not only significantly reduces the reliance on expert knowledge, but also correspondingly improves the accuracy and efficiency of detection.
[0004] Smart contract vulnerability detection methods using deep learning are generally divided into two categories. The first category regards the code as a natural language sequence and applies technical means such as long short-term memory network (LSTM) and bidirectional long short-term memory network (BiLSTM) for vulnerability detection. The second category is to build a code graph for the source code and use graph neural networks such as graph convolutional neural network (GCN) and graph attention neural network (GAT) to detect vulnerabilities. However, the former faces challenges in representing the rich semantics and strict grammatical rules of the code, resulting in poor detection results. In contrast, the latter represents the source code of the smart contract through control flow graph (CFG), data flow graph (DFG), abstract syntax tree (AST) or a combination thereof, which can better capture syntax and semantics.
[0005] It is important to note that current vulnerability detection methods using deep learning are designed for Ethereum smart contracts. It is not currently possible to apply deep learning to EOSIO smart contracts for vulnerability detection. Due to significant differences in network platforms, including calling conventions, seed formats, transaction dependencies, and notification mechanisms, vulnerability detection methods developed for Ethereum smart contracts cannot currently be directly applied to EOSIO smart contracts. Summary of the invention
[0006] The purpose of this invention is to provide an EOSIO smart contract vulnerability detection method based on an adaptive multi-channel graph convolutional network to solve the problem that deep learning cannot be applied to EOSIO smart contracts for vulnerability detection.
[0007] The object of the present invention is achieved in that:
[0008] An EOSIO smart contract vulnerability detection method based on an adaptive multi-channel graph convolutional network includes the following steps:
[0009] S1. Use the wasma tool to generate the control flow graph CFG and data flow graph DFG of the smart contract function to be tested; the control flow graph CFG and data flow graph DFG are used together to express the syntax and semantics of the code.
[0010] S2. Adopt the Euclidean distance-based adaptive multi-channel graph convolutional network EAM-GCN to learn the contents of control flow graphs CFG and DFG.
[0011] S3. After the feature vector concatenation process in the control flow graph CFG and data flow graph DFG learned by the adaptive multi-channel graph convolutional network EAM-GCN based on Euclidean distance, the semantic features extracted from the control flow graph CFG and data flow graph DFG of the source code are fused using the global fusion attention mechanism, and the obtained global code features are classified using a classifier to identify the existence of the EOSIO smart contract vulnerability to be detected.
[0012] Furthermore, step S2 includes the following sub-steps:
[0013] S2-1 generates a topological graph, a KNN graph, and a Euclidean distance graph as feature structure graphs.
[0014] S2-2 uses the graph convolution network Specific-GCN to extract node features in the topological map, KNN map and Euclidean distance map respectively, and uses the common graph convolution network Common-GCN with shared parameters to extract shared embeddings between the topological map, KNN map and Euclidean distance map.
[0015] S2-3 uses the scaled dot product attention module to integrate the features extracted by the graph convolution network Specific-GCN and the general graph convolution network Common-GCN.
[0016] Furthermore, the original graph of the control flow graph CFG or the data flow graph DFG is used as the topology graph G t :
[0017] G t =(A t,X t )
[0018] Among them, A t represents the input adjacency matrix, X t Represents the input node feature matrix.
[0019] Furthermore, the KNN graph G is constructed based on the node feature matrix X k :
[0020] G k =(A k ,X)
[0021] Among them, A k is the adjacency matrix of the KNN graph.
[0022] The specific construction method is: first, calculate the cosine similarity between each pair of nodes to generate a similarity matrix S; then, for each node i, select the k nodes most similar to it as its neighbors according to the similarity matrix S; k The corresponding elements in are set to 1, and node i is connected to these k nodes to construct the adjacency matrix A of the KNN graph. k .
[0023] Furthermore, the Euclidean distance graph G is constructed based on the node feature matrix X e :
[0024] G e =(A e ,X)
[0025] Among them, A e is the adjacency matrix of the Euclidean distance graph.
[0026] The specific construction method is: first, the Euclidean distance between each pair of nodes is calculated to form the Euclidean distance matrix E; then, if the distance between two nodes is less than or equal to a predetermined threshold, the adjacency matrix A of the Euclidean distance graph is converted into e The corresponding elements in are set to 1 to add edges between them; thus constructing the adjacency matrix A that defines the Euclidean distance graph e .
[0027] Furthermore, the specific method of using the common graph convolutional network Common-GCN to extract shared embeddings between the topological graph, the KNN graph, and the Euclidean distance graph includes the following sub-steps:
[0028] S2-2-1 Extracting node embeddings from KNN graphs using Common-GCN
[0029]
[0030] in, for is a diagonal matrix, and And A k is the adjacency matrix of the KNN graph, I K is the identity matrix; Indicates the node embedding extracted at the (l-1)th layer in the KNN graph, and the initial embedding is the node feature matrix X; represents the weight matrix of layer l in a general GCN.
[0031] S2-2-2 Extracting node embeddings from Euclidean distance graphs using the common graph convolutional network Common-GCN
[0032]
[0033] in, for is a diagonal matrix, and And A e is the adjacency matrix of the Euclidean distance graph, I e is the identity matrix; It represents the node embedding extracted from the (l-1)th layer in the Euclidean distance graph, and the initial embedding is the node feature matrix X.
[0034] S2-2-3 Extracting node embeddings from topological graphs using the common graph convolutional network Common-GCN
[0035]
[0036] in, for is a diagonal matrix, and And A t is the adjacency matrix of the topological graph, I t is the identity matrix; It represents the node embedding extracted from the (l-1)th layer in the topology graph, and the initial embedding is the node feature matrix X.
[0037] S2-2-4 Use the following formula to calculate the common embedding Z between the topological graph, KNN graph and Euclidean distance graph c :
[0038]
[0039] Furthermore, the specific operation of step S2-3 includes the following sub-steps:
[0040] S2-3-1 will embed Z connection as follows:
[0041] Z = concat(Z t ,Z k ,Z e ,Z c )
[0042] Among them, Z t represents a special convolution to extract features from the topological graph, Z k represents a special convolution to extract features from the KNN graph, Z e Denotes a special convolution to extract features from the Euclidean distance map, Z c Represents the common embedding between topological graph, KNN graph and Euclidean distance graph.
[0043] S2-3-2 performs the following three linear transformations on the embedding Z to obtain the query vector Q, key vector K, and value vector V:
[0044] Q=ZW Q ; K = ZW K ; V = ZW v
[0045] Among them, W Q , W K and W V They represent the weight matrices of the linear layer respectively.
[0046] S2-3-3 calculates the dot product of the query vector Q and the transposed key vector K to determine the attention score Scores; the attention score Scores is obtained by adjusting the scaling factor of the dot product:
[0047]
[0048] Among them, d k represents the dimension of the query vector Q; T represents the transpose of the vector.
[0049] S2-3-4 uses the softmax function to normalize the attention scores:
[0050]
[0051] S2-3-5 aggregates information in the sequence, and adds the attention weight W to the value vector V to obtain the output Output with the aggregated information value vector:
[0052] Output=W·V
[0053] S2-3-6 integrates information through the mean of the orientation quantity, denoted as: Mean Output =mean(Output); compress the sequence information into a representative vector; use linear transformation to obtain the message feature tensor of the graph Final Output :
[0054] Final Output =Mean Output ·W o
[0055] Among them, W o is the weight matrix of the linear layer.
[0056] S2-3-7 adjusts the processed vector through linear transformation and maps it to the output dimension to synthesize the sequence information into a refined output.
[0057] EOSIO smart contracts use WebAssembly (Wasm) as their execution code, which is a binary format known for its efficient execution speed and cross-platform compatibility. Since Wasm is encoded in binary, it cannot be directly parsed into an abstract syntax tree (AST) at the source code level, which poses challenges to static analysis and vulnerability detection of EOSIO smart contracts. In addition, the lack of mature Wasm decompilation tools to convert Wasm binary files into human-readable source code further increases the difficulty of analysis.
[0058] The present invention uses a neural network to detect vulnerabilities directly in the Wasm binary file, that is, to detect vulnerabilities in EOSIO smart contracts using a graph neural network. First, the wasma tool is used to generate the control flow graph CFG and data flow graph DFG of the smart contract function to be detected. Among them, the control flow graph CFG represents the control flow information, its nodes contain the comprehensive semantic details of the basic blocks, and the edges represent the execution order; while the data flow graph DFG represents the flow and transfer of data within the program. The control flow graph CFG and the data flow graph DFG are used together to fully express the syntax and semantics of the code.
[0059] In order to capture grammatical and semantic features, the present invention adopts an adaptive multi-channel graph convolution network EAM-GCN based on Euclidean distance (abbreviated as "Euclidean distance") to learn the content in the control flow graph CFG and the data flow graph DFG. In this process, a topological graph, a k-nearest neighbor (KNN) graph and a Euclidean distance graph are first generated as feature structure graphs. Then, the node features of the three graphs are extracted using a specific graph convolution network Specific-GCN, and the shared embedding between these graphs is extracted using a general graph convolution network Common-GCN with shared parameters. In this way, the information space within the function can be fully utilized. Subsequently, the features extracted by the specific graph convolution network Specific-GCN and the general graph convolution network Common-GCN are integrated using a scaled dot product attention module. In addition, after the feature vector splicing process in the learning control flow graph CFG and the data flow graph DFG of the adaptive multi-channel graph convolution network EAM-GCN, in order to obtain global code features, the present invention uses a global fusion attention mechanism to fuse the semantic features extracted from the control flow graph CFG and the data flow graph DFG of the source code, and then classifies these features using a classifier. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] Figure 1 This is the overall architecture diagram of the vulnerability detection framework.
[0061] Figure 2 It is the framework diagram of the adaptive multi-channel graph convolutional network EAM-GCN.
[0062] Figure 3 It is a structural diagram of the global fusion attention GFA. DETAILED DESCRIPTION
[0063] The present invention is further described in detail below with reference to the accompanying drawings and embodiments.
[0064] like Figure 1 As shown, the vulnerability detection framework consists of four stages: semantic graph generation stage, information propagation stage, information readout stage and classification stage.
[0065] In the semantic graph generation phase, the wasma tool is used to generate the control flow graph CFG and data flow graph DFG of the function. Each block in the control flow graph CFG or data flow graph DFG represents a token with an intermediate representation, and the node embedding within each block is pre-trained using Word2Vec. The node feature matrix X is used to store all node embeddings in the control flow graph CFG or data flow graph DFG, and the adjacency matrix A is used to represent the edges in the graph.
[0066] In the information propagation stage, an adaptive multi-channel graph convolutional network (EAM-GCN) is used to update the semantic and structural embeddings of the function code graph and construct the message feature tensor.
[0067] In the information readout stage, the global fusion attention GFA merges the message feature tensors of the control flow graph CFG and the data flow graph DFG into a single tensor as input, and calculates the output global code graph feature tensor.
[0068] In the classification phase, a multi-layer perceptron (MLP) network uses the global code feature tensor generated in the information readout phase to classify functions to identify the presence of vulnerabilities.
[0069] like Figure 2 As shown in Figure 2, the adaptive multi-channel graph convolutional network EAM-GCN framework takes the adjacency matrix A and the node feature matrix X as input. In the adjacency matrix A, A ij =1, it means there is an edge between node i and node j; and A ij = 0, it means there is no edge between node i and node j. In order to capture the potential structure of nodes in the feature space, the following three graphs are constructed.
[0070] (1) Construct KNN graph G based on node feature matrix X k =(A k ,X). First, the cosine similarity between each pair of nodes is calculated to generate a similarity matrix S. Then, for each node i, the k nodes most similar to it are selected as its neighbors according to the similarity matrix S. k The corresponding elements in are set to 1, and node i is connected to these k nodes to construct the adjacency matrix A of the KNN graph. k .
[0071] (2) Construct the Euclidean distance graph G based on the node feature matrix X e =(A e ,X). First, the Euclidean distance between each pair of nodes is calculated to form the Euclidean distance matrix E. Then, if the distance between two nodes is less than or equal to a predetermined threshold, the adjacency matrix A is transformed into e The corresponding elements in are set to 1 to add edges between them. This constructs the adjacency matrix A that defines the Euclidean distance graph e .
[0072] (3) Use the original graphs of the control flow graph CFG and the data flow graph DFG as the topology graph G t =(A t ,X t ). That is, A t =A and X t =X.
[0073] In addition, for each graph, a specific graph convolutional network Specific-GCN is used to extract its unique feature information, and a common graph convolutional network Common-GCN with a parameter sharing strategy is used to extract common embedded features in the KNN graph Gk, the Euclidean distance graph Ge, and the topology graph Gt. The parameter sharing strategy not only effectively reduces the model complexity, but also enhances the generalization ability of the features. Finally, the scaled dot product attention mechanism is applied for feature fusion to construct the message feature tensor.
[0074] The following specific graph convolutional network Specific-GCN is used to calculate the output embedding Z of the KNN graph of the EOSIO smart contract k :
[0075]
[0076] Among them, ReLU represents the rectified linear unit activation function, express is a diagonal matrix, and And A k is the adjacency matrix of the KNN graph, I K is the identity matrix. This means that every node in the KNN graph is connected to itself. The initial value of is X. represents the weight matrix of layer l in a general GCN.
[0077] The output of the topological graph is embedded in Z t and the output embedding Z of the Euclidean distance graph e It can be calculated in a similar way.
[0078] There are now three specific output embeddings Z t , Z k and Z e , and jointly embedded in Z c Considering that node labels may be associated with one or more combinations of these embeddings, the present invention utilizes the scaled dot product attention mechanism att(Z t ,Z k ,Z e ,Z c ) to determine their respective importance.
[0079] Finally, in order to aggregate the information in the sequence, the attention weights and the value vector V are weighted and summed to obtain: Output = W V. The information is integrated by taking the mean of the orientation quantity, denoted as: Mean Output =mean(Output), which condenses the sequence information into a single representative vector.
[0080] To further refine this representation, a linear transformation is used to obtain the message feature map of the graph (CFG or DFG). Output , that is, Final Output =Mean Output ·W o , where W o is the weight matrix of the linear layer.
[0081] This transformation resizes the processed vector and maps it to a specific output dimension, thereby synthesizing the sequence information into a refined output.
[0082] like Figure 3 As shown in the figure, in order to improve the prediction ability of the model, a global fusion attention mechanism is introduced to fuse the features of the control flow graph CFG and the data flow graph DFG. Global fusion attention GFA can extract features from the feature graph while maintaining the original dimension, enhance the model's attention to important features, and ignore irrelevant information. Global fusion attention GFA combines spatial attention and channel attention to effectively enhance the ability of feature representation.
[0083] The EOSIO smart contract vulnerability detection method of the present invention based on an adaptive multi-channel graph convolutional network includes the following steps:
[0084] S1. Use the wasma tool to generate the control flow graph CFG and data flow graph DFG of the smart contract function to be tested; the control flow graph CFG and data flow graph DFG are used together to express the syntax and semantics of the code.
[0085] S2, using the Euclidean distance-based adaptive multi-channel graph convolutional network EAM-GCN to learn the content of the control flow graph CFG and DFG. Specifically, it includes the following sub-steps:
[0086] S2-1 generates a topological graph, a KNN graph, and a Euclidean distance graph as feature structure graphs.
[0087] ⑴ Take the original graph of the control flow graph CFG or the data flow graph DFG as the topology graph G t :
[0088] G t =(A t ,X t )
[0089] Among them, A t represents the input adjacency matrix, X t Represents the input node feature matrix.
[0090] ⑵Build KNN graph G based on node feature matrix X k :
[0091] Gk =(A k ,X)
[0092] Among them, A k is the adjacency matrix of the KNN graph.
[0093] The specific construction method is: first, calculate the cosine similarity between each pair of nodes to generate a similarity matrix S; then, for each node i, select the k nodes most similar to it as its neighbors according to the similarity matrix S; k The corresponding elements in are set to 1, and node i is connected to these k nodes to construct the adjacency matrix A of the KNN graph. k .
[0094] ⑶ Construct Euclidean distance graph G based on node feature matrix X e :
[0095] G e =(A e ,X)
[0096] Among them, A e is the adjacency matrix of the Euclidean distance graph.
[0097] The specific construction method is: first, calculate the Euclidean distance between each pair of nodes to form a Euclidean distance matrix E; then, if the distance between two nodes is less than or equal to a predetermined threshold, add an edge between them by setting the corresponding elements in the adjacency matrix Ae of the Euclidean distance graph to 1; thereby constructing the adjacency matrix Ae that defines the Euclidean distance graph.
[0098] S2-2 uses the graph convolution network Specific-GCN to extract node features in the topology map, KNN map, and Euclidean distance map respectively, and uses the common graph convolution network Common-GCN with shared parameters to extract shared embeddings between the topology map, KNN map, and Euclidean distance map. The specific method includes the following sub-steps:
[0099] S2-2-1 Extracting node embeddings from KNN graphs using Common-GCN
[0100]
[0101] in, for is a diagonal matrix, and And A k is the adjacency matrix of the KNN graph, I K is the identity matrix; Indicates the node embedding extracted at the (l-1)th layer in the KNN graph, and the initial embedding is the node feature matrix X; represents the weight matrix of layer l in a general GCN.
[0102] S2-2-2 Extracting node embeddings from Euclidean distance graphs using the common graph convolutional network Common-GCN
[0103]
[0104] in, for is a diagonal matrix, and And A e is the adjacency matrix of the Euclidean distance graph, I e is the identity matrix; It represents the node embedding extracted from the (l-1)th layer in the Euclidean distance graph, and the initial embedding is the node feature matrix X.
[0105] S2-2-3 Extracting node embeddings from topological graphs using the common graph convolutional network Common-GCN
[0106]
[0107] in, for is a diagonal matrix, and And A t is the adjacency matrix of the topological graph, I t is the identity matrix; It represents the node embedding extracted from the (l-1)th layer in the topology graph, and the initial embedding is the node feature matrix X.
[0108] S2-2-4 Use the following formula to calculate the common embedding Z between the topological graph, KNN graph and Euclidean distance graph c :
[0109]
[0110] S2-3 uses the scaled dot product attention module to integrate the features extracted by the graph convolution network Specific-GCN and the general graph convolution network Common-GCN. Its specific operation includes the following sub-steps:
[0111] S2-3-1 will embed Z connection as follows:
[0112] Z = concat(Z t ,Z k ,Z e ,Z c )
[0113] Among them, Z trepresents a special convolution to extract features from the topological graph, Z k represents a special convolution to extract features from the KNN graph, Z e Denotes a special convolution to extract features from the Euclidean distance map, Z c Represents the common embedding between topological graph, KNN graph and Euclidean distance graph.
[0114] S2-3-2 performs the following three linear transformations on the embedding Z to obtain the query vector Q, key vector K, and value vector V:
[0115] Q=ZW Q ; K = ZW K ; V = ZW V
[0116] Among them, W Q , W K and W V They represent the weight matrices of the linear layer respectively.
[0117] S2-3-3 calculates the dot product of the query vector Q and the transposed key vector K to determine the attention score Scores; the attention score Scores is obtained by adjusting the scaling factor of the dot product:
[0118]
[0119] Among them, d k represents the dimension of the query vector Q; T represents the transpose of the vector.
[0120] S2-3-4 uses the softmax function to normalize the attention scores:
[0121]
[0122] S2-3-5 aggregates information in the sequence, and adds the attention weight W to the value vector V to obtain the output Output with the aggregated information value vector:
[0123] Output=W·V
[0124] S2-3-6 integrates information through the mean of the orientation quantity, denoted as: Mean Output =mean(Output); compress the sequence information into a representative vector; use linear transformation to obtain the message feature tensor of the graph Final Output :
[0125] Final Output =Mean output ·W o
[0126] Among them, Wo is the weight matrix of the linear layer.
[0127] S2-3-7 adjusts the processed vector through linear transformation and maps it to the output dimension to synthesize the sequence information into a refined output.
[0128] S3. After the feature vector concatenation process in the control flow graph CFG and data flow graph DFG learned by the adaptive multi-channel graph convolutional network EAM-GCN based on Euclidean distance, the semantic features extracted from the control flow graph CFG and data flow graph DFG of the source code are fused using the global fusion attention mechanism, and the obtained global code features are classified using a classifier to identify the existence of the EOSIO smart contract vulnerability to be detected.
[0129] The message feature tensors of the CFG and DFG of the detected function are concatenated to form the initial global code graph tensor, and GFA is used to learn the final global code graph tensor. First, the global code graph tensor F is obtained by concatenating the message feature tensors of CFG and DFG in the following way:
[0130] F = concat(M1,M2)
[0131] Among them, M1 represents the message feature tensor of CFG generated by EAM-GCN, and M2 is the message feature tensor of DFG.
[0132] Next, the channel attention module calculates the channel attention map M using the following formula c (F):
[0133] M c (F)=σ(MLP(AvgPool(F))+MLP(MaxPool(F)))
[0134] Among them, AvgPool represents the global average pooling operation, MaxPool represents the maximum pooling operation, MLP represents the multi-layer perceptron, and σ represents the sigmoid activation function.
[0135] Furthermore, the spatial attention module calculates the spatial attention map M s (F), the formula is as follows:
[0136] M s (F) = σ(f n×n ([AvgPool(F); MaxPool(F)]))
[0137] Among them, f n×n Represents an n×n convolution operation, and [AvgPool(F); MaxPool(F)] represents the results of concatenating average pooling and maximum pooling along the channel.
[0138] Finally, the final global code graph tensor is calculated through GFA:
[0139]
[0140] First, the channel attention map is calculated and then element-wise multiplied with the original feature F to produce the intermediate result F′. Then the spatial attention map is calculated and element-wise multiplied with the intermediate result F′ to obtain the final result F″.
[0141] After obtaining the hidden features F″ generated by the global fusion attention mechanism (GFA), a multi-layer perceptron MLP is used to determine whether a given EOSIO smart contract function has a vulnerability. F″ is processed by a fully connected layer and finally a softmax function is applied to obtain the classification result. Represents the category prediction of n nodes, where is the probability of belonging to category c. It can be calculated as follows:
[0142]
[0143] in, As a normalizer for all categories, W represents the weight matrix used by the fully connected layer, and b represents the bias vector used by the fully connected layer.
[0144] Experimental setup for the present invention.
[0145] There are four types of vulnerabilities in the dataset: forged receipts, block information dependency, lack of authorization verification, and integer overflow. As shown in Table 1, the dataset contains 12,523 labeled smart contract functions, including 1,612 forged receipt vulnerability instances, 1,465 functions with block information dependency issues, 1,734 functions lacking authorization verification, 1,118 functions susceptible to integer overflow, and 6,594 normal functions without these vulnerabilities. The present invention randomly assigns 80% of the dataset as a training set, 10% as a validation set, so as to evaluate the model performance and adjust the parameters during the training process to prevent overfitting, and the remaining 10% as a test set to evaluate the performance of the training model and verify its generalization ability and practical application effect.
[0146] Table 1. Dataset of vulnerable functions
[0147]
[0148] In order to fully evaluate the model, we constructed two training sets with different labeling rates: 100 and 150 labeled nodes per category. Our model simultaneously trains four graph convolutional networks (GCNs) with a two-layer architecture and a hidden layer dimension of n. hid1Select from {512,768}, output dimension n hid2 Select from {32, 128, 256}. The present invention uses the Adam optimizer to adjust the learning rate in the range of 0.0001 to 0.0005. To prevent overfitting, the present invention sets the dropout rate to 0.5, the weight decay is set within {5e-3, 5e-4}, and the k value of the k-nearest neighbor graph varies between 2 and 10. The present invention explores the coefficients of consistency and difference constraints, selecting them in {0.01, 0.001, 0.0001} and {1e-10, 5e-9, 1e-9, 5e-8, 1e-8} respectively. To ensure the stability of the results, each experiment is repeated five times under the same data partition, and the average results are reported. The present invention uses accuracy, precision, recall and macro F1 score as the main indicators for model evaluation. The specific parameter settings are detailed in Table 2.
[0149] Table 2. Parameters of the model
[0150]
[0151] Evaluation of the effectiveness of the detection method of the present invention:
[0152] The present invention conducts experiments on the test set of smart contracts and evaluates the effectiveness of the method of the present invention by measuring the accuracy, precision, recall and F1 score of detecting four types of vulnerabilities. The four types of vulnerabilities include: false receipt FakeRec, block information dependency BlockinfoDep, lack of authorization verification LackAuth and integer overflow IntegerOver. The experimental results are shown in Table 3.
[0153] In Table 3, the column “Vulnerability” indicates the smart contracts marked with a specific vulnerability type. The column “ACC” shows the ratio of the proportion of samples correctly predicted by the model to the total number of samples. The column “Prec” gives the proportion of samples predicted by the model as positive that are actually positive. The column “Recall” indicates the proportion of samples correctly predicted by the model as positive among all actual positive samples. The column “F1” shows the F1 score, which is the harmonic mean of precision and recall. The sub-columns 100 and 150 indicate that the number of labeled nodes for each category is 100 and 150, respectively.
[0154] Table 3. Evaluation results
[0155]
[0156] The results in Table 3 show that the proposed method performs better when the number of labeled nodes in each category is 150. In this case, the average accuracy, precision, recall and F1 score reach 91.24%, 91.51%, 91.15% and 91.26% respectively. The experimental results show that EAM-GCN has significant potential in smart contract vulnerability detection.
[0157] This paper further compares EAM-GCN with other neural network methods to determine which neural network architecture can improve the accuracy of smart contract vulnerability detection. The compared neural networks are summarized as follows:
[0158] Transformer: The attention-based sequence transformation model, or Transformer, establishes a global dependency between input and output sequences through a multi-head self-attention mechanism. It uses an encoder-decoder architecture, where both the encoder and decoder consist of multiple layers of the same module. Each module contains a multi-head self-attention mechanism and a feedforward neural network.
[0159] GAT: This is an attention-based graph neural network architecture that uses an adaptively learned attention mechanism to assign different attention weights to each node, dynamically focusing on important neighbor nodes during information propagation.
[0160] Chevnet: This is a GCN network architecture using Chebyshev polynomials to approximate convolution operations on graphs, promote deep learning and extract features from graph-structured data. In smart contract vulnerability detection, the Chebyshev Graph Convolutional Network (Chebyshev GCN) improves the accuracy and efficiency of vulnerability detection by capturing structural information and dependencies in code graphs such as control flow graphs (CFGs) and data flow graphs (DFGs).
[0161] KNN-GCN: It is a graph convolutional network (GCN) that computes input based on a feature matrix based on cosine similarity and represented as a sparse KNN graph.
[0162] ED-GCN: This method uses graph neural networks to perform graph convolution operations based on the Euclidean distance between node features, capturing the spatial relationship between nodes and improving the analysis of graph structured data in the spatial distance dimension.
[0163] The network in the method of the present invention (EMA-GCN) is replaced with the above network for comparison, and the results are shown in Table 4. The results show that the detection method of the present invention performs well in vulnerability detection.
[0164] Table 4. Performance comparison of different models
[0165]
[0166] From the experimental results in Table 4, we can observe that: First, the graph-based method EAM-GCN outperforms the Transformer that treats the graph representation of the code as a sequence. Specifically, EAM-GCN shows an average accuracy improvement of 31.52% and an F1 score improvement of 33.24% in vulnerability detection compared to Transformer. It can be seen that treating the graph as a sequence fails to capture the execution order of statements and data relationships, resulting in poor performance in smart contract vulnerability detection. Therefore, representing the source code in a graph format is more conducive to obtaining better detection results. Secondly, EAM-GCN significantly outperforms GAT, Chevnet, KNN-GCN, and ED-GCN networks in accuracy, precision, recall, and F1 scores. The results show that EAM-GCN can extract more useful information than these networks.
Claims
1. An EOSIO smart contract vulnerability detection method based on an adaptive multi-channel graph convolutional network, characterized in that: The following steps are involved: S1. Use the wasma tool to generate the control flow graph CFG and data flow graph DFG of the smart contract function to be tested; the control flow graph CFG and data flow graph DFG are used together to express the syntax and semantics of the code; S2, using the Euclidean distance-based adaptive multi-channel graph convolutional network EAM-GCN to learn the content of the control flow graph CFG and the data flow graph DFG; S3. After the feature vector concatenation process in the control flow graph CFG and data flow graph DFG learned by the adaptive multi-channel graph convolutional network EAM-GCN based on Euclidean distance, the semantic features extracted from the control flow graph CFG and data flow graph DFG of the source code are fused using the global fusion attention mechanism, and the obtained global code features are classified using a classifier to identify the existence of the EOSIO smart contract vulnerability to be detected.
2. The EOSIO smart contract vulnerability detection method according to claim 1, characterized in that: Step S2 includes the following sub-steps: S2-1 generates a topological graph, a KNN graph, and a Euclidean distance graph as a feature structure graph; S2-2 uses the graph convolution network Specific-GCN to extract node features in the topology map, KNN map, and Euclidean distance map respectively, and uses the common graph convolution network Common-GCN with shared parameters to extract shared embeddings between the topology map, KNN map, and Euclidean distance map; S2-3 uses the scaled dot product attention module to integrate the features extracted by the graph convolution network Specific-GCN and the general graph convolution network Common-GCN.
3. The EOSIO smart contract vulnerability detection method according to claim 2, characterized in that: The original graph of the control flow graph CFG or data flow graph DFG is used as the topology graph G t : G t =(A t ,X t ) Among them, A t represents the input adjacency matrix, X t Represents the input node feature matrix.
4. The EOSIO smart contract vulnerability detection method according to claim 2, characterized in that: Construct KNN graph G based on node feature matrix X k : G k =(A k ,X) Among them, A k is the adjacency matrix of the KNN graph; The specific construction method is: first, calculate the cosine similarity between each pair of nodes to generate a similarity matrix S; then, for each node i, select the k nodes most similar to it as its neighbors according to the similarity matrix S; k The corresponding elements in are set to 1, and node i is connected to these k nodes to construct the adjacency matrix A of the KNN graph. k .
5. The EOSIO smart contract vulnerability detection method according to claim 2, characterized in that: Constructing Euclidean distance graph G based on node feature matrix x e : G e =(A e ,X) Among them, A e is the adjacency matrix of the Euclidean distance graph; The specific construction method is: first, the Euclidean distance between each pair of nodes is calculated to form the Euclidean distance matrix E; then, if the distance between two nodes is less than or equal to a predetermined threshold, the adjacency matrix A of the Euclidean distance graph is converted into e The corresponding elements in are set to 1 to add edges between them; thus constructing the adjacency matrix A that defines the Euclidean distance graph e .
6. The EOSIO smart contract vulnerability detection method according to claim 2, characterized in that: The specific method of using the common graph convolutional network Common-GCN to extract shared embeddings between the topological graph, KNN graph, and Euclidean distance graph includes the following sub-steps: S2-2-1 Extracting node embeddings from KNN graphs using Common-GCN in, for is a diagonal matrix, and And A k is the adjacency matrix of the KNN graph, I K is the identity matrix; Indicates the node embedding extracted at the (l-1)th layer in the KNN graph, and the initial embedding is the node feature matrix X; Represents the weight matrix of the lth layer in the general GCN; S2-2-2 Extracting node embeddings from Euclidean distance graphs using the common graph convolutional network Common-GCN in, for is a diagonal matrix, and And A e is the adjacency matrix of the Euclidean distance graph, I e is the identity matrix; It represents the node embedding extracted at the (l-1)th layer in the Euclidean distance graph, and the initial embedding is the node feature matrix X; S2-2-3 Extracting node embeddings from topological graphs using the common graph convolutional network Common-GCN in, for is a diagonal matrix, and And A t is the adjacency matrix of the topological graph, I t is the identity matrix; Indicates the node embedding extracted from the (l-1)th layer in the topology graph, and the initial embedding is the node feature matrix X; S2-2-4 Use the following formula to calculate the common embedding Z between the topological graph, KNN graph and Euclidean distance graph c :
7. The EOSIO smart contract vulnerability detection method according to claim 2, characterized in that: The specific operation method of step S2-3 includes the following sub-steps: S2-3-1 will embed Z connection as follows: Z=concat(Z t ,From k ,From e ,From c ) Among them, Z t represents a special convolution to extract features from the topological graph, Z k represents a special convolution to extract features from the KNN graph, Z e Denotes a special convolution to extract features from the Euclidean distance map, Z c Represents the common embedding between topological graph, KNN graph and Euclidean distance graph; S2-3-2 performs the following three linear transformations on the embedding Z to obtain the query vector Q, key vector K, and value vector V: Q=ZW Q ;K=ZW K ;V=ZW V Among them, W Q , W K and W V Represent the weight matrices of the linear layer respectively; S2-3-3 calculates the dot product of the query vector Q and the transposed key vector K to determine the attention score Scores; the attention score Scores is obtained by adjusting the scaling factor of the dot product: Among them, d k represents the dimension of the query vector Q; T represents the transpose of the vector; S2-3-4 uses the softmax function to normalize the attention scores: S2-3-5 aggregates information in the sequence, and adds the attention weight W to the value vector V to obtain the output Output with the aggregated information value vector: Output=W·V S2-3-6 integrates information through the mean of the orientation quantity, denoted as: Mean output =mean(Output); compress the sequence information into a representative vector; use linear transformation to obtain the message feature tensor of the graph Final Output : Final output =Mean output ·W o Among them, W o is the weight matrix of the linear layer; S2-3-7 adjusts the processed vector through linear transformation and maps it to the output dimension to synthesize the sequence information into a refined output.
Citation Information
Cited By
Defect detection method and system based on joint distribution optimization and structural knowledge guidance
CN120411083A
Defect detection method and system based on joint distribution optimization and structural knowledge guidance
CN120411083B
Multi-modal graph learning-based circRNA-miRNA interaction prediction method
CN121725889A