A fine-grained vulnerability detection method for smart contracts based on expert knowledge

Through the fine-grained vulnerability detection method of smart contracts based on expert knowledge, combined with static analysis and deep learning technology, the problem that existing methods are difficult to fully capture the complex semantic and structural information of smart contracts is solved, achieving higher detection accuracy and security.

CN119475358BActive Publication Date: 2025-04-11HUNAN NORMAL UNIVERSITY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510029264.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-08
Publication Date
2025-04-11
Estimated Expiration
2045-01-08

AI Technical Summary

Technical Problem

Existing smart contract vulnerability detection methods based on deep learning are difficult to fully capture the complex semantic and structural information of contracts, resulting in insufficient detection accuracy.

Method used

A fine-grained vulnerability detection method for smart contracts based on expert knowledge is adopted. Through static analysis of the smart contract source code, an abstract syntax tree and control flow diagram is combined, the attention mechanism is used to combine features, and an expert knowledge classifier is introduced. The output of multiple classifiers is fused through the stack pressing method to achieve more accurate vulnerability detection.

Benefits of technology

It improves the accuracy and interpretability of smart contract vulnerability detection, realizes line-of-code vulnerability positioning, reduces the false positive rate, and supports rapid response to new vulnerabilities, improving the security of smart contracts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119475358B_ABST
    Figure CN119475358B_ABST
Patent Text Reader

Abstract

A method for detecting fine-grained vulnerabilities in smart contracts based on expert knowledge, the method comprising: S1: using a large language model, constructing prompt words, analyzing smart contract source code, and labeling smart contract data sets; statically analyzing smart contract source code statements, obtaining a preliminary representation of source code fine-grained features by representing source code elements as vectors, and obtaining a graph representation of the source code by merging abstract syntax tree subtrees into the code graph of control flow graph nodes; S2: obtaining heterogeneous code features and source code fine-grained features of the same smart contract, inputting them into a BGSCVul model for iterative fusion, and constructing a deep learning classifier; S3: making decisions based on specific expert knowledge by constructing an expert knowledge classifier; S4: using a stacking method to fuse the outputs of each sub-classifier and output a final prediction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of smart contract vulnerability detection, and specifically relates to a smart contract fine-grained vulnerability detection method based on expert knowledge. Background Art

[0002] Since the birth of blockchain, blockchain technology has gained wide attention and application in many fields such as business, finance, and healthcare. The concept of decentralization and its practical feasibility in finance and daily life have led to a new direction in cryptographic research. Blockchain 2.0, represented by Ethereum, has promoted the widespread application of smart contracts, which not only opened up unlimited possibilities for decentralized applications, but also promoted the progress of the foundations of computer science. However, the security risks of smart contracts and the performance bottlenecks of blockchain itself, such as capacity limitations, latency issues, and scalability challenges, have become the main obstacles to large-scale promotion. Therefore, smart contract vulnerability detection has become a key issue in academic research.

[0003] Existing deep learning-based detection methods mainly rely on single-dimensional analysis of smart contract source code, which is difficult to fully capture the complex semantics and structural information of the contract. To this end, this paper proposes a smart contract fine-grained vulnerability detection method based on expert knowledge - BGSCVul.

[0004] BGSCVul statically analyzes smart contract source code statements and merges abstract syntax tree subtrees into the code graph of control flow graph nodes for heterogeneous code feature representation. It combines fine-grained features through the attention mechanism and combines expert knowledge classifiers to extract more comprehensive vulnerability feature representations. BGSCVul can more accurately identify potential vulnerabilities in smart contracts. Summary of the invention

[0005] The present invention provides a fine-grained vulnerability detection method for smart contracts based on expert knowledge, the main purpose of which is to be able to extract vulnerability information more comprehensively, thereby improving the accuracy of vulnerability detection.

[0006] In order to achieve the above object, a smart contract fine-grained vulnerability detection method based on expert knowledge of the present invention comprises the following steps:

[0007] S1: Use a large language model to construct prompt words, analyze smart contract source code, and label the smart contract dataset; statically analyze smart contract source code statements, obtain a preliminary representation of source code fine-grained features by representing source code elements as vectors, and obtain a graph representation of the source code by merging abstract syntax tree subtrees into the code graph of control flow graph nodes;

[0008] S2: Obtain heterogeneous code features and source code fine-grained features of the same smart contract through preliminary representation of source code fine-grained features and source code graph representation, input them into the BGSCVul model for iterative fusion, and build a deep learning classifier;

