A Smart Contract Vulnerability Detection Method Based on Pre-training Technology

By employing a smart contract vulnerability detection method based on pre-training technology and utilizing multimodal feature extraction and decision fusion, the accuracy and reliability issues of smart contract vulnerability detection are addressed, achieving more efficient feature learning and detection results.

CN120180447BActive Publication Date: 2026-11-10CHONGQING UNIV OF POSTS & TELECOMM
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510315271.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-18
Publication Date
2026-11-10
Estimated Expiration
2045-03-18

AI Technical Summary

Technical Problem

Existing smart contract vulnerability detection technologies are insufficient in terms of multimodal data utilization, feature extraction methods, and detection model performance, making it difficult to meet the security requirements of smart contracts. In particular, when dealing with the multimodal features of smart contracts, traditional methods cannot fully capture their complex features, resulting in limited detection accuracy.

Method used

This paper adopts a pre-training-based approach to extract multimodal information from smart contract source code, including semantic features, graph structure features, and execution behavior features. It utilizes the BERT pre-trained language model and Graph Attention Network (GAT) combined with a multi-head attention mechanism to generate initial node features. Finally, it uses a stacking method for decision fusion to improve the accuracy of feature extraction and detection.

Benefits of technology

It significantly improves the accuracy and reliability of smart contract vulnerability detection, overcomes the limitations of traditional methods in graph structure data processing, and can guarantee no less than the best detection effect of a single modality in the worst case, thereby reducing security risks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120180447B_ABST
    Figure CN120180447B_ABST
Patent Text Reader

Abstract

This invention proposes a smart contract vulnerability detection method based on pre-training technology, comprising: extracting multimodal information from the smart contract source code; inputting the smart contract source code into a first pre-trained language model to extract semantic features; inputting the control flow graph of the smart contract source code into a GAT model based on multi-head attention to extract graph structure features; inputting the intermediate representation (IR) of the smart contract source code into a second pre-trained language model to extract execution behavior features; inputting the semantic features, execution behavior features, and graph structure features of the smart contract source code into three classifiers respectively to obtain corresponding prediction results; and fusing the prediction results obtained from the three classifiers to obtain the final decision. This invention can identify potential risks in advance, reduce security vulnerabilities, and has broad application prospects and commercial value.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of information security technology, and in particular relates to a smart contract vulnerability detection method based on pre-training technology. Background Technology

[0002] With the widespread application of blockchain technology, smart contracts are playing a crucial role in numerous fields such as finance, supply chain management, and the Internet of Things. However, once deployed, the operating mechanism of smart contracts is difficult to modify. If vulnerabilities exist, they can lead to serious economic losses and security risks, such as hacking attacks, theft of funds, and data breaches. Therefore, accurately detecting vulnerabilities in smart contracts has become a core task for ensuring the secure and stable operation of blockchain systems.

[0003] Currently, smart contract vulnerability detection faces numerous challenges. From a data characteristics perspective, smart contract data exhibits multimodal features, including information at different levels such as code structure, control flow graph structure, and domain knowledge. Traditional single-modal analysis methods, focusing only on a specific angle, cannot comprehensively capture the complex characteristics of smart contracts, thus limiting detection accuracy.

[0004] In terms of vulnerability detection models, commonly used machine learning and deep learning models have shortcomings when processing smart contract data. For example, traditional machine learning models rely heavily on feature engineering, requiring careful manual design and extraction of features. This not only consumes a lot of manpower and time but also makes it difficult to cover all the key features of smart contract data. On the other hand, deep learning models, such as some simple neural networks, lack effective feature extraction and processing capabilities when faced with the complex graph structure data of smart contracts, and cannot fully explore the potential patterns in the data.

[0005] Specifically, in graph structure data processing, the control flow graph of a smart contract contains rich structural information, but existing methods are ineffective in extracting features from it. For example, traditional node feature aggregation methods, such as average pooling, treat all nodes equally and fail to highlight the importance of key nodes; max pooling is easily affected by noisy nodes, resulting in the loss of important information. Furthermore, when using Graph Attention Networks (GAT) for feature extraction, effectively combining multimodal information and optimizing the network structure to improve the accuracy and efficiency of feature extraction is also a problem that urgently needs to be solved.

[0006] In summary, existing smart contract vulnerability detection technologies have shortcomings in multimodal data utilization, feature extraction methods, and detection model performance, making it difficult to meet the growing security needs of smart contracts. There is an urgent need for an innovative technical solution to improve the accuracy and reliability of smart contract vulnerability detection. Summary of the Invention

