Intelligent contract reentry vulnerability detection method driven by optimal security practice

By adopting a security best practice-driven method in smart contract reentry vulnerability detection, using graph attention network and multi-layer perception machines to build global and local contract graphs, the problems of high false positive rate and insufficient model flexibility in the existing technology are solved, and higher detection accuracy and recall rate are achieved.

CN119808084APending Publication Date: 2025-04-11JIANGSU UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411749285.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-02
Publication Date
2025-04-11

AI Technical Summary

Technical Problem

The existing smart contract reentry vulnerability detection methods have false positive problems when identifying security modules in the code, and the model is insufficient to effectively detect potential hazard sources.

Method used

A smart contract reentry vulnerability detection method driven by security best practices is adopted to construct a global contract graph and a local contract graph through function-level slices and graph attention networks, and feature extraction and classification detection are performed in combination with a dual attention mechanism and a multi-layer perception machine.

Benefits of technology

It effectively reduces the false positives caused by the model due to the inability to identify the security modules in the code, and improves the flexibility of the model, significantly improving the accuracy and recall rate of smart contract reentry vulnerability detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119808084A_ABST
    Figure CN119808084A_ABST
Patent Text Reader

Abstract

The invention discloses an intelligent contract re-entry vulnerability detection method driven by safety optimal practice, which is characterized by comprising the following steps of: 1, transmitting an intelligent contract source code, and performing function-level slicing on the intelligent contract source code to obtain a contract function set; 2, independently analyzing a logic unit of each function in the function set by using a function slice detection algorithm, and dividing the functions into a safety function and a suspicious function; step 3, taking a suspicious function set as a core based on the obtained security function and suspicious function; step 4, performing function screening on the suspicious function set by using an enhanced filtering algorithm; 5, performing feature extraction on the global contract graph and the local contract graph by using a graph attention network combined with a double attention mechanism; and step 6, carrying out combined feature fusion on the obtained global graph features and local graph features. According to the method, false alarms caused by the fact that the model cannot identify the security module in the code can be effectively reduced, and the flexibility of the model can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of blockchain behavior detection, and in particular to a smart contract reentry vulnerability detection method driven by security best practices. Background Art

[0002] Security Best Practices (SBP) is a widely adopted strategy in smart contract development that aims to prevent common vulnerabilities. With the widespread application of smart contracts in finance, supply chain and other fields, their security has become critical. SBP includes code auditing, using audited libraries, conducting comprehensive unit testing and adopting multi-signature mechanisms to prevent common security vulnerabilities such as reentrancy attacks and integer overflows. By following these best practices, developers can significantly reduce the risk of contract attacks and enhance users' trust in blockchain technology.

[0003] There are five main SBPs for reentrancy vulnerabilities:

[0004] 1. Checks, Effects, Interactions (CEI) pattern: CEI is a design pattern that ensures that state variables are updated first, avoiding unsafe states caused by reentrancy during external calls.

[0005] 2. ReentrancyGuard / Mutex: Ensure that the function cannot be reentrantly called during execution by adding a mutex lock. A widely used way to implement the lock is to inherit OpenZeppelin's ReentrancyGuard and use the nonReentrant modifier.

[0006] 3. PullPayment mode: By allowing users to actively withdraw payments instead of the contract automatically sending them, external calls are fundamentally avoided.

[0007] 4.GasLimit: Limit the gas used during external calls to prevent attackers from exhausting gas through complex operations and affecting the normal logic of the contract.

[0008] 5. Prevent control flow hijacking: Use a whitelist strategy to limit the addresses that are allowed to call contracts and prevent malicious contract injection.

[0009] Graph Neural Network (GNN) is a deep neural network designed for processing graph data of arbitrary structure. This network can effectively capture the complex relationship between nodes in the graph and is widely used in social network analysis, recommendation systems, bioinformatics and other fields. The core idea of ​​GNN is to aggregate the neighborhood information of nodes in an iterative way to generate high-order feature representations of each node.

[0010] GNNs usually work in a stacked manner, with each layer updating node features and using the information of neighboring nodes to enhance the representation of the current node. Different GNN architectures can be divided into two types: isotropic and anisotropic, based on the way features are aggregated. In the isotropic model, all neighbor nodes contribute equally to the central node. This method is simple and effective. For example, the graph convolutional network (GCN) is a representative of this category. The anisotropic model considers the different importance of neighbor nodes and assigns different weights to neighbor nodes through a self-attention mechanism (such as the graph attention network GAT), thereby more flexibly capturing the complex relationships in the graph. Summary of the invention