[0009] S3: By constructing an expert knowledge classifier, decisions can be made based on specific expert knowledge;

[0010] S4: Use the stacking method to fuse the outputs of each sub-classifier and output the final prediction.

[0011] Furthermore, the step S1 comprises:

[0012] S1-1: Collect and organize data on smart contract source code by analyzing technical documents such as syntax descriptions and code features of Ethereum smart contracts and combining them with descriptions of vulnerabilities on public smart contract vulnerability platforms;

[0013] S1-2: Based on the smart contract code collected in step S1-1, the abstract syntax trees of different versions of smart contract codes are standardized through official interfaces and Solidity version descriptions;

[0014] S1-3: Use descriptive words such as "reentrancy", "denial of service", and "unchecked low-level call"; provide sufficient background information to help the model understand the meaning of the code snippet, and describe the specific location through "transfer function in Solidity contract"; give the code snippet with vulnerabilities as an example so that the model can learn how to identify similar patterns; raise specific questions or tasks to guide the model to find potential security risks, and use specific instructions such as "find all places that may trigger reentrancy attacks"; combine with carefully designed prompt words to assist in analyzing the smart contract source code and accurately identify potential vulnerability types, analyze the answers of multiple large models, and if more than 80% of the answers of the large models indicate that the contract has vulnerabilities, then label the contract as having vulnerabilities;

[0015] S1-4: In order to accurately capture the source code features of smart contracts, the ANTLR4 tool is used in conjunction with the syntax specifications of the Solidity language to construct an abstract syntax tree, converting the smart contract source code into an input stream in a format that can be read by the ANTLR4 parser. Then, the lexical analyzer is used to decompose the input stream into tokens for the source code.

[0016] S1-5: In order to further optimize the abstract syntax tree data and improve the accuracy of subsequent analysis, the generated sequences were normalized. In this stage, we focused on removing redundant information that did not contribute substantially to the semantic interpretation. All simple variable names, unnecessary punctuation marks, and various types of constant values ​​were systematically replaced or removed.

[0017] S1-6: In order to further extract source code information, FastText is used as a code embedding tool. After training, each token in the corpus, including those symbols reflecting structural characteristics, is converted into a fixed-length real vector. This process effectively captures the intrinsic characteristics of the code. Then, the tokens in the source code are traversed and the vectors of each token are added to obtain a preliminary representation of the fine-grained features of the source code S. vector;

[0018] S1-7: During the static analysis process, four different pieces of information were extracted from the code. First, the Solidity static analysis tool Slither was used to generate a control flow graph as the basis of the code graph. In the control flow graph, each node represents a statement and each edge represents the control flow between statements. Then, based on the control flow graph, the data flow between statements was extracted through the definition-use chain of each variable. Then, the abstract syntax tree subtree of each statement was extracted. This abstract syntax tree subtree was implemented using the Solidity syntax analysis tool solc-typed-ast. Finally, the type information of each statement was obtained from the "nodeType" field of the root node of the abstract syntax tree subtree of each statement.

[0019] S1-8: After obtaining the above code information through static analysis, it is combined with two types of additional virtual nodes v_fun and v_loop to construct a code graph; first, the control flow graph is used as the basis of the code graph, and the data flow information is added to it; then, in order to retain the tree structure of the grammatical features, the abstract syntax tree subtree of each statement is used to replace the content of the corresponding node in the control flow graph; then, the type of each statement is merged into the corresponding node in the graph. The nodes in the merged code graph can reflect the grammatical information of the statement, and the directed edges represent the control flow and data flow between statements.

[0020] Further, step S2 includes the following steps:

[0021] S2-1: For S generated in S1-6 vector, Send it to the feedforward neural network for feature extraction to obtain the fine-grained feature X of the source code reduce ,

[0022] ;

[0023] Where X1 is X reduce The result after the linear layer and relu, X2 is the result after X1 passes through the linear layer and relu, linear is the linear layer, relu is the activation function, after these two layers, the vector S vectorThe dimension will be improved, and then through:

[0024] ;

[0025] S2-2: For each code semantic graph, the input data is ,in is the set of nodes, E is the set of edges, is the feature matrix of the node, is the number of nodes, is the feature dimension of each node. For each propagation, the feature matrix As input, we have:

[0026] ;

[0027] in is the degree matrix, is the adjacency matrix of the graph with self-loops added, is the weight matrix of graph convolution, is the feature dimension after convolution; The final representation after the multi-scale residual graph convolution operation is ,for , and then perform a global attention pooling operation on it, first calculating the attention score :