[0007] To address the problems existing in the background art, one aspect of the present invention provides a smart contract vulnerability detection method based on pre-training technology, comprising:

[0008] S1: Extract multimodal information of the smart contract source code from the smart contract source code, wherein the multimodal information includes: smart contract source code, control flow chart of smart contract source code, and intermediate representation (IR) of smart contract source code;

[0009] S2: Input the smart contract source code into the first pre-trained language model to extract the semantic features of the smart contract source code;

[0010] S3: Input the control flow graph of the smart contract source code into the GAT model based on multi-head attention to extract the graph structure features of the smart contract source code;

[0011] S4: Input the intermediate representation (IR) of the smart contract source code into the second pre-trained language model to extract the execution behavior features of the smart contract source code;

[0012] S5: Input the semantic features, execution behavior features, and graph structure features of the smart contract source code into three classifiers respectively to obtain the corresponding prediction results;

[0013] S6: The prediction results obtained from the three classifiers are fused to obtain the final decision.

[0014] Another aspect of the present invention provides an electronic device, including a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the aforementioned smart contract vulnerability detection method based on pre-training technology.

[0015] In one aspect, the present invention provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the aforementioned smart contract vulnerability detection method based on pre-training technology.

[0016] The present invention has at least the following beneficial effects

[0017] This invention generates initial node features from a multimodal perspective, including code structure, graph structure, and domain knowledge. It comprehensively captures the characteristics of smart contract nodes, providing a rich and accurate data foundation for subsequent analysis. Compared to single-modal feature extraction, it more completely reflects the inherent information of smart contracts, improving detection accuracy. This invention employs a Graph Attention Network (GAT) combined with a multi-head attention mechanism. In multi-layer hidden layer computation, each node effectively integrates neighbor node information, dynamically adjusts the importance of neighbor nodes, and learns more representative node features. This process fully mines control flow graph structure information, overcoming the limitations of traditional methods in processing graph structure data, and improving feature learning efficiency and quality. Sub-nodes make decisions based on different modal features, and then fuse these decisions through a stacking method. This approach integrates multimodal decision information, avoiding the one-sidedness of single-modal decisions. Even in the worst case, it ensures detection performance no less than the best single-modal result, significantly improving the accuracy and reliability of smart contract vulnerability assessment and effectively reducing security risks. Attached Figure Description

[0018] Figure 1 This is a schematic diagram of the method flow of the present invention. Detailed Implementation

[0019] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of the present invention. Unless otherwise specified, the following embodiments and features can be combined with each other.

[0020] Please see Figure 1 This invention provides a smart contract vulnerability detection method based on pre-training technology, comprising:

[0021] S1: Extract multimodal information of the smart contract source code from the smart contract source code, wherein the multimodal information includes: smart contract source code, control flow chart of smart contract source code, and intermediate representation (IR) of smart contract source code;

[0022] Preferably, the extraction of multimodal information from the smart contract source code includes: preprocessing the smart contract source code; generating a control flow diagram of the smart contract source code using the Slither static analysis tool; and generating an intermediate representation (IR) of the smart contract source code using the Slither tool.

[0023] In this embodiment, since the modal data of the control flow graph and intermediate representation of the smart contract cannot be directly obtained, it is necessary to generate the control flow graph and intermediate representation based on the source code. A control flow graph (CFG) is a graph structure used to represent the execution flow of a program, recording the variable calls and function calls of each part of the system when the EVM executes a smart contract. The control flow graph consists of basic blocks and control flow edges. A basic block is a set of sequentially executed instructions without jumps or branches, up to the last statement. Control flow edges represent directed edges indicating possible execution paths of the code, including sequential execution, conditional jumps, and function calls. This method uses the Slither static analysis tool to generate the control flow graph. An intermediate representation (IR) is a data structure used in program compilation and analysis, serving as a bridge between source code and machine code. IR is an abstract form of code representation that helps optimize, analyze, and transform programs. It is typically closer to machine code than the source code but still maintains a certain level of readability, facilitating further processing by the compiler.

[0024] S2: Input the smart contract source code into the first pre-trained language model to extract the semantic features of the smart contract source code;

[0025] S3: Input the control flow graph of the smart contract source code into the GAT model based on multi-head attention to extract the graph structure features of the smart contract source code;