[0011] The purpose of this section is to summarize some aspects of embodiments of the present invention and briefly introduce some preferred embodiments. Some simplifications or omissions may be made in this section and the specification abstract and the invention title of this application to avoid blurring the purpose of this section, the specification abstract and the invention title, and such simplifications or omissions cannot be used to limit the scope of the present invention.

[0012] In view of the above-mentioned problems existing in the existing smart contract reentry vulnerability detection method driven by security best practices, the present invention is proposed.

[0013] Therefore, the purpose of the present invention is to provide a smart contract reentrancy vulnerability detection method driven by security best practices, which adopts a new idea, by using the security best practices of reentrancy vulnerabilities, reversely excluding the security code blocks in the contract source code to identify potential sources of danger. This method can not only effectively reduce the false positives caused by the model's inability to identify security modules in the code, but also increase the flexibility of the model.

[0014] To solve the above technical problems, the present invention provides the following technical solutions: a smart contract reentry vulnerability detection method driven by security best practices, comprising the following steps:

[0015] Step 1: Pass in the smart contract source code and slice it at the function level to obtain the contract function set;

[0016] Step 2: Use the function slicing detection algorithm to independently analyze the logic unit of each function in the function set and divide the functions into safe functions and suspicious functions;

[0017] Step 3: Based on the obtained safe functions and suspicious functions, a global contract graph is constructed with the suspicious function set as the core and combined with the safe function set;

[0018] Step 4: Use an enhanced filtering algorithm to screen the suspicious function set, and use the screened core function set to construct a local contract graph;

[0019] Step 5: Use a graph attention network combined with a dual attention mechanism to extract features from the global contract graph and the local contract graph;

[0020] Step 6: Combine the obtained global graph features and local graph features for feature fusion, use a multi-layer perceptron (MLP) as a classifier, take the fused features as input, and output the prediction results.

[0021] As a preferred solution of the smart contract reentrancy vulnerability detection method driven by security best practices described in the present invention, the specific steps of the function slice detection algorithm in step 2 are:

[0022] Step 2.1: Initialize two sets, one for storing "safe functions" and the other for storing "suspicious functions";

[0023] Step 2.2: Create a rule map to map the predefined security best practice rule set into a query-friendly format;

[0024] Step 2.3: Traverse each function of the smart contract and perform code slicing to extract independent code snippets of the function;

[0025] Step 2.4: For each sliced ​​function, initialize a security flag to record whether the function meets the security standard;

[0026] Step 2.5: In each function’s code snippet, check the statements one by one and detect them according to the rule mapping;

[0027] Step 2.6: If a statement meets any of the safety rules in the rule mapping, the function is marked as safe and added to the "safe functions" set, and further detection is stopped;

[0028] Step 2.7: If all statements of the function do not comply with the security rules, add it to the "suspicious function" set;

[0029] Step 2.8: Repeat the above steps until all functions are traversed;

[0030] Step 2.9: Finally, output the list of “safe functions” and “suspicious functions”.

[0031] As a preferred solution of the smart contract reentry vulnerability detection method driven by security best practices described in the present invention, the specific steps of constructing the global contract graph in step 3 are as follows:

[0032] Step 3.1, node construction:

[0033] In the construction of the global contract graph, nodes are divided into core nodes, ordinary nodes and fallback nodes; core nodes are composed of suspicious functions and their key variables. Suspicious functions are identified through function slicing detection in the previous step; safe functions are marked as ordinary nodes to assist in expressing the global structure of smart contracts; fallback functions are used as fallback nodes to simulate attack paths;

[0034] Step 3.2: Edge construction:

[0035] After the node is built, the dependency between functions and variables is further captured by constructing control flow edges, data flow edges, fallback edges and timing edges. Each type of edge connects core nodes and ordinary nodes according to different semantic dependencies to ensure that the contract reflects the correct call path and data interaction during execution. The control flow edge is used to capture the execution order of the code within the function and reflect the natural flow of the code logic. The data flow edge captures the use and modification of variables. The fallback edge is used to model possible fallback attack paths. In addition to the control flow edge and data flow edge, the timing edge is used to capture the execution order between all function nodes.