[0028] ;

[0029] in For Node go through The final representation of the multi-scale residual graph convolutional network, is a learnable weight matrix, is the learned attention vector, and the attention score is obtained Then, the feature representations of all nodes are weighted and summed according to the attention weights to obtain the heterogeneous code feature representation h global The formula is as follows:

[0030] ;

[0031] S2-3: Afterwards, the obtained X reduce With h global Fusion to get h concat , and then use the attention mechanism to h concat Perform update operations. In each training round, the bias and weight will be updated to iterate the fusion parameters that best suit the actual situation:

[0032] ;

[0033] ;

[0034] Where b is the bias of the model and W is the weight.

[0035] Furthermore, the step S3 comprises:

[0036] S3-1: Design expert knowledge for different vulnerabilities,

[0037] S3-2: Input the smart contract source code into the designed expert knowledge classifier to obtain h exp :

[0038] ;

[0039] in It is the smart contract source code.

[0040] Furthermore, the step S4 comprises:

[0041] S4-1 combines the results of the deep learning classifier with the results of the expert knowledge classifier:

[0042] ;

[0043] in Represents a stack push operation.

[0044] S4-2: The obtained results are then flattened and passed through a multi-layer perceptron and sigmoid activation function to obtain the vulnerability representation:

[0045] .

[0046] The present invention extracts fine-grained features by combining large language models to assist annotation and static analysis, and integrates the graph representation structure of the source code to achieve accurate detection of smart contract vulnerabilities. The BGSCVul model is used to iteratively fuse heterogeneous features, and an expert knowledge classifier is introduced to provide professional judgment. Finally, the stacking method is used to fuse the outputs of multiple classifiers. Compared with other methods, it not only improves the detection accuracy and interpretability, but also realizes the vulnerability location at the code line level. It performs well in scalability and adaptability, can handle smart contract codes of different complexities, and supports rapid response to new vulnerabilities. At the same time, it has a high degree of automation, controllable computational overhead, and the complementary verification mechanism of multi-source features and multi-classifiers significantly reduces the false alarm rate, providing a more reliable guarantee for the security of smart contracts, and has important practical application value. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to more clearly illustrate the technical solution of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only one embodiment of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0048] Figure 1 It is the overall flow chart of the scheme of the present invention. DETAILED DESCRIPTION

[0049] The following is a clear and complete description of the technical solution in the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0050] The technical solution of the present application is described in detail below with specific embodiments; the following specific embodiments may be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments.

[0051] In order to achieve the above object, a smart contract vulnerability detection method of the present invention comprises the following steps:

[0052] S1: Use a large language model to construct prompt words, analyze smart contract source code, and label the smart contract dataset; statically analyze smart contract source code statements, obtain a preliminary representation of source code fine-grained features by representing source code elements as vectors, and obtain a graph representation of the source code by merging abstract syntax tree subtrees into the code graph of control flow graph nodes;

[0053] S2: Obtain heterogeneous code features and source code fine-grained features of the same smart contract through preliminary representation of source code fine-grained features and source code graph representation, input them into the BGSCVul model for iterative fusion, and build a deep learning classifier;

[0054] S3: By constructing an expert knowledge classifier, decisions can be made based on specific expert knowledge;

[0055] S4: Use the stacking method to fuse the outputs of each sub-classifier and output the final prediction.

[0056] A smart contract fine-grained vulnerability detection method based on expert knowledge, wherein step S1 comprises:

[0057] S1-1: Collect and organize data on smart contract source code by analyzing technical documents such as syntax descriptions and code features of Ethereum smart contracts and combining them with descriptions of vulnerabilities on public smart contract vulnerability platforms;

[0058] S1-2: Based on the smart contract code collected in step S1-1, the abstract syntax trees of different versions of smart contract codes are standardized through official interfaces and Solidity version descriptions;

[0059] S1-3: Use descriptive words such as "reentrancy", "denial of service", and "unchecked low-level call"; provide sufficient background information to help the model understand the meaning of the code snippet, and describe the specific location through "transfer function in Solidity contract"; give the code snippet with vulnerabilities as an example so that the model can learn how to identify similar patterns; raise specific questions or tasks to guide the model to find potential security risks, and use specific instructions such as "find all places that may trigger reentrancy attacks"; combine with carefully designed prompt words to assist in analyzing the smart contract source code and accurately identify potential vulnerability types, analyze the answers of multiple large models, and if more than 80% of the answers of the large models indicate that the contract has vulnerabilities, then label the contract as having vulnerabilities;