[0026] Preferably, the graph structure features for extracting smart contract source code include:

[0027] S31: Initialize the initial characteristics of nodes based on their code structure, graph structure, and domain knowledge;

[0028] Preferably, the initial characteristics of the initialization node include:

[0029] S331: Perform word segmentation on the smart contract code to generate a bag of words containing all unique words, symbols, and keywords; for each node in the control flow graph, determine its associated code segment, count the number of times each element in the bag of words appears in the code segment, and form the bag of words frequency feature of the node; for example, if the bag of words contains 1000 elements, and "function" appears 5 times and "uint" appears 3 times in the associated code segment of the node, then construct a 1000-dimensional vector and fill the corresponding positions with the corresponding number of occurrences.

[0030] S332: Use specialized AST construction tools or libraries to build the abstract syntax tree of smart contracts. Extract the node type, AST depth, number of child nodes and parent node type from the AST for each node. Combine the AST features to form the node's bag-of-words frequency features and AST features to obtain the node's code structure features.

[0031] In this embodiment, one-hot encoding is performed on common node types (such as function definitions, variable declarations, assignment statements, conditional statements, loop statements, etc.). Assume there are 10 node types, with function definition nodes represented as [1,0,0,…,0], variable declaration nodes represented as [0,1,0,…,0], etc.

[0032] The AST depth record shows the depth value of a node in the AST. The root node has a depth of 0, and the depth value increases by 1 for each deeper layer.

[0033] Number of child nodes: The number of child nodes that a node has is counted as a numerical feature.

[0034] Parent node type: The parent node type is one-hot encoded, using the same encoding method as the node type. These features are combined into a vector. Assuming the node type encoding is 10-dimensional, the depth is 1-dimensional, the number of child nodes is 1-dimensional, and the parent node type encoding is 10-dimensional, the final AST feature vector length is 22 dimensions.

[0035] S333: Calculate the in-degree and out-degree of each node in the control flow graph and concatenate them to obtain the degree centrality feature; calculate the betweenness centrality of each node using a graph algorithm library, i.e., count the number of times all shortest paths pass through the node and normalize the result to a value between 0 and 1, which is used as the betweenness centrality feature of the node; calculate the proximity centrality of each node using a graph algorithm library, i.e., calculate the reciprocal of the sum of the shortest paths between the node and all other nodes and normalize it to a value between 0 and 1, which is used as the proximity centrality feature of the node; concatenate the degree centrality feature, betweenness centrality feature, and proximity centrality feature of the node to obtain the graph structure feature of the node.

[0036] In this embodiment, the degree centrality feature is calculated by taking the in-degree and out-degree of each node in the control flow graph and combining them into a two-dimensional vector. For example, if a node has an in-degree of 8 and an out-degree of 5, then the degree centrality feature vector is [8,5].

[0037] Betweenness centrality feature: The betweenness centrality of each node is calculated using a graph algorithm library (such as NetworkX), which counts the number of times all shortest paths pass through the node and normalizes the result so that its value is between 0 and 1, as a separate numerical feature.

[0038] Proximity centrality feature: The proximity centrality of each node is calculated using a graph algorithm library. This is done by calculating the reciprocal of the sum of the shortest paths between the node and all other nodes, and normalizing it to between 0 and 1, as a separate numerical feature.

[0039] S334: Based on smart contract security knowledge, check whether the node is involved in sensitive operations, and set a binary flag for each type of sensitive operation, where 1 is involved and 0 is not involved; at the same time, check whether the node has known security vulnerability patterns, and set a binary flag for each vulnerability pattern, where 1 is involved and 0 is not involved; concatenate the sensitive operation flag vector and the security vulnerability pattern flag vector to obtain the node's domain knowledge features;

[0040] Based on smart contract security knowledge, the system checks whether nodes involve sensitive operations (such as fund transfers, permission modifications, and external contract calls), assigning a binary flag to each type of sensitive operation (1 for involvement, 0 for non-involvement). Simultaneously, it checks for known security vulnerability patterns (such as integer overflows, reentrancy attacks, and unverified external calls), assigning a binary flag to each vulnerability pattern. The sensitive operation flag vector and the security vulnerability pattern flag vector are concatenated; assuming 3 types of sensitive operations and 5 types of security vulnerability patterns, an 8-dimensional security feature vector is ultimately formed.

[0041] S335: The initial features of a node are obtained by concatenating its code structure features, graph structure features, and domain knowledge features.