[0036] As a preferred solution of the smart contract reentry vulnerability detection method driven by security best practices described in the present invention, the specific steps of the enhanced filtering algorithm in step 4 are as follows:

[0037] Step 4.1: Initialize two sets, one for storing functions with reentrancy risk (F_local) and the other for storing function call relations (G_local);

[0038] Step 4.2: Traverse the set of suspicious functions after preliminary filtering, and perform the following operations on each function: According to the external contract interaction rules, determine whether the function interacts with the external contract; if so, add the function to the set of functions with reentrancy risk F_local, and record the calling relationship between the function and the external contract in G_local;

[0039] Step 4.3: Traverse the entire contract call graph and perform the following operations on the call relationship of each suspicious function: If the target function called by the suspicious function is a transfer function, add the suspicious function to the function set F_local with reentrancy risk, and record the call relationship between the function and the transfer function in G_local;

[0040] Step 4.4: Repeat the above steps until all suspicious functions are processed;

[0041] Step 4.5: Output the set of functions containing reentrancy risks and the corresponding function call relationship graph.

[0042] As a preferred solution of the smart contract reentry vulnerability detection method driven by security best practices described in the present invention, the specific method of extracting the features of the global contract graph and the local contract graph in step 5 is as follows:

[0043] Step 5.1: Linear transformation of node features:

[0044] We first start by linearly transforming the features of each node, using a learnable weight matrix W to transform the features h of each node i i Make changes:

[0045] h′ i =Wh i

[0046] Among them, h i is the original feature of node i, such as the code feature of a function or the attribute information of a variable. The purpose of this linear transformation is to project the node feature into a new feature space so that it is comparable with other node features.

[0047] Step 5.2, node level attention:

[0048] The node-level attention in the contract graph is used to capture the influence of the internal call chain of the function. For node i and its neighbor node j, the node-level attention weight is calculated as follows:

[0049]

[0050] Among them, W n is the linear transformation matrix, a n is the learnable weight vector of node-level attention. || represents the vector connection operation, N(i) represents the neighbor set of node i; the purpose of introducing the LeakyReLU activation function is to capture more nonlinear relationships so that the model can better cope with different types of node features; node-level attention is used to measure the influence of different neighbor nodes on the current node;

[0051] Step 5.3, edge-level attention:

[0052] In the contract graph, the types of edges are diverse and important. Edge-level attention is introduced to distinguish the influence of different edges. ij The edge-level attention weight of the connected nodes i and j is:

[0053]

[0054] Among them, e ij represents the edge type feature vector (such as control flow, data flow, backoff edge), W e and a eis the linear transformation matrix and weight vector of edge-level attention; through this mechanism, the model can distinguish the impact of different types of edges on node feature aggregation, and ε(i) is the set of edges connected to node i;

[0055] Step 5.4, feature aggregation:

[0056] After calculating the attention weights at the node level and edge level, the updated feature representation of node i is obtained by weighted aggregation of the information of neighboring nodes:

[0057]

[0058] Among them, σ is a nonlinear activation function. Then, all nodes in the global graph and the local graph are aggregated to obtain the feature representation H of the global graph. global and the feature representation H of the local graph local :

[0059] H global =Aggregate({h′ i |i∈V global})

[0060] H local =Aggregate({h′ i |i∈V local})

[0061] Among them, V global and V local Represents the node sets in the global graph and the local graph respectively; Aggregate() represents the aggregation operation.

[0062] As a preferred solution of the smart contract reentry vulnerability detection method driven by security best practices described in the present invention, wherein: in step 6:

[0063] Using the splicing method, the global feature H global and local features H local Combine to form a fusion feature representation H fused , whose expression is:

[0064] H fused =Concat(H global ,H local )

[0065] After feature fusion, the model enters the classification detection stage, using a multi-layer perceptron (MLP) as a classifier. Its structure includes several fully connected layers and nonlinear activation functions to enhance the model's expressive power. Specifically, the output y of the classification process is expressed by the following formula:

[0066] y=σ(Wclass ·H fused +b class )

[0067] Among them, W class is the weight matrix of the classifier, b class is the bias term, σ is the activation function used to convert the output into a probability distribution. Through back propagation in the training phase, the model will continuously adjust the parameters to minimize the difference between the predicted value and the true label, thereby improving the classification performance.