[0060] S1-4: In order to accurately capture the source code features of smart contracts, the ANTLR4 tool is used in conjunction with the syntax specifications of the Solidity language to construct an abstract syntax tree, converting the smart contract source code into an input stream in a format that can be read by the ANTLR4 parser. Then, the lexical analyzer is used to decompose the input stream into tokens for the source code.

[0061] S1-5: In order to further optimize the abstract syntax tree data and improve the accuracy of subsequent analysis, the generated sequence was normalized. In this stage, the focus was on removing redundant information that did not contribute substantially to the semantic interpretation. All simple variable names, unnecessary punctuation marks, and various types of constant values ​​were systematically replaced or cleared. The specific operations are shown in Table 1.

[0062] Table 1: Operations of code elements

[0063] Token_type_id Token_type Normalization 1 COMMENT delete 2 LINE_COMMENT delete 3 ; neglect 4 , neglect 5 . neglect 6 StringLiteral Replace with the corresponding label 7 DecimalNumber Replace with the corresponding label 8 HexNumber Replace with the corresponding label 9 HexLiteral Replace with the corresponding label 10 Version Literal Replace with the corresponding label 11 Identifier Convert to lowercase S1-6: In order to further extract source code information, FastText is used as a code embedding tool. After training, each token in the corpus, including those symbols reflecting structural characteristics, is converted into a fixed-length real vector. This process effectively captures the intrinsic characteristics of the code. Then, the tokens in the source code are traversed and the vectors of each token are added to obtain a preliminary representation of the fine-grained features of the source code S. vector ;

[0064] S1-7: During the static analysis process, four different pieces of information were extracted from the code. First, the Solidity static analysis tool Slither was used to generate a control flow graph as the basis of the code graph; in the control flow graph, each node represents a statement, and each edge represents the control flow between statements; then, based on the control flow graph, the data flow between statements was extracted through the definition-use chain of each variable; then, the abstract syntax tree subtree of each statement was extracted to reflect the grammatical characteristics of the code; this abstract syntax tree subtree was implemented using the Solidity syntax analysis tool solc-typed-ast; finally, the type information of each statement was obtained from the "nodeType" field of the root node of the abstract syntax tree subtree of each statement;

[0065] S1-8: After obtaining the above code information through static analysis, it is combined with two types of additional virtual nodes v_fun and v_loop to construct a code graph; first, the control flow graph is used as the basis of the code graph, and the data flow information is added to it; then, in order to retain the tree structure of the grammatical features, the abstract syntax tree subtree of each statement is used to replace the content of the corresponding node in the control flow graph; then, the type of each statement is merged into the corresponding node in the graph. The nodes in the merged code graph can reflect the grammatical information of the statement, and the directed edges represent the control flow and data flow between statements in the form of a graph structure.

[0066] Further, step S2 includes the following steps:

[0067] S2-1: For S generated in S1-6 vector, Send it to the feedforward neural network for feature extraction to obtain the fine-grained feature X of the source code reduce ,

[0068] ;

[0069] Where X1 is X reduce The result after the linear layer and relu, X2 is the result after X1 passes through the linear layer and relu, linear is the linear layer, relu is the activation function, after these two layers, the vector S vector The dimension will be improved, and then through:

[0070] ;

[0071] S2-2: For each code semantic graph, the input data is ,in is the set of nodes, E is the set of edges, is the feature matrix of the node, is the number of nodes, is the feature dimension of each node. For each propagation, the feature matrix As input, we have:

[0072] ;

[0073] in is the degree matrix, is the adjacency matrix of the graph with self-loops added, is the weight matrix of graph convolution, is the feature dimension after convolution; The final representation after the multi-scale residual graph convolution operation is ,for , and then perform a global attention pooling operation on it, first calculating the attention score :

[0074] ;

[0075] in For Node go through The final representation of the multi-scale residual graph convolutional network, is a learnable weight matrix, is the learned attention vector, and the attention score is obtained Then, the feature representations of all nodes are weighted and summed according to the attention weights to obtain the heterogeneous code feature representation h global, The formula is as follows:

[0076] ;

[0077] S2-3: Afterwards, the obtained X reduce With h global Fusion to get h concat , and then use the attention mechanism to h concat Perform update operations. In each training round, the bias and weight will be updated to iterate the fusion parameters that best suit the actual situation:

