Intelligent contract-oriented graph attention network vulnerability detection method based on global feature augmentation

By introducing global feature augmentation and graph attention networks in smart contract vulnerability detection, the problem that existing detection methods do not consider account information and contract category characteristics is solved, achieving higher vulnerability detection accuracy and a deeper understanding of complex business logic.

CN119830301APending Publication Date: 2025-04-15XUZHOU NORMAL UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411914349.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-24
Publication Date
2025-04-15

AI Technical Summary

Technical Problem

The existing smart contract vulnerability detection methods do not consider the account information characteristics and contract category characteristics during contract execution, resulting in low accuracy of vulnerability detection.

Method used

A graph attention network vulnerability detection method for global features augmented smart contracts is proposed. By adding contract categories and account information features as global virtual nodes to the contract graph, and feature aggregation and classifier processing are carried out in the graph attention network model, the contract code execution flow, account information features and contract categories are fully integrated.

Benefits of technology

The accuracy of smart contract vulnerability detection is improved. By combining the graph attention network and global features, it can more comprehensively understand the contract execution behavior and business logic, thereby discovering potential hidden vulnerabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119830301A_ABST
    Figure CN119830301A_ABST
Patent Text Reader

Abstract

The invention discloses a graph attention network vulnerability detection method for global feature augmentation of a smart contract, and belongs to the field of block chains. The problem of low vulnerability detection accuracy due to the fact that account information features and contract category features are not considered when a contract is executed in an existing intelligent contract vulnerability detection method is solved. According to the method, in a contract graph creation stage, account information features and contract categories during contract execution are taken as global features to be expanded into contract graph features, and in a model learning stage, each node and edge feature is subjected to learning updating with the global features and adjacent nodes or edges; therefore, full fusion of the execution flow of the contract code, the account information feature during contract execution and the contract category is realized, and the effect of improving the vulnerability detection accuracy of the intelligent contract is achieved. The method can be applied to vulnerability detection of the smart contract.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of blockchain, and specifically relates to a graph attention network vulnerability detection method with global feature augmentation for smart contracts. Background Art

[0002] Blockchain is a distributed database shared between computer network nodes that stores electronic information in digital format. Unlike traditional databases, blockchain collects information in the form of groups (blocks) and connects the blocks in chronological order to ensure data reliability. Blockchain has attracted widespread attention in the industry in recent years. Due to the openness, decentralization and autonomy of blockchain systems, massive blockchain data provides huge business value and opportunities for enterprises. Taking commercial transaction data as an example, in the past, it was difficult for researchers to obtain real commercial transaction data due to privacy or ownership issues of data owners. However, all data in existing blockchain systems are publicly available. At the same time, due to the decentralization of blockchain systems, blockchain data in permissionless blockchains can be accessed almost everywhere. In addition, the distributed consensus of blockchain also guarantees the autonomy of blockchain data.

[0003] Ethereum supports Turing-complete smart contracts, which can be understood as automatically executed contracts that can write the terms of the agreement between the buyer and the seller directly into the code logic, and the code and the agreements contained in it exist in a distributed blockchain network. The code can contain agreements, that is, automatically execute pre-determined operations when certain conditions are met, including transfers, decision-making, and interaction with other contracts. At present, thousands of smart contracts have been deployed on the Ethereum platform, and the number of smart contracts deployed on Ethereum is still growing rapidly.

[0004] Since smart contracts are often associated with cryptocurrency transactions, contract vulnerabilities may lead to serious security issues and financial losses.

[0005] At present, the research on the detection of known vulnerabilities in smart contracts mainly focuses on analyzing the execution process of the contract itself. Specifically, researchers usually use a combination of static analysis and dynamic analysis to identify potential security vulnerabilities. Static analysis methods focus on detecting security defects in the code through syntax parsing, pattern matching, etc. without actually executing the code; while dynamic analysis is to observe the behavior of the contract through simulated transactions or actual deployment during the actual operation of the contract to discover possible problems.