[0068] The beneficial effects of the present invention are: BRIEF DESCRIPTION OF THE DRAWINGS

[0069] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative labor. Among them:

[0070] Figure 1 This is a schematic diagram of the overall structure of the smart contract reentry vulnerability detection method driven by security best practices in the present invention. DETAILED DESCRIPTION

[0071] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are described in detail below in conjunction with the accompanying drawings.

[0072] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein, and those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.

[0073] Secondly, the term "one embodiment" or "embodiment" as used herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The term "in one embodiment" that appears in different places in this specification does not necessarily refer to the same embodiment, nor does it refer to a separate or selective embodiment that is mutually exclusive with other embodiments.

[0074] Secondly, the present invention is described in detail with reference to the schematic diagram. When describing the embodiments of the present invention in detail, for the sake of convenience, the cross-sectional diagrams showing the device structure will not be partially enlarged according to the general scale, and the schematic diagrams are only examples, which should not limit the scope of protection of the present invention. In addition, in actual production, the three-dimensional dimensions of length, width and depth should be included.

[0075] Reference Figure 1, provides a smart contract reentrancy vulnerability detection method driven by security best practices, including the following steps:

[0076] Step 1: Pass in the smart contract source code and slice it at the function level to obtain the contract function set;

[0077] Step 2: Use the function slicing detection algorithm to independently analyze the logic unit of each function in the function set and divide the functions into safe functions and suspicious functions;

[0078] Step 3: Based on the obtained safe functions and suspicious functions, a global contract graph is constructed with the suspicious function set as the core and combined with the safe function set;

[0079] Step 4: Use an enhanced filtering algorithm to screen the suspicious function set, and use the screened core function set to construct a local contract graph;

[0080] Step 5: Use a graph attention network combined with a dual attention mechanism to extract features from the global contract graph and the local contract graph;

[0081] Step 6: Combine the obtained global graph features and local graph features for feature fusion, use a multi-layer perceptron (MLP) as a classifier, take the fused features as input, and output the prediction results.

[0082] The specific steps of the function slice detection algorithm in step 2 are as follows:

[0083] Step 2.1: Initialize two sets, one for storing "safe functions" and the other for storing "suspicious functions";

[0084] Step 2.2: Create a rule map to map the predefined security best practice rule set into a query-friendly format;

[0085] Step 2.3: Traverse each function of the smart contract and perform code slicing to extract independent code snippets of the function;

[0086] Step 2.4: For each sliced ​​function, initialize a security flag to record whether the function meets the security standard;

[0087] Step 2.5: In each function’s code snippet, check the statements one by one and detect them according to the rule mapping;

[0088] Step 2.6: If a statement meets any of the safety rules in the rule mapping, the function is marked as safe and added to the "safe functions" set, and further detection is stopped;

[0089] Step 2.7: If all statements of the function do not comply with the security rules, add it to the "suspicious function" set;

[0090] Step 2.8: Repeat the above steps until all functions are traversed;

[0091] Step 2.9: Finally, output the list of “safe functions” and “suspicious functions”.

[0092] Furthermore, the specific steps of constructing the global contract graph in step 3 are as follows:

[0093] Step 3.1, node construction:

[0094] In the construction of the global contract graph, nodes are divided into core nodes, ordinary nodes and fallback nodes; core nodes are composed of suspicious functions and their key variables. Suspicious functions are identified through function slicing detection in the previous step; safe functions are marked as ordinary nodes to assist in expressing the global structure of smart contracts; fallback functions are used as fallback nodes to simulate attack paths;

[0095] Step 3.2: Edge construction:

[0096] After the node is built, the dependency between functions and variables is further captured by constructing control flow edges, data flow edges, fallback edges and timing edges. Each type of edge connects core nodes and ordinary nodes according to different semantic dependencies to ensure that the contract reflects the correct call path and data interaction during execution. The control flow edge is used to capture the execution order of the code within the function and reflect the natural flow of the code logic. The data flow edge captures the use and modification of variables. The fallback edge is used to model possible fallback attack paths. In addition to the control flow edge and data flow edge, the timing edge is used to capture the execution order between all function nodes.

[0097] For a clearer expression, as shown in Table 1, we list the composition process of an example contract.