[0042] S32: Input the control flow graph data and the initial feature vectors of the nodes into the GAT model. For each node i and its neighboring nodes j, use the shared linear transformation matrix at each attention head k. Transform the node features to obtain and Where k = 1, ..., K, and K is the number of attention heads; This represents the weight matrix of the k-th attention head in the l-th hidden layer of GAT; This represents the feature embedding of node i in the (l-1)th hidden layer of GAT; This represents the feature embedding of node i's neighbor node j in the (l-1)th hidden layer of GAT;

[0043] S33: Calculate the attention coefficients of nodes in the attention head and their neighboring nodes using the attention function:

[0044]

[0045] in, Represents the learnable parameter matrix The transpose of , ∥ denotes concatenation, j,m∈N (i)N (i) Represents the set of neighboring nodes of node i; LeakyReLU represents the activation function; exp represents the exponential function; This represents the attention coefficient of node i and its neighbor node j in the output of the k-th attention head in the (l-1)-th hidden layer of GAT;

[0046] S34: Based on the attention coefficients of the attention head, the features of neighboring nodes are weighted and summed to obtain the intermediate features of each node under each attention:

[0047]

[0048] in, σ represents the intermediate feature of node i in the output of the k-th attention head of the l-th hidden layer of GAT; σ represents the activation function;

[0049] S35: Average the intermediate features obtained from K attention heads to obtain the feature of node i after processing by the multi-head attention mechanism at layer l.

[0050]

[0051] Where K represents the number of attention heads in multi-head attention;

[0052] S36: After calculation of the Lth hidden layer of GAT, the features of the node in the last hidden layer are obtained, and the graph structure features of the smart contract source code are generated by using a node attention mechanism and weighted average aggregation.

[0053] Preferably, the graph structure features for generating smart contract source code include:

[0054] S361: Calculate intermediate feature c:

[0055]

[0056] Where n is the total number of nodes, and W is a learnable weight matrix;

[0057] S362: Calculate the attention weights between each node and the intermediate feature c. Where σ is the Sigmoid activation function, W A It is a weight matrix;

[0058] S363: Graph structure characteristics of smart contract source code;

[0059]

[0060] Among them, h G The graph structure features representing the source code of a smart contract.

[0061] S4: Input the intermediate representation (IR) of the smart contract source code into the second pre-trained language model to extract the execution behavior features of the smart contract source code;

[0062] Preferably, both the first pre-trained language model and the second pre-trained language model use the BERT pre-trained language model.

[0063] In this embodiment, to capture high-level semantic features from the source code, this method uses a BERT pre-trained language model for feature extraction. First, the smart contract's source code needs to be preprocessed, significantly reducing its average length. Specifically, two cleaning operations are performed: removing code comments and compressing whitespace. Since code comments and redundant whitespace are irrelevant to the code logic, removing them will not affect the code's execution logic, and they may introduce noise that interferes with feature extraction. The preprocessed code sequence is converted into three sets of embedding vectors through an embedding layer, containing basic information from the smart contract's source code, such as code semantics, code structure, and word position information within the contract. The source code is then converted into vectors by the embedding layer and fed into the encoding block to calculate the relationships between words. Because this method utilizes the overall semantic features of the smart contract, the extracted feature vector corresponds to the first character, i.e., the feature vector of the [CLS] character. Simultaneously, to extract the smart contract's execution behavior features and contextual dependencies from the intermediate representation, this method also uses a BERT pre-trained language model for feature extraction. BERT's powerful context-aware capabilities are used to perform refined modeling of the contract's execution behavior and contextual dependencies.

[0064] S5: Input the semantic features, execution behavior features, and graph structure features of the smart contract source code into three classifiers respectively to obtain the corresponding prediction results;

[0065] S6: The prediction results obtained from the three classifiers are fused to obtain the final decision.

[0066] Preferably, the step of fusing the prediction results from the three classifiers to obtain the final decision includes:

[0067] S61: Use the semantic features, execution behavior features, and graph structure features of the smart contract source code to train the corresponding classifiers.

[0068] S62: After training, each classifier judges the input features based on the modal features it has learned and gives a decision on whether the smart contract has a vulnerability.

[0069] S63: A stacking method is used for decision fusion, which takes the decision outputs of multiple classifiers and the real labels as input information of the meta-learner. The meta-learner fuses the decision results of the classifiers to obtain the final decision.