[0006] Although the above methods have improved the security of smart contracts to a certain extent, there are still problems such as lack of comprehensiveness in vulnerability detection and insufficient utilization of contract category information. Specifically, existing detection methods often focus too much on the analysis of the contract code level, while neglecting the in-depth understanding of the contract execution behavior and the business logic behind it, which may lead to some hidden vulnerabilities not being discovered in time, especially in smart contracts involving complex business logic. In addition, different types of smart contracts (such as ERC-20 token contracts, decentralized exchange contracts, etc.) have different design purposes and security requirements. However, current research rarely considers incorporating contract category information into the vulnerability detection process, which affects the accuracy of the detection results. Therefore, how to fully utilize the execution flow of the contract code, the account information characteristics during contract execution, and the contract category characteristics in contract vulnerability detection has become a hot topic for researchers. Summary of the invention

[0007] The purpose of this invention is to solve the problem that the existing smart contract vulnerability detection method does not take into account the account information characteristics and contract category characteristics during contract execution, resulting in low accuracy of vulnerability detection, and proposes a graph attention network vulnerability detection method with global feature augmentation for smart contracts.

[0008] The technical solution adopted by the present invention to solve the above technical problems is: a graph attention network vulnerability detection method for global feature augmentation of smart contracts, the method specifically comprising the following steps:

[0009] Step 1: Use the variables and functions in the Ethereum Solidity smart contract code as nodes of the contract graph, and use the execution flow in the Ethereum Solidity smart contract code as the edge of the contract graph to obtain the constructed contract graph;

[0010] Step 2: Add the contract category and the account information features during contract execution as global virtual nodes to the contract graph, and connect the other nodes in the contract graph to the global virtual nodes to obtain an updated contract graph;

[0011] Step 3: shrink the contract graph to obtain a shrunken contract graph; then transform the node features and edge features in the shrunken contract graph to obtain transformed node features and edge features;

[0012] Step 4: Input the converted node features and edge features into the vulnerability detection model, which includes a graph attention module, a feature aggregation module, and a classifier;

[0013] The graph attention module is used to update the converted node features and edge features to obtain updated node features and edge features;

[0014] The feature aggregation module is used to aggregate the updated node features and edge features to obtain aggregated node features and edge features;

[0015] The classifier is used to process the aggregated node features and edge features to obtain the smart contract vulnerability detection results.

[0016] Furthermore, the nodes of the contract graph include a main node, an auxiliary node and a callback node;

[0017] The master node includes variables and functions related to the transfer operation, functions and variables related to the timestamp, functions and variables related to the loop, digital variables involved in the operation, and output parameters and input parameters of the functions involved in the operation;

[0018] The auxiliary node includes variables and functions other than the main node and the callback function;

[0019] The callback node includes a callback function.

[0020] Furthermore, the edges of the contract graph include control flow edges, data flow edges, forward edges and callback edges.

[0021] Furthermore, the contracting of the contract graph is specifically as follows:

[0022] For any auxiliary node in the contract graph, shrink the auxiliary node to the main node closest to the auxiliary node; for any callback node in the contract graph, shrink the callback node to the main node closest to the callback node;

[0023] The characteristics of the master node after shrinking are:

[0024] V i =v i +∑ i A i +∑ i F i

[0025] Among them, v i is the characteristic of the ith master node in the original contract graph, V i is the characteristic of the ith main node in the contracted contract graph, ∑ i A i represents the sum of the characteristics of all callback nodes contracted to the i-th main node, ∑ i F i Represents the characteristic sum of all auxiliary nodes shrunk to the i-th primary node.

[0026] Furthermore, the node features and edge features in the contracted contract graph are converted as follows:

[0027] Word2Vec encoding is used to convert node features, edge features in the contracted contract graph, and account information features in the global virtual node into vector features;

[0028] Convert the contract category features in the global virtual node into one-hot encoding.

[0029] Furthermore, the graph attention module includes a parallel K-head graph attention network.