[0078] ;

[0079] ;

[0080] Where b is the bias of the model and W is the weight.

[0081] Furthermore, the step S3 comprises:

[0082] S3-1: Design expert knowledge for different vulnerabilities,

[0083] S3-2: Input the smart contract source code into the designed expert knowledge classifier to obtain h exp :

[0084] ;

[0085] in It is the smart contract source code.

[0086] Furthermore, the step S4 comprises:

[0087] S4-1 combines the results of the deep learning classifier with the results of the expert knowledge classifier:

[0088] ;

[0089] in Represents a stack push operation.

[0090] S4-2: The obtained results are then flattened and passed through a multi-layer perceptron and sigmoid activation function to obtain the vulnerability representation:

[0091] .

[0092] In order to further verify the method proposed in this application, this application experimentally verifies the performance of the method by setting up a corresponding experimental environment. The data set used in this application contains 1,300 smart contracts from Ethereum. The pattern extraction tool and graph construction tool are implemented in Python, and the neural network is implemented in pytorch. 80% of the functions are randomly selected as the training set, and the other 20% are used as the test set. The experimental results are shown in Table 2:

[0093] Table 2: Experimental results

[0094]

[0095] Experiments have shown that the present application has achieved a detection accuracy of 86.3% for access control vulnerabilities, 80.1% for arithmetic vulnerabilities, 84.2% for reentrancy vulnerabilities, and 86.2% for unchecked call vulnerabilities. The method BGSCVul of the present invention is superior to the existing methods in terms of the accuracy of the four vulnerability detections in the table, which proves the effectiveness of the present application. Extracting more comprehensive vulnerability feature representations is conducive to more effective identification of vulnerabilities, and the recall rate and precision also have satisfactory performance.

Claims

1. A fine-grained vulnerability detection method for smart contracts based on expert knowledge, characterized in that: The following steps are involved: S1: Use a large language model to construct prompt words, analyze smart contract source code, and label the smart contract dataset; statically analyze smart contract source code statements, obtain a preliminary representation of source code fine-grained features by representing source code elements as vectors, and obtain a graph representation of the source code by merging abstract syntax tree subtrees into the code graph of control flow graph nodes; S2: The fine-grained features of the source code are initially represented and the source code graph is represented. The feedforward neural network and the multi-scale residual graph convolutional neural network are used for feature extraction to obtain the heterogeneous code features and fine-grained features of the source code of the same smart contract. The attention mechanism is then used to obtain the fused features and build a deep learning classifier. S3: By constructing an expert knowledge classifier, decisions can be made based on specific expert knowledge; S4: Use the stacking method to fuse the outputs of each sub-classifier and output the final prediction.

2. According to the expert knowledge-based smart contract fine-grained vulnerability detection method of claim 1, it is characterized in that: The step S1 comprises: S1-1: Collect and organize data on smart contract source code by analyzing the syntax description and code feature technical documentation of Ethereum smart contracts and combining the description of vulnerabilities on the public smart contract vulnerability platform; S1-2: Based on the smart contract code collected in step S1-1, the abstract syntax trees of different versions of smart contract codes are standardized through official interfaces and Solidity version descriptions; S1-3: Use descriptive words such as "reentrancy", "denial of service", and "unchecked low-level call"; provide sufficient background information to help the model understand the meaning of the code snippet, and describe the specific location through "transfer function in Solidity contract"; give the code snippet with vulnerabilities as an example so that the model can learn how to identify similar patterns; raise specific questions or tasks to guide the model to find potential security risks, and use specific instructions such as "find all places that may trigger reentrancy attacks"; combine with carefully designed prompt words to assist in analyzing the smart contract source code and accurately identify potential vulnerability types, analyze the answers of multiple large models, and if more than 80% of the answers of the large models indicate that the contract has vulnerabilities, then label the contract as having vulnerabilities; S1-4: In order to accurately capture the source code features of smart contracts, the ANTLR4 tool is used in conjunction with the syntax specifications of the Solidity language to construct an abstract syntax tree, converting the smart contract source code into an input stream in a format that can be read by the ANTLR4 parser. Then, the lexical analyzer is used to decompose the input stream into tokens for the source code. S1-5: In order to further optimize the abstract syntax tree data and improve the accuracy of subsequent analysis, the generated sequences were normalized. In this stage, we focused on removing redundant information that did not contribute substantially to the semantic interpretation. All simple variable names, unnecessary punctuation marks, and various types of constant values ​​were systematically replaced or removed. S1-6: In order to further extract source code information, FastText is used as a code embedding tool. After training, each token in the corpus, including those symbols reflecting structural characteristics, is converted into a fixed-length real vector. This process effectively captures the intrinsic characteristics of the code. Then, the tokens in the source code are traversed and the vectors of each token are added to obtain a preliminary representation of the fine-grained features of the source code S. vector ; S1-7: During the static analysis process, four different pieces of information were extracted from the code. First, the Solidity static analysis tool Slither was used to generate a control flow graph as the basis of the code graph. In the control flow graph, each node represents a statement and each edge represents the control flow between statements. Then, based on the control flow graph, the data flow between statements was extracted through the definition-use chain of each variable. Then, the abstract syntax tree subtree of each statement was extracted. This abstract syntax tree subtree was implemented using the Solidity syntax analysis tool solc-typed-ast. Finally, the type information of each statement was obtained from the "nodeType" field of the root node of the abstract syntax tree subtree of each statement. S1-8: After obtaining the above code information through static analysis, it is combined with two types of additional virtual nodes v_fun and v_loop to construct a code graph; first, the control flow graph is used as the basis of the code graph, and the data flow information is added to it; then, in order to retain the tree structure of the grammatical features, the abstract grammar book subtree of each statement is used to replace the content of the corresponding node in the control flow graph; then, the type of each statement is merged into the corresponding node in the graph. The nodes in the merged code graph can reflect the grammatical information of the statement, and the directed edges represent the control flow and data flow between statements. In this way, the merged code graph is a graph representation of the source code.