[0098] Table 1 Summary of edge types

[0099]

[0100]

[0101] The specific steps of the enhanced filtering algorithm in step 4 are as follows:

[0102] Step 4.1: Initialize two sets, one for storing functions with reentrancy risk (F_local) and the other for storing function call relations (G_local);

[0103] Step 4.2: Traverse the set of suspicious functions after preliminary filtering, and perform the following operations on each function: According to the external contract interaction rules, determine whether the function interacts with the external contract; if so, add the function to the set of functions with reentrancy risk F_local, and record the calling relationship between the function and the external contract in G_local;

[0104] Step 4.3: Traverse the entire contract call graph and perform the following operations on the call relationship of each suspicious function: If the target function called by the suspicious function is a transfer function, add the suspicious function to the function set F_local with reentrancy risk, and record the call relationship between the function and the transfer function in G_local;

[0105] Step 4.4: Repeat the above steps until all suspicious functions are processed;

[0106] Step 4.5: Output the set of functions containing reentrancy risks and the corresponding function call relationship graph.

[0107] Furthermore, the specific method for extracting the features of the global contract graph and the local contract graph in step 5 is as follows:

[0108] Step 5.1: Linear transformation of node features:

[0109] We first start by linearly transforming the features of each node, using a learnable weight matrix W to transform the features h of each node i i Make changes:

[0110] h′ i =Wh i

[0111] Among them, h i is the original feature of node i, such as the code feature of a function or the attribute information of a variable. The purpose of this linear transformation is to project the node feature into a new feature space so that it is comparable with other node features.

[0112] Step 5.2, node level attention:

[0113] The node-level attention in the contract graph is used to capture the influence of the internal call chain of the function. For node i and its neighbor node j, the node-level attention weight is calculated as follows:

[0114]

[0115] Among them, W n is the linear transformation matrix, a nis the learnable weight vector of node-level attention. || represents the vector connection operation, N(i) represents the neighbor set of node i; the purpose of introducing the LeakyReLU activation function is to capture more nonlinear relationships so that the model can better cope with different types of node features; node-level attention is used to measure the influence of different neighbor nodes on the current node;

[0116] Step 5.3, edge-level attention:

[0117] In the contract graph, the types of edges are diverse and important. Edge-level attention is introduced to distinguish the influence of different edges. ij The edge-level attention weight of the connected nodes i and j is:

[0118]

[0119] Among them, e ij represents the edge type feature vector (such as control flow, data flow, backoff edge), W e and a e is the linear transformation matrix and weight vector of edge-level attention; through this mechanism, the model can distinguish the impact of different types of edges on node feature aggregation, and ε(i) is the set of edges connected to node i;

[0120] Step 5.4, feature aggregation:

[0121] After calculating the attention weights at the node level and edge level, the updated feature representation of node i is obtained by weighted aggregation of the information of neighboring nodes:

[0122]

[0123] Among them, σ is a nonlinear activation function. Then, all nodes in the global graph and the local graph are aggregated to obtain the feature representation H of the global graph. global and the feature representation H of the local graph local :

[0124] H global =Aggregate({h′ i |i∈V global})