[0030] Furthermore, in step 4, the method for updating the converted edge features is:

[0031] For the jth edge in the contract graph after contraction:

[0032] Step S1, calculate the intermediate variable e jn :

[0033] e jn =α(W k E j ,W k E n )

[0034] Among them, W k is the weight matrix of the k-th image attention network, α represents the weight vector, E j is the feature of the jth edge after transformation, E n is the feature of the nth edge after conversion, n = j-1 or j+1;

[0035] Then the attention score α jn for:

[0036] α jn =softmax(e jn )

[0037] Among them, softmax(·) is the activation function;

[0038] Step S2: Calculate the intermediate variable e jm and e j(m+1) :

[0039] e jm =α(WkE j ,WkρV m )

[0040] e j(m+1) =a(W k E j ,W k ρV m+1 )

[0041] Among them, V m and V m+1is the transformed feature of the two nodes connected by the jth edge, ρV m Indicates V m The mapped features, ρV m+1 Indicates V m+1 The mapped features of

[0042] Then the attention score α jm and α j(m+1) for:

[0043] α jm =softmax(e jm )

[0044] α j(m+1) =softmax(e j(m+1) )

[0045] Step S3: Calculate the intermediate variable e ju :

[0046] e ju =α(W k E j ,W k ρ'U)

[0047] Among them, ρ'U represents the mapped features of U;

[0048] Then the attention score α ju for:

[0049] α ju =softmax(e ju )

[0050] Step S4: Calculate the updated features of the j-th edge:

[0051]

[0052] Among them, K is the total number of attention heads, E' j represents the updated feature of the j-th edge, and σ(·) is a nonlinear activation function.

[0053] Furthermore, in step 4, the method for updating the converted node features is:

[0054] For the i-th node in the contracted contract graph:

[0055] Step C1: Calculate the intermediate variable e im :

[0056]

[0057] in, is the weight matrix of the k-th image attention network, represents the weight vector, V i is the feature of the i-th node after conversion, V m is the feature of the mth node adjacent to the i-th node;

[0058] Then the attention score α im for:

[0059] α im =softmax(e im )

[0060] Step C2: Calculate the intermediate variable e in :

[0061]

[0062] Among them, E n is the transformed feature of the nth edge connected to the i-th node, Indicates E n The mapped features of

[0063] Then the attention score α in for:

[0064] α in =softmax(e in )

[0065] Step C3: Calculate the intermediate variable e iu :

[0066]

[0067] in, Represents the mapped features of U;

[0068] Then the attention score α iu for:

[0069] α iu =softmax(e iu )

[0070] Step C4: Calculate the updated features of the i-th node:

[0071]

[0072] Among them, K is the total number of attention heads, M is the set of nodes adjacent to the i-th node, and N is the set of edges connected to the i-th node.

[0073] Furthermore, the feature aggregation module aggregates the updated node features and edge features to obtain aggregated node features and edge features; specifically:

[0074]

[0075] Where I is the set of main nodes in the contract graph, |I| is the number of nodes in set I, and V is the converged node feature;

[0076]

[0077] Among them, L is the edge set in the contract graph, |L| is the number of edges in the set L, and E is the converged edge feature.

[0078] Furthermore, the classifier is used to process the aggregated node features and edge features to obtain the smart contract vulnerability detection results, specifically:

[0079]

[0080] Among them, y is the smart contract vulnerability detection result.

[0081] The beneficial effects of the present invention are:

[0082] In the contract graph creation stage, the method of the present invention expands the account information features and contract categories during contract execution into the contract graph features as global features, and in the model learning stage, each node and edge feature is learned and updated with the global features and adjacent nodes or edges to achieve a full integration of the execution flow of the contract code, the account information features during contract execution, and the contract category, so as to achieve the effect of improving the accuracy of smart contract vulnerability detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0083] Figure 1 It is a flow chart of a graph attention network vulnerability detection method for global feature augmentation of smart contracts of the present invention. DETAILED DESCRIPTION