[0070] In this embodiment, each sub-classifier, based on its learned modal features, judges the input smart contract data and provides a decision result regarding whether the smart contract has vulnerabilities. Let the number of sub-classifiers be n, and their corresponding decision outputs be denoted as y1, y2, ..., yn, where yi (i = 1, 2, ..., n) represents the decision result of the i-th sub-classifier. A stacking method is used for decision fusion, taking the decision outputs of multiple sub-classifiers as input information. Specifically, the input of the meta-learner consists of the set of decision outputs of the sub-classifiers {y1, y2, ..., yn}. n The model consists of the subclassifier and the real label Y. The real label Y provides supervision during the training of the meta-learner, ensuring that the meta-learner learns how to effectively fuse the decisions of the subclassifiers. This invention selects a binomial logistic regression model as the meta-learner to fuse the decision results of the subclassifiers. The binomial logistic regression model can map the multimodal subclassifier decision information to the final classification result, determining whether a smart contract has vulnerabilities. In the binomial logistic regression model, the model parameters w are determined by maximizing likelihood estimation. The specific calculation formula is as follows:

[0071]

[0072] Where, x∈R n+1 Y is the input vector of the meta-learner, which contains the decision output of the sub-classifier and information such as possible bias terms; Y∈{0,1} is the output of the model, representing whether there is a vulnerability in the smart contract (Y=1 indicates that there is a vulnerability, Y=0 indicates that there is no vulnerability).

[0073] Another aspect of the present invention provides an electronic device, including a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the aforementioned smart contract vulnerability detection method based on pre-training technology.

[0074] In one aspect, the present invention provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the aforementioned smart contract vulnerability detection method based on pre-training technology.

[0075] In summary, initial node features are generated from a multimodal perspective, including code structure, graph structure, and domain knowledge. Through various methods such as bag-of-words model, AST features, and degree centrality, the characteristics of smart contract nodes are comprehensively captured, providing a rich and accurate data foundation for subsequent analysis. Compared to single-modal feature extraction, this method more completely reflects the inherent information of smart contracts and improves detection accuracy. This invention employs a Graph Attention Network (GAT) combined with a multi-head attention mechanism. In multi-layer hidden layer computation, each node can effectively integrate neighbor node information, dynamically adjust the importance of neighbor nodes, and learn more representative node features. This process fully mines the control flow graph structure information, overcoming the limitations of traditional methods in processing graph structure data and improving the efficiency and quality of feature learning. Sub-classifiers make decisions based on different modal features, and then use a stacking method to fuse the decisions using a binomial logistic regression model. This approach integrates multimodal decision information, avoiding the one-sidedness of single-modal decisions. Even in the worst case, it ensures a detection performance no less than the best single-modal result, significantly improving the accuracy and reliability of smart contract vulnerability judgment and effectively reducing security risks.

[0076] Any references to memory, storage, database, or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.

[0077] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.

Claims