3. According to the expert knowledge-based smart contract fine-grained vulnerability detection method of claim 1, it is characterized in that: The step S2 comprises: S2-1: Preliminary representation of the fine-grained features of the source code generated in S1-6 vector , sent to the feedforward neural network, and its features are extracted to obtain the fine-grained features X of the source code reduce , X1=ReLU(Linear(x vector ))X2=ReLU(Linear( x 1)); Where X1 is X reduce The result after the linear layer and relu, X2 is the result after X1 passes through the linear layer and relu, linear is the linear layer, relu is the activation function, after these two layers, the vector S vector The dimension will be improved, and then through: X reduce =ReLU(Linear(x2)); S2-2: For each source code graph representation, the input data is G = (V, E, X), where V is the set of nodes, E is the set of edges, and X∈R n*d is the feature matrix of the node, n is the number of nodes, d is the feature dimension of each node, and for each propagation, the feature matrix X is used as input, and we have: in is the degree matrix, is the adjacency matrix of the graph with self-loops added, W∈R d*d is the weight matrix of the graph convolution, d′ is the feature dimension after convolution; the final representation after K times of multi-scale residual graph convolution operation is H k , for H k , before performing a global attention pooling operation, first calculate the attention score α i : in is the final representation of node i after k times of multi-scale residual graph convolutional network, W is the learnable weight matrix, a is the learned attention vector, and the attention score α is obtained i Then, the feature representations of all nodes are weighted and summed according to the attention weights to obtain the heterogeneous code feature h global , the formula is as follows: S2-3: Afterwards, the obtained X reduce With h global Fusion to get h concat , and then use the attention mechanism to h concat Perform update operations. In each training round, the bias and weight will be updated to iterate the fusion parameters that best suit the actual situation: h fused =softmax(Wh concat +b)X reduce +(1-softmax(Wh concat +b))h qlobal ; Where b is the bias of the model and W is the weight.

4. According to claim 1, a smart contract fine-grained vulnerability detection method based on expert knowledge is characterized in that: The step S3 comprises: S3-1: Design expert knowledge for different vulnerabilities, S3-2: Input the smart contract source code into the designed expert knowledge classifier to obtain h exp : h exp =Classifier(h code ); where h code It is the smart contract source code.

5. According to claim 1, a smart contract fine-grained vulnerability detection method based on expert knowledge is characterized in that: The step S4 comprises: S4-1 combines the results of the deep learning classifier with the results of the expert knowledge classifier: in Represents a stack push operation. S4-2: The obtained results are then flattened and passed through a multi-layer perceptron and sigmoid activation function to obtain the vulnerability representation:

Citation Information

Patent Citations

  • Vulnerability detection and model construction method and device for smart contract and storage medium

    CN117807602A

  • Techniques for securing, accessing, and interfacing with enterprise resources

    WO2024091682A1