[0084] Specific implementation method 1: Combination Figure 1 The present embodiment describes a global feature augmented graph attention network vulnerability detection method for smart contracts, and the method specifically includes the following steps:

[0085] Step 1: Use the variables and functions in the Ethereum Solidity smart contract code as nodes of the contract graph, and use the execution flow in the Ethereum Solidity smart contract code as the edge of the contract graph to obtain the constructed contract graph;

[0086] Step 2: Add the contract category and the account information features during contract execution as global virtual nodes to the contract graph, and connect each other node in the contract graph to the global virtual node (i.e., an edge is generated between the global virtual node and each other node), to obtain an updated contract graph;

[0087] Step 3: shrink the contract graph to obtain a shrunken contract graph; then transform the node features and edge features in the shrunken contract graph to obtain transformed node features and edge features;

[0088] Step 4: Input the converted node features and edge features into the vulnerability detection model, which includes a graph attention module, a feature aggregation module, and a classifier;

[0089] The graph attention module is used to update the converted node features and edge features to obtain updated node features and edge features;

[0090] The feature aggregation module is used to aggregate the updated node features and edge features to obtain aggregated node features and edge features;

[0091] The classifier is used to process the aggregated node features and edge features to obtain the smart contract vulnerability detection results.

[0092] The vulnerability detection model of the present invention is a vulnerability detection model trained based on training set data. The graph attention module includes two sets of trained parameters, one set of parameters is used to update node features during detection, and the other set of parameters is used to update edge features during detection.

[0093] Specific implementation method 2: This implementation method is different from the specific implementation method 1 in that the nodes of the contract graph include a main node, an auxiliary node and a callback node;

[0094] The master node includes variables and functions related to the transfer operation, functions and variables related to the timestamp, functions and variables related to the loop, digital variables involved in the operation, and output parameters and input parameters of the functions involved in the operation;

[0095] The auxiliary node includes variables and functions other than the main node and the callback function;

[0096] The callback node includes a callback function.

[0097] The other steps and parameters are the same as those in the first embodiment.

[0098] A node can be abstracted as a four-tuple V i=(Identifier,Access,Call,Type). Among them, Identifier represents its identifier; Access represents the caller's access rights. Access=Limited means that the caller has limited access, while Access=NoLimited means that the caller has unlimited access; Call represents the caller address of the call; Type represents the node type. According to the different importance of nodes in program execution, these nodes are divided into three types: main nodes, auxiliary nodes, and callback nodes. The main node is the function and variable that has an important impact on the detection of smart contract vulnerabilities. The main node includes several main categories: variables and functions related to transfer operations, functions and variables directly related to timestamps, functions and variables related to loops, and the output and input parameters of digital variables and functions involved in operations. The built-in functions send(), transfer(), and call.value() related to transfer operations, as well as variables related to account and contract balance, are key nodes for detecting reentrancy vulnerabilities. Functions and variables directly related to timestamps include: calling with the timestamp built-in function block.timestamp, variables assigned by block.timestamp, and random functions using block.timestamp as a seed. These are key nodes for detecting timestamp-dependent vulnerabilities. All for and while statements, loop condition variables, and recursive call statements. These are key nodes for detecting infinite loop vulnerabilities. Variables that store numbers and variables assigned by arithmetic operations are key nodes for detecting integer overflow vulnerabilities. Auxiliary nodes include functions and variables that are not taken into account when the main nodes are extracted. They play an auxiliary role in smart contract vulnerability detection, such as variables related to rewards and variables indirectly related to timestamps. Callback nodes refer to callback functions in attack contracts. These callback functions are one of the potential sources of contract vulnerabilities because they have the ability to simulate callback functions in attack contracts and can interact with functions in attacked contracts.

[0099] Specific implementation method three: This implementation method is different from specific implementation methods one or two in that the edges of the contract graph include control flow edges, data flow edges, forward edges and callback edges.

[0100] The other steps and parameters are the same as those in the first or second embodiment.