1. A smart contract vulnerability detection method based on pre-training technology, characterized in that, include: S1: Extract multimodal information of the smart contract source code from the smart contract source code, wherein the multimodal information includes: smart contract source code, control flow chart of smart contract source code, and intermediate representation (IR) of smart contract source code; S2: Input the smart contract source code into the first pre-trained language model to extract the semantic features of the smart contract source code; S3: Input the control flow graph of the smart contract source code into the GAT model based on multi-head attention to extract the graph structure features of the smart contract source code; S4: Input the intermediate representation (IR) of the smart contract source code into the second pre-trained language model to extract the execution behavior features of the smart contract source code; S5: Input the semantic features, execution behavior features, and graph structure features of the smart contract source code into three classifiers respectively to obtain the corresponding prediction results; S6: The prediction results obtained from the three classifiers are fused to obtain the final decision; The extraction of multimodal information from smart contract source code includes: preprocessing the smart contract source code; generating a control flow diagram of the smart contract source code using the Slither static analysis tool; and generating an intermediate representation (IR) of the smart contract source code using the Slither tool. Both the first and second pre-trained language models use the BERT pre-trained language model. The graph structure features for extracting smart contract source code include: S31: Initialize the initial characteristics of nodes based on their code structure, graph structure, and domain knowledge; S32: Input the control flow graph data and the initial feature vectors of the nodes into the GAT model. For each node i and its neighboring nodes j, use the shared linear transformation matrix at each attention head k. Transform the node features to obtain and Where k=1,⋯,K, and K is the number of attention heads; This represents the weight matrix of the k-th attention head in the l-th hidden layer of GAT; This represents the feature embedding of node i in the (l-1)th hidden layer of GAT; This represents the feature embedding of node i's neighbor node j in the (l-1)th hidden layer of GAT; S33: Calculate the attention coefficients of nodes in the attention head and their neighboring nodes using the attention function: ; ; in, Represents the learnable parameter matrix transpose, Indicates splicing, , Represents a node The set of neighboring nodes; exp represents the activation function; Indicates the GAT number In the hidden layer, the th Each node outputs attention. and its neighboring nodes Attention coefficient; S34: Based on the attention coefficients of the attention head, the features of neighboring nodes are weighted and summed to obtain the intermediate features of each node under each attention: ; in, This indicates that node i is in the l-th hidden layer of GAT. Intermediate features of the attention head output; Indicates the activation function; S35: Average the intermediate features obtained from K attention heads to obtain the feature of node i after processing by the multi-head attention mechanism at layer l. : ; Where K represents the number of attention heads in multi-head attention; S36: After calculation of the Lth hidden layer of GAT, the features of the node in the last hidden layer are obtained, and the graph structure features of the smart contract source code are generated by using a node attention mechanism and weighted average aggregation. The initial characteristics of the initialization node include: S331: Perform word segmentation on the smart contract code to generate a bag of words containing all unique words, symbols and keywords; for each node in the control flow graph, determine its associated code segment, count the number of times each element in the bag of words appears in the code segment, and form the bag of words frequency feature of the node; S332: Use specialized AST construction tools or libraries to build the abstract syntax tree of smart contracts. Extract the node type, AST depth, number of child nodes and parent node type from the AST for each node. Combine the AST features to form the node's bag-of-words frequency features and AST features to obtain the node's code structure features. S333: Calculate the in-degree and out-degree of each node in the control flow graph and concatenate them to obtain the degree centrality feature; calculate the betweenness centrality of each node using a graph algorithm library, i.e., count the number of times all shortest paths pass through the node and normalize the result to a value between 0 and 1, which is used as the betweenness centrality feature of the node; calculate the proximity centrality of each node using a graph algorithm library, i.e., calculate the reciprocal of the sum of the shortest paths between the node and all other nodes and normalize it to a value between 0 and 1, which is used as the proximity centrality feature of the node; concatenate the degree centrality feature, betweenness centrality feature, and proximity centrality feature of the node to obtain the graph structure feature of the node. S334: Based on smart contract security knowledge, check whether the node is involved in sensitive operations, and set a binary flag for each type of sensitive operation, where 1 is involved and 0 is not involved; at the same time, check whether the node has known security vulnerability patterns, and set a binary flag for each vulnerability pattern, where 1 is involved and 0 is not involved; concatenate the sensitive operation flag vector and the security vulnerability pattern flag vector to obtain the node's domain knowledge features; S335: The initial features of a node are obtained by concatenating its code structure features, graph structure features, and domain knowledge features.

2. The smart contract vulnerability detection method based on pre-training technology according to claim 1, characterized in that, The graph structure features of the generated smart contract source code include: S361: Calculate intermediate feature c: ; Where n is the total number of nodes, and W is a learnable weight matrix; S362: Calculate the attention weights between each node and the intermediate feature c. ,in, It is the Sigmoid activation function. It is a weight matrix; S363: Graph structure characteristics of smart contract source code; ; in, The graph structure features representing the source code of a smart contract.

3. The smart contract vulnerability detection method based on pre-training technology according to claim 1, characterized in that, Its features are, The process of fusing the predictions from the three classifiers to obtain the final decision includes: S61: Use the semantic features, execution behavior features, and graph structure features of the smart contract source code to train the corresponding classifiers. S62: After training, each classifier judges the input features based on the modal features it has learned and gives a decision on whether the smart contract has a vulnerability. S63: A stacking method is used for decision fusion, which takes the decision outputs of multiple classifiers and the real labels as input information of the meta-learner. The meta-learner fuses the decision results of the classifiers to obtain the final decision.

4. An electronic device, characterized in that, It includes a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the method as described in any one of claims 1 to 3.

5. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium, which, when executed by a processor, implements the method as described in any one of claims 1 to 3.

Citation Information

Patent Citations

  • Software defect prediction method, system and equipment based on information fusion and medium

    CN115617694A