[0125] H local =Aggregate(({h′ i |i∈V local})

[0126] Among them, V global and V local Represents the node sets in the global graph and the local graph respectively; Aggregate() represents the aggregation operation.

[0127] Wherein, in step 6:

[0128] Using the splicing method, the global feature H global and local features H local Combine to form a fusion feature representation H fused , whose expression is:

[0129] H fused =Concat(H global ,H local )

[0130] After feature fusion, the model enters the classification detection stage, using a multi-layer perceptron (MLP) as a classifier. Its structure includes several fully connected layers and nonlinear activation functions to enhance the model's expressive power. Specifically, the output y of the classification process is expressed by the following formula:

[0131] y=σ(W class ·H fused +b class )

[0132] Among them, W class is the weight matrix of the classifier, b class is the bias term, σ is the activation function used to convert the output into a probability distribution. Through back propagation in the training phase, the model will continuously adjust the parameters to minimize the difference between the predicted value and the true label, thereby improving the classification performance.

[0133] To verify the performance of the technical solution of the present invention, we conducted experimental tests and comparisons with the seven most advanced vulnerability detection solutions under the same data set. The experimental results are shown in Table 2. The present invention is superior to the existing methods to a large extent. More specifically, the accuracy of the detection model of the present method reaches 92.39%, which is 8.45% higher than the current best method. The accuracy and recall rate are 5.02% and 4.28% higher than the highest value of the existing technology respectively. In addition, the F1-score of the model of the present invention is 6.31% higher than the highest value of the existing technology.

[0134] Table 2 Performance data comparison between the present invention and the prior art

[0135] Methods Accuracy (%) Recall rate (%) Accuracy (%) F1(%) Securify 69.22 58.93 50.48 53.97 Oyente 61.25 54.75 46.26 50.20 Mythril 65.73 71.23 44.63 55.62 Peculiar 81.77 84.82 79.37 82.56 ReVulDL 82.60 85.00 79.44 83.04 TMP 82.13 80.46 73.02 76.51 AME 87.21 86.39 83.94 85.11 The present invention 92.23 90.67 92.39 91.42

[0136] In summary, the present invention innovatively introduces security best practices in smart contract reentrancy vulnerability detection. Different from existing methods, this method constructs a global contract graph and a local contract graph based on reverse exclusion of information irrelevant to the vulnerability in the source code through security best practice rules. It can not only capture the overall structure of the smart contract and the dependencies between functions, but also deeply analyze the internal call chain of suspicious functions and related control flow and data flow features. In addition, we also used GAT (graph attention network) with edge-level attention mechanism to learn graph features from the contract graph. Finally, we also conducted a large number of comparative experiments to prove that our invention can not only effectively detect reentrancy vulnerabilities in smart contracts in the real world, but also obviously solve the problem of high false alarm rate in the prior art.

[0137] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention, which should all be included in the scope of the claims of the present invention.

Claims

1. A smart contract reentrancy vulnerability detection method driven by security best practices, characterized by: The following steps are involved: Step 1: Pass in the smart contract source code and slice it at the function level to obtain the contract function set; Step 2: Use the function slicing detection algorithm to independently analyze the logic unit of each function in the function set and divide the functions into safe functions and suspicious functions; Step 3: Based on the obtained safe functions and suspicious functions, a global contract graph is constructed with the suspicious function set as the core and combined with the safe function set; Step 4: Use an enhanced filtering algorithm to screen the suspicious function set, and use the screened core function set to construct a local contract graph; Step 5: Use a graph attention network combined with a dual attention mechanism to extract features from the global contract graph and the local contract graph; Step 6: Combine the obtained global graph features and local graph features for feature fusion, use a multi-layer perceptron (MLP) as a classifier, take the fused features as input, and output the prediction results.

2. The smart contract reentrancy vulnerability detection method driven by security best practices according to claim 1 is characterized in that: The specific steps of the function slice detection algorithm in step 2 are: Step 2.1: Initialize two sets, one for storing "safe functions" and the other for storing "suspicious functions"; Step 2.2: Create a rule map to map the predefined security best practice rule set into a query-friendly format; Step 2.3: Traverse each function of the smart contract and perform code slicing to extract independent code snippets of the function; Step 2.4: For each sliced ​​function, initialize a security flag to record whether the function meets the security standard; Step 2.5: In each function’s code snippet, check the statements one by one and detect them according to the rule mapping; Step 2.6: If a statement meets any of the safety rules in the rule mapping, the function is marked as safe and added to the "safe functions" set, and further detection is stopped; Step 2.7: If all statements of the function do not comply with the security rules, add it to the "suspicious function" set; Step 2.8: Repeat the above steps until all functions are traversed; Step 2.9: Finally, output the list of "safe functions" and "suspicious functions".

3. The smart contract reentrancy vulnerability detection method driven by security best practices according to claim 2 is characterized in that: The specific steps for constructing the global contract graph in step 3 are as follows: Step 3.1, node construction: In the construction of the global contract graph, nodes are divided into core nodes, ordinary nodes and fallback nodes; core nodes are composed of suspicious functions and their key variables, and suspicious functions are identified through function slicing detection in the previous step; The security function is marked as a normal node to assist in expressing the global structure of the smart contract; the fallback function is used as a fallback node to simulate the attack path; Step 3.2: Edge construction: After the node is built, the dependency between functions and variables is further captured by building control flow edges, data flow edges, fallback edges, and timing edges. Each type of edge connects core nodes and common nodes according to different semantic dependencies to ensure that the contract reflects the correct call path and data interaction during execution. The control flow edge is used to capture the execution order of the code within the function and reflect the natural flow of the code logic. Data flow edges capture the use and modification of variables; backoff edges are used to model possible backoff attack paths. In addition to control flow edges and data flow edges, timing edges are used to capture the execution order between all function nodes.

4. The smart contract reentrancy vulnerability detection method driven by security best practices according to claim 3 is characterized in that: The specific steps of the enhanced filtering algorithm in step 4 are as follows: Step 4.1: Initialize two sets, one for storing functions with reentrancy risk (F_local) and the other for storing function call relations (G_local); Step 4.2: Traverse the set of suspicious functions after preliminary filtering, and perform the following operations on each function: determine whether the function interacts with an external contract according to the external contract interaction rules; If yes, add the function to the set of functions with reentrancy risk F_local, and record the calling relationship between the function and the external contract in G_local; Step 4.3: Traverse the entire contract call graph and perform the following operations on the call relationship of each suspicious function: If the target function called by the suspicious function is a transfer function, add the suspicious function to the function set F_local with reentrancy risk, and record the call relationship between the function and the transfer function in G_local; Step 4.4: Repeat the above steps until all suspicious functions are processed; Step 4.5: Output the set of functions containing reentrancy risks and the corresponding function call relationship graph.

5. The smart contract reentrancy vulnerability detection method driven by security best practices according to claim 1 is characterized in that: The specific method of extracting the features of the global contract graph and the local contract graph in step 5 is as follows: Step 5.1: Linear transformation of node features: We first start by linearly transforming the features of each node, using a learnable weight matrix W to transform the features h of each node i i Make changes: h' i =Wh i Among them, h i is the original feature of node i, such as the code feature of a function or the attribute information of a variable. The purpose of this linear transformation is to project the node feature into a new feature space so that it is comparable with other node features. Step 5.2, node level attention: The node-level attention in the contract graph is used to capture the influence of the internal call chain of the function. For node i and its neighbor node j, the node-level attention weight is calculated as follows: Among them, W n is the linear transformation matrix, a n is the learnable weight vector of node-level attention. || represents the vector connection operation, N(i) represents the neighbor set of node i; the purpose of introducing the LeakyReLU activation function is to capture more nonlinear relationships so that the model can better cope with different types of node features; node-level attention is used to measure the influence of different neighbor nodes on the current node; Step 5.3, edge-level attention: In the contract graph, the types of edges are diverse and important. Edge-level attention is introduced to distinguish the influence of different edges. ij The edge-level attention weight of the connected nodes i and j is: Among them, e ij represents the edge type feature vector (such as control flow, data flow, backoff edge), W e and a e is the linear transformation matrix and weight vector of edge-level attention; through this mechanism, the model can distinguish the impact of different types of edges on node feature aggregation, and ε(i) is the set of edges connected to node i; Step 5.4, feature aggregation: After calculating the attention weights at the node level and edge level, the updated feature representation of node i is obtained by weighted aggregation of the information of neighboring nodes: Among them, σ is a nonlinear activation function. Then, all nodes in the global graph and the local graph are aggregated to obtain the feature representation H of the global graph. global and the feature representation H of the local graph local : H global =Aggregate({h′ i |i∈V global }) H local =Aggregate({h′ i |i∈V local }) Among them, V global and V local Represents the node sets in the global graph and the local graph respectively; Aggregate() represents the aggregation operation.

6. The smart contract reentrancy vulnerability detection method driven by security best practices according to claim 5 is characterized in that: In step 6: Using the splicing method, the global feature H global and local features H local Combine to form a fusion feature representation H fused , whose expression is: H fused =Concat(H global ,H local ) After feature fusion, the model enters the classification detection stage, using a multi-layer perceptron (MLP) as a classifier. Its structure includes several fully connected layers and nonlinear activation functions to enhance the model's expressive power. Specifically, the output y of the classification process is expressed by the following formula: y=σ(W class ·H fused +b class ) Among them, W class is the weight matrix of the classifier, b class is the bias term, σ is the activation function used to convert the output into a probability distribution. Through back propagation in the training phase, the model will continuously adjust the parameters to minimize the difference between the predicted value and the true label, thereby improving the classification performance.