[0101] Each edge can be abstracted as a four-tuple E = (V i ,V j ,time,type), where V i and V jIndicates the start and end nodes of an edge; time indicates its time sequence (edges are numbered in sequence according to the order of contract execution); type indicates the type of edge. These edges are divided into four types as shown in Table 1 based on semantic dependencies. Among them, control flow edges are used to represent the order or jump statements in the contract execution path; data flow edges represent the usage of variables; forward edges are used to describe the natural control flow during code execution; callback edges are used to model the fallback mechanism.

[0102] Table 1 Four edge types

[0103]

[0104]

[0105] Specific implementation method 4: This implementation method is different from the specific implementation methods 1 to 3 in that the contract diagram is shrunk as follows:

[0106] For any auxiliary node in the contract graph, shrink the auxiliary node to the main node closest to the auxiliary node; for any callback node in the contract graph, shrink the callback node to the main node closest to the callback node;

[0107] The characteristics of the master node after shrinking are:

[0108] V i =v i +∑ i A i +∑ i F i

[0109] Among them, v i is the characteristic of the ith master node in the original contract graph, V i is the characteristic of the ith main node in the contracted contract graph, ∑ i A i represents the sum of the characteristics of all callback nodes contracted to the i-th main node, ∑ i F i Represents the characteristic sum of all auxiliary nodes shrunk to the i-th primary node.

[0110] The other steps and parameters are the same as those in Specific Embodiments 1 to 3.

[0111] The specific method of contract graph shrinkage is to traverse the contract graph in breadth, merge each auxiliary node and callback node into their respective main nodes that have been traversed most recently, and the final contract graph only retains those main nodes that are critical to vulnerability detection.

[0112] Specific implementation method five: This implementation method is different from the specific implementation methods one to four in that the node features and edge features in the contracted contract graph are converted as follows:

[0113] Word2Vec encoding is used to convert node features, edge features in the contracted contract graph, and account information features in the global virtual node into vector features;

[0114] Convert the contract category features in the global virtual node into one-hot encoding.

[0115] The other steps and parameters are the same as those in Specific Embodiments 1 to 4.

[0116] The contract categories and their corresponding one-hot codes are shown in Table 2:

[0117] Table 2

[0118] Contract Type One-hot encoding Games and Entertainment (1,0,0,0,0) Social Management (0,1,0,0,0) Lotto (0,0,1,0,0) Finance and Insurance (0,0,0,1,0) Trading Investment (0,0,0,0,1)

[0119] Specific implementation method six: This implementation method is different from any one of specific implementation methods one to five in that the graph attention module includes a parallel K-head graph attention network.

[0120] The other steps and parameters are the same as those in Specific Implementation Methods 1 to 5.

[0121] Specific implementation method 7: This implementation method is different from any one of specific implementation methods 1 to 6 in that, in step 4, the method for updating the converted edge features is:

[0122] For the jth edge in the contract graph after contraction:

[0123] Step S1, calculate the intermediate variable e jn :

[0124] e jn =α(W k E j ,W k E n )=LeakyReLU(α T [W k E j ||W k E n ])

[0125] Among them, W k is the weight matrix of the k-th image attention network, α represents the weight vector, E j is the feature of the jth edge after transformation, E n is the feature of the nth edge after conversion, n = j-1 or j+1;

[0126] Then the attention score α jn for:

[0127] α jn =softmaqx(e jn )

[0128] Among them, softmax(·) is the activation function;

[0129] Step S2: Calculate the intermediate variable e jm and e j(m+1) :

[0130] e jm =α(W k E j ,W k ρV m )=LeakyReLU(α T [W k E j ||W k ρV m ])

[0131] e j(m+1) =α(W k E j ,W k ρV m+1 )=LeakyReLU(α T [W k E j ||W k ρV m+1 ])

[0132] Among them, V m and V m+1 is the transformed feature of the two nodes connected by the jth edge, ρV m Indicates V m The mapped features, ρV m+1 Indicates V m+1 The mapped features of

[0133] Then the attention score α jm and α j(m+1) for:

[0134] α jm =softmax(e jm )

[0135] α j(m+1) =softmax(e j(m+1) )

[0136] Step S3: Calculate the intermediate variable e ju :

[0137] eju =α(W k E j ,W k ρ'U)=LeakyReLU(α T (W k E j ||W k ρ'U])

[0138] Among them, ρ'U represents the mapped features of U;

[0139] Then the attention score α ju for:

[0140] α ju =softmaqx(e ju )

[0141] Step S4: Calculate the updated features of the j-th edge:

[0142]

[0143] Among them, K is the total number of attention heads, E' j represents the updated feature of the j-th edge, and σ(·) is a nonlinear activation function.

[0144] The other steps and parameters are the same as those in Specific Embodiments 1 to 6.

[0145] When updating the feature vector of the edge in the graph, we first learn the relationship between the jth edge and the previous time sequence edge (E j-1 ) and the next timing edge (E j+1 ) jn Secondly, learn the two nodes (V m and V m+1 ) jm , ρ is used to map the node vector to the edge vector (by the activation of linear transformation, and other ρ-related mapping methods are similar), and then learn the weight α of the jth edge and the global feature (U) ju ρ' has the same function as ρ, which is to map the global feature vector to the edge vector. In this process, the parameters that the neural network needs to learn include the shared weight feature α and the dimension-increasing parameter matrix W. The shared weight feature maps the concatenated high-dimensional features to real numbers, while the dimension-increasing parameter matrix can automatically extract useful information from the original features.

[0146] Specific implementation eight: This implementation differs from any one of specific implementations one to seven in that, in step 4, the method for updating the converted node features is:

[0147] For the i-th node in the contracted contract graph:

[0148] Step C1: Calculate the intermediate variable e im :

[0149]

[0150] in, is the weight matrix of the k-th image attention network, represents the weight vector, V i is the feature of the i-th node after conversion, V m is the feature of the mth node adjacent to the ith node (the adjacent node is the node directly connected to the ith node);

[0151] Then the attention score α im for:

[0152] α im =softmax(e im )

[0153] Step C2: Calculate the intermediate variable e in :

[0154]

[0155] Among them, E n is the transformed feature of the nth edge connected to the i-th node, Indicates E n The mapped features of

[0156] Then the attention score α in for:

[0157] α in =softmax(e in )

[0158] Step C3: Calculate the intermediate variable e iu :

[0159]

[0160] in, Represents the mapped features of U;

[0161] Then the attention score α iu for:

[0162] α iu =softmax(e iu )

[0163] Step C4: Calculate the updated features of the i-th node:

[0164]

[0165] Among them, K is the total number of attention heads, M is the set of nodes adjacent to the i-th node, and N is the set of edges connected to the i-th node.

[0166] The other steps and parameters are the same as those in Specific Embodiments 1 to 7.

[0167] The present invention only updates the main node features, specifically based on the combination of different weights learned previously. When updating the feature vector of a node in the graph, similar to the convergence learning operation of the edge, first learn the node (V i ) and all adjacent nodes (V m ), and V i Directly connected edges (E n ) and the weight of the global feature, and finally update the node. In this process, the parameters that the neural network needs to learn include shared weight features And the dimension-increasing parameter matrix The shared weight features map the concatenated high-dimensional features to real numbers, while the dimension-increased parameter matrix can automatically extract useful information from the original features.

[0168] The update method of node features and edge features is shown in Algorithm 1 of Table 3:

[0169] Table 3

[0170]

[0171] h i and h j is the feature vector of node i and node j, which is connected to h through a shared weight matrix W i and h j After linear transformation, we get the new eigenvector Wh i and Wh j , and concatenate the two together, and then calculate the inner product with the vector α to get a constant e ij :

[0172] e ij =α(Wh i ,Wh j )

[0173] Finally, the activation function is used to normalize the mapping to the attention coefficient α ij :

[0174]

[0175] The activation function uses LeakyReLU, || represents the concatenation operation, and the calculation of α is expanded ij The formula is as follows:

[0176]

[0177] In order to ensure the stability of the model during feature learning, the following multi-head attention mechanism is adopted:

[0178]

[0179] The readout phase aggregates the representations of all nodes:

[0180]

[0181] U=U

[0182] Then we get the vulnerability detection results of the smart contract:

[0183]

[0184] Specific implementation method 9: This implementation method is different from any one of specific implementation methods 1 to 8 in that the feature aggregation module aggregates the updated node features and edge features to obtain aggregated node features and edge features; specifically:

[0185]

[0186] Where I is the set of main nodes in the contract graph, |I| is the number of nodes in set I, and V is the converged node feature;

[0187]

[0188] Among them, L is the edge set in the contract graph, |L| is the number of edges in the set L, and E is the converged edge feature.

[0189] The other steps and parameters are the same as those in Specific Embodiments 1 to 8.

[0190] Specific implementation method ten: This implementation method is different from the specific implementation methods one to nine in that the classifier is used to process the aggregated node features and edge features to obtain the smart contract vulnerability detection results, specifically:

[0191]

[0192] Among them, y is the smart contract vulnerability detection result (that is, the detection result of whether the smart contract has vulnerabilities).

[0193] The other steps and parameters are the same as those in Specific Embodiments 1 to 9.

[0194] The above calculation examples of the present invention are only used to explain the calculation model and calculation process of the present invention in detail, and are not intended to limit the implementation methods of the present invention. For ordinary technicians in the relevant field, other different forms of changes or modifications can be made based on the above description. It is impossible to list all the implementation methods here. All obvious changes or modifications derived from the technical solution of the present invention are still within the scope of protection of the present invention.

Claims

1. A global feature augmentation graph attention network vulnerability detection method for smart contracts, characterized by: The method specifically comprises the following steps: Step 1: Use the variables and functions in the Ethereum Solidity smart contract code as nodes of the contract graph, and use the execution flow in the Ethereum Solidity smart contract code as the edge of the contract graph to obtain the constructed contract graph; Step 2: Add the contract category and the account information features during contract execution as global virtual nodes to the contract graph, and connect the other nodes in the contract graph to the global virtual nodes to obtain an updated contract graph; Step 3: shrink the contract graph to obtain a shrunken contract graph; then transform the node features and edge features in the shrunken contract graph to obtain transformed node features and edge features; Step 4: Input the converted node features and edge features into the vulnerability detection model, which includes a graph attention module, a feature aggregation module, and a classifier; The graph attention module is used to update the converted node features and edge features to obtain updated node features and edge features; The feature aggregation module is used to aggregate the updated node features and edge features to obtain aggregated node features and edge features; The classifier is used to process the aggregated node features and edge features to obtain the smart contract vulnerability detection results.

2. According to claim 1, a global feature augmented graph attention network vulnerability detection method for smart contracts is characterized in that: The nodes of the contract graph include main nodes, auxiliary nodes and callback nodes; The master node includes variables and functions related to the transfer operation, functions and variables related to the timestamp, functions and variables related to the loop, digital variables involved in the operation, and output parameters and input parameters of the functions involved in the operation; The auxiliary node includes variables and functions other than the main node and the callback function; The callback node includes a callback function.

3. According to claim 2, a global feature augmented graph attention network vulnerability detection method for smart contracts is characterized in that: The edges of the contract graph include control flow edges, data flow edges, forward edges and callback edges.

4. According to claim 3, a global feature augmented graph attention network vulnerability detection method for smart contracts is characterized in that: The contract graph is contracted as follows: For any auxiliary node in the contract graph, shrink the auxiliary node to the main node closest to the auxiliary node; for any callback node in the contract graph, shrink the callback node to the main node closest to the callback node; The characteristics of the master node after shrinking are: V i =v i +∑ i A i +∑ i F i Among them, v i is the characteristic of the ith master node in the original contract graph, V i is the characteristic of the ith main node in the contracted contract graph, ∑ i A i represents the sum of the characteristics of all callback nodes contracted to the i-th main node, ∑ i F i Represents the characteristic sum of all auxiliary nodes shrunk to the i-th primary node.

5. According to claim 3, a global feature augmented graph attention network vulnerability detection method for smart contracts is characterized in that: The node features and edge features in the contracted contract graph are converted as follows: Word2Vec encoding is used to convert node features, edge features in the contracted contract graph, and account information features in the global virtual node into vector features; Convert the contract category features in the global virtual node into one-hot encoding.

6. According to claim 5, a global feature augmented graph attention network vulnerability detection method for smart contracts is characterized in that: The graph attention module includes a parallel K-head graph attention network.

7. According to claim 6, a global feature augmented graph attention network vulnerability detection method for smart contracts is characterized in that: In step 4, the method for updating the converted edge features is: For the jth edge in the contract graph after contraction: Step S1, calculate the intermediate variable e jn : and jn =α(WkE j ,IN k E n ) Among them, W k is the weight matrix of the k-th image attention network, α represents the weight vector, E j is the feature of the jth edge after transformation, E n is the feature of the nth edge after conversion, n = j-1 or j+1; Then the attention score α jn for: a jn =softmax(e jn ) Among them, softmax(·) is the activation function; Step S2: Calculate the intermediate variable e jm and e j(m+1) : e jm =α(W k E j ,W k pV m ) e j(m+1) =α(W k E j ,W k pV m+1 ) Among them, V m and V m+1 is the transformed feature of the two nodes connected by the jth edge, ρV m Indicates V m The mapped features, ρV m+1 Indicates V m+1 The mapped features of Then the attention score α jm and α j(m+1) for: a jm =softmax(e jm ) a j(m+1) =softmax(e j(m+1) ) Step S3: Calculate the intermediate variable e ju : e ju =α(W k E j ,W k (r'U) Among them, ρ'U represents the mapped features of U; Then the attention score α ju for: a ju =softmax(e ju ) Step S4: Calculate the updated features of the j-th edge: Among them, K is the total number of attention heads, E' j represents the updated feature of the j-th edge, and σ(·) is a nonlinear activation function.

8. According to claim 7, a global feature augmented graph attention network vulnerability detection method for smart contracts is characterized in that: In step 4, the method for updating the converted node features is: For the i-th node in the contracted contract graph: Step C1: Calculate the intermediate variable e im : in, is the weight matrix of the k-th image attention network, represents the weight vector, V i is the feature of the i-th node after conversion, V m is the feature of the mth node adjacent to the i-th node; Then the attention score α im for: a im =softmax(e im ) Step C2: Calculate the intermediate variable e in : Among them, E n is the transformed feature of the nth edge connected to the i-th node, Indicates E n The mapped features of Then the attention score α in for: a in =softmax(e in ) Step C3: Calculate the intermediate variable e iu : in, Represents the mapped features of U; Then the attention score α iu for: a iu =softmax(e iu ) Step C4: Calculate the updated features of the i-th node: Among them, K is the total number of attention heads, M is the set of nodes adjacent to the i-th node, and N is the set of edges connected to the i-th node.

9. According to claim 8, a global feature augmented graph attention network vulnerability detection method for smart contracts is characterized in that: The feature aggregation module aggregates the updated node features and edge features to obtain aggregated node features and edge features; specifically: Where I is the set of main nodes in the contract graph, |I| is the number of nodes in set I, and V is the converged node feature; Among them, L is the edge set in the contract graph, |L| is the number of edges in the set L, and E is the converged edge feature.

10. The method of detecting vulnerabilities in graph attention networks with global feature augmentation for smart contracts according to claim 9 is characterized in that: The classifier is used to process the aggregated node features and edge features to obtain the smart contract vulnerability detection results, specifically: Among them, y is the smart contract vulnerability detection result.