A smart contract vulnerability detection and location method based on multi-task learning

Through the multi-task learning method, combined with key function extraction and graph convolution network, smart contract vulnerability detection and positioning are realized, solving the shortcomings of existing methods in dealing with dynamic contracts and resource consumption, and improving detection accuracy and efficiency.

CN117668850BActive Publication Date: 2025-03-14UNIV OF ELECTRONICS SCI & TECH OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311088351.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-28
Publication Date
2025-03-14
Estimated Expiration
2043-08-28

AI Technical Summary

Technical Problem

The existing smart contract vulnerability detection methods are difficult to deal with dynamic contract creation and interactive contract creation, and the computing resources and time consume a lot, making it difficult to apply to actual contract auditing and development processes, and the specific function code snippets that lead to the vulnerability cannot be located.

Method used

The smart contract vulnerability detection and positioning method based on multi-task learning is adopted, and the overall vulnerability detection and specific vulnerability positioning of smart contracts are achieved through technologies such as key function extraction, feature extraction, clustering and graph convolution networks.

Benefits of technology

It improves the accuracy and efficiency of smart contract vulnerability detection, can locate specific function code snippets that cause vulnerabilities, and provides guidance to help vulnerability repair.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure SMS_2
    Figure SMS_2
  • Figure SMS_5
    Figure SMS_5
  • Figure SMS_7
    Figure SMS_7
Patent Text Reader

Abstract

The present invention discloses a smart contract vulnerability detection and location method based on multi-task learning, which mines smart contract category features based on clustering and graph embedding algorithms for feature enhancement, and constructs contract-level and function-level vulnerability classifiers through multi-task learning models, so as to quickly locate the problem code fragment while detecting whether there are vulnerabilities in the smart contract. For the smart contract vulnerability detection task, the purpose is to build a contract-level vulnerability binary classifier to determine whether there are vulnerabilities in the smart contract as a whole; for the vulnerability fragment function location task, the purpose is to build a function-level vulnerability binary classifier to determine whether the input function is a function that causes the contract vulnerability. The present invention ensures the division of smart contract function categories and feature enhancement through clustering and graph embedding algorithms, and realizes the accurate identification of reentrant vulnerabilities and timestamp-dependent vulnerabilities and vulnerability location location.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of blockchain smart contract security, and more specifically, relates to a smart contract vulnerability detection and positioning method based on multi-task learning. Background Art

[0002] As an emerging technology, blockchain is widely used in communication, Internet of Things, e-commerce and other fields due to its anti-counterfeiting, tamper-proof and traceable characteristics. As the most dynamic emerging blockchain platform, Ethereum has improved the performance problems of traditional Bitcoin. Among them, smart contracts, as the core function of blockchain 2.0, provide programmability and are automatically executed in the form of code. Its operation process is not subject to third-party intervention. However, this feature also leads to serious security risks once vulnerabilities appear in the smart contract code. When the smart contract is attacked, its execution process cannot be interrupted or blocked, resulting in a large amount of property losses. These vulnerabilities may lead to the theft of user accounts, tampering of transactions, and even paralysis of the entire blockchain system. In order to solve these problems, many scholars and researchers have begun to study vulnerability detection technologies for smart contracts. These technologies can help developers and auditors to discover potential vulnerabilities in a timely manner and provide repair suggestions. At present, smart contract vulnerability detection technology has become one of the important research areas of blockchain security, attracting widespread attention and research.

[0003] Dynamic symbolic execution is a dynamic analysis technology based on symbolic execution. It can track the state of the contract execution process and find vulnerabilities during the execution process. Ye et al. (Paper: Xue, Yinxing, et al. "Cross-contract static analysis for detecting practical reentrancy vulnerabilities in smart contracts." Proceedings of the 35th IEEE / ACM International Conference on Automated Software Engineering. 2020.) proposed a static analysis method Clairvoyance for reentrancy vulnerabilities. By identifying infeasible paths, it implements cross-contract and cross-function smart contract vulnerability detection methods. In order to reduce false positives, this work also systematically summarizes five main path protection techniques (PPT) to support fast and accurate path feasibility checks. Huang et al. (Paper: Huang, Jianjun, et al. "Precise Dynamic Symbolic Execution for Nonuniform Data Access in SmartContracts." IEEE Transactions on Computers 71.7(2021):1551-1563.) Considering the problem of multiple addressing models in smart contracts, they proposed a Dynamic symbolic execution (DSE) method to solve the problem of non-uniform data access in smart contracts, and implemented an integer overflow detector Nova and a multi-transaction vulnerability detector Mtvd. Chen et al. (Paper: Chen, Jiachi, et al. "Defectchecker: Automated smartcontract defect detection by analyzing evm bytecode." IEEE Transactions onSoftware Engineering 48.7(2021):2189-2207.) proposed a smart contract vulnerability detection tool DefectChecker based on symbolic execution, which can detect eight types of smart contract vulnerabilities.

[0004] However, these traditional detection methods have some limitations. For example, they may suffer from high false positive rates or low detection accuracy. They may also have difficulty keeping up with the rapid development of smart contract languages, which may cause outdated analysis techniques to miss new vulnerabilities. In addition, these methods may require a lot of manual work and domain expertise, which makes them inaccessible to developers with limited experience in smart contract development. To address some of the limitations of traditional detection methods, researchers have begun to explore machine learning-based smart contract vulnerability detection methods. These methods use techniques such as graph neural networks, recursive neural networks, gradient boosting decision trees, and differentiable constraints to automatically learn and detect potential vulnerabilities in smart contracts. Gao et al. (Paper: Gao, Zhipeng, et al. "Checking smart contracts with structural code embedding." IEEE Transactions on Software Engineering 47.12 (2020): 2874-2891.) convert smart contract code into a word stream by word embedding, extract the grammatical and semantic features of the code, and then implement vulnerability detection by comparing the smart contract embedding with the smart contract embedding of known vulnerabilities. However, the selection of smart contracts with known vulnerabilities in this work will affect the vulnerability detection results to a certain extent. Zhuang et al. (Paper: Zhuang, Yuan, et al. "Smart Contract Vulnerability Detection using Graph Neural Network." IJCAI. 2020.) proposed using graph neural networks and expert knowledge for smart contract vulnerability detection, projecting the rich control and data flow semantics in the code into the smart contract graph, and proposed a new temporal information propagation network to extract the features of the smart contract graph to achieve vulnerability detection. Liu (Paper: Liu Z, Qian P, Wang X, et al. Combining graph neural networks with expert knowledge for smart contract vulnerability detection [J]. IEEE Transactions on Knowledge and Data Engineering, 2021.) et al. On this basis, they defined several expert knowledge models about smart contract vulnerabilities, and further improved the accuracy of vulnerability detection by combining the features of the smart contract graph with the features of the expert knowledge model.

[0005] In general, the existing detection methods have the following problems:

[0006] (1) Many static analysis methods have difficulty handling situations where contracts are dynamically created and interact with each other, and thus may miss potential vulnerabilities.

[0007] (2) Many dynamic analysis methods require a lot of computing resources and time, making them difficult to apply in actual contract auditing and development processes.

[0008] (3) Existing machine learning models focus more on mining the syntactic and semantic features of smart contract codes, ignoring the strong correlation between the frequency of occurrence of different vulnerabilities and contract types.

[0009] (4) Most current vulnerability detection methods can only determine whether there are vulnerabilities in smart contracts, but cannot locate the specific fragments that cause the vulnerabilities and provide guidance for vulnerability repair. Summary of the invention

[0010] The technical problem to be solved by the present invention is to realize the method of judging whether there are vulnerabilities in the smart contract as a whole, and locating the function code fragment that specifically causes the vulnerability through two subtasks: smart contract vulnerability classification and key function vulnerability classification.

[0011] The technical solution adopted by the present invention to solve the above technical problems is a multi-task-based smart contract vulnerability detection and positioning method, comprising the following steps:

[0012] 1) Key function extraction steps

[0013] Extract the functions related to the vulnerability from the smart contract as key functions according to predefined rules, and label whether the key functions are the source of the vulnerability;

[0014] 2) Extract key function features based on key functions;

[0015] 3) Extract smart contract features based on smart contracts;

[0016] 4) Clustering step based on contract function categories:

[0017] First, unsupervised clustering is performed on smart contracts with similar functions to form different smart contract clusters. The key functions corresponding to the smart contracts in each smart contract cluster also belong to different function clusters. The similarity values ​​between two smart contracts in a smart contract cluster are calculated. After obtaining the similarity values ​​between all smart contracts, a similarity threshold is set to regard two smart contracts with a similarity greater than the similarity threshold as having a connection relationship. Then, each smart contract cluster is converted into a smart contract subgraph with smart contracts as nodes and the connection relationship between smart contracts as edges. Then, each function cluster is converted into a key function subgraph with key functions as nodes and the connection relationship between smart contracts as edges.

[0018] 5) Multi-task sharing steps:

[0019] Then, the features of the smart contract subgraph and the key function subgraph are extracted through the graph convolutional network, and the features of the smart contract subgraph and the key function subgraph are processed by maximum pooling respectively to obtain the smart contract subgraph representation and the key function subgraph representation; the key function features and the key function subgraph representation are concatenated as the input of the vulnerability detection model, and the smart contract features and the smart contract subgraph representation are concatenated as the input of the vulnerability location model;

[0020] 6) Result output steps:

[0021] The vulnerability detection model is a binary classifier based on the convolutional neural network (CNN) that has been trained. It outputs a binary classification result of whether the currently detected smart contract as a whole has a vulnerability. The vulnerability location model is a binary classifier based on the convolutional neural network (CNN) that has been trained. It outputs a binary classification result of whether the currently detected key function has a vulnerability, thereby obtaining the code snippet location of the function that causes the vulnerability in the source code.

[0022] Specifically, the specific steps for extracting key function features are as follows: after extracting the key functions, generate a corresponding word vector for each key function; then input the word vector into the feature extractor of the convolutional neural network CNN, and the CNN feature extractor uses convolution kernels of different sizes to slide on the word vector, thereby aggregating sequence local feature vectors of different lengths, and finally concatenates all sequence local features into a feature sequence and inputs it into the Transformer encoding layer, and the Transformer encoding layer outputs the encoded text sequence representation as the key function feature.

[0023] The specific steps for extracting smart contract features are as follows: obtain the calling relationship between key functions in the smart contract, use the key functions in the smart contract as nodes, and convert the smart contract source code into a smart contract graph with the calling relationship representation between key functions as edges; obtain edge vectors based on one-hot encoding for the edges in the smart contract graph; use Word2vec to encode the nodes of the smart contract graph to obtain node features; then use the time-series message propagation network TMP to update the node features according to the time sequence of the edge vectors, and finally obtain the smart contract features by adding and aggregating the features of all nodes at the final moment.

[0024] The present invention first matches the key functions according to expert knowledge, labels whether the key functions are the source of vulnerabilities, extracts features from the key functions, and obtains the semantic features and sequence dependencies of the key functions. When extracting features from smart contracts, this paper constructs a smart contract graph based on the calling relationship between key functions and variables, which not only retains the code syntax calling features, but also reduces the impact of irrelevant functions on smart contract feature extraction. In addition, this paper also notes the correlation between the occurrence frequency of different vulnerabilities and contract types, clusters smart contracts into subgraphs of different functional categories through a code fragment-based sign sequence method, and extracts the features of each functional category subgraph. In the final smart contract vulnerability classification, the model, on the basis of traditional code semantic syntax features, also considers the functional category features of each smart contract implementation, further improving the accuracy of the vulnerability classification results. Similarly, when classifying vulnerabilities for key functions, the functional category features of the smart contract to which they belong are also added to the key functions to enhance the input data features, thereby improving the discrimination effect of the classifier.

[0025] Beneficial effects of the present invention:

[0026] (1) Based on predefined rule matching, the smart contract graph is constructed by extracting key functions to improve the overall feature embedding effect of the smart contract. On the one hand, the semantic features of key functions related to vulnerabilities are retained, reducing the impact of irrelevant functions on the overall feature mining of smart contracts; further, by vectorizing key functions using word2vec and Transformer methods, rich code semantic features can be mined.

[0027] (2) Considering the correlation between the occurrence frequency of different vulnerabilities and contract types, data enhancement is performed by mining the functional features of smart contracts to improve classification accuracy. Compared with existing research work, this paper not only considers the semantic and grammatical features of smart contract codes, but also takes into account the functional features of smart contracts, and conducts multi-dimensional and comprehensive feature modeling.

[0028] (3) Construct a multi-task learning model to detect and locate smart contract vulnerabilities through two sub-tasks: smart contract vulnerability classification and key function vulnerability classification. It can not only determine whether there are vulnerabilities in the smart contract, but also locate the specific function code snippet that causes the vulnerability, generate explainable vulnerability detection results, and provide certain guidance for smart contract vulnerability repair. DETAILED DESCRIPTION

[0029] For the convenience of description, the relevant professional terms appearing in the specific implementation methods are first explained:

[0030] GCN: Graph Convolutional Neural Network

[0031] Self-Attention: Self-Attention Mechanism

[0032] CNN: Convolutional Neural Network

[0033] The blockchain smart contract scenario in which the present invention is applied is: when the smart contract developer or user puts the smart contract on the chain or calls the smart contract, he or she cannot determine whether the contract is safe and has no loopholes, which may cause security problems to the user's account. Therefore, the present invention can provide users with contract vulnerability detection and vulnerability location services, and protect the account security of blockchain smart contract users.

[0034] The present invention considers the following factors that affect the performance of smart contract vulnerability detection and vulnerability location:

[0035] First, many static analysis methods have difficulty handling situations where contracts are dynamically created and interact with each other, and thus potential vulnerabilities may be missed. Second, many dynamic analysis methods require a lot of computing resources and time, making them difficult to apply in actual contract auditing and development processes. Furthermore, existing machine learning models focus more on mining the grammatical and semantic features of smart contract code, ignoring the strong correlation between the frequency of occurrence of different vulnerabilities and contract types. In addition, most of the current vulnerability detection methods can only determine whether there are vulnerabilities in smart contracts, but cannot locate the specific fragments that cause the vulnerabilities, and provide guidance for vulnerability repair.

[0036] Based on the above points, the present invention proposes a multi-task-based smart contract vulnerability detection and location method. Through the two subtasks of smart contract vulnerability classification and key function vulnerability classification, the judgment of whether there are vulnerabilities in the smart contract as a whole and the location of the function code fragments that specifically cause the vulnerabilities are realized. This paper first matches the key functions based on expert knowledge, and labels whether the key functions are the source of the vulnerability. Feature embedding is performed based on word2vec and Transformer methods to extract the semantic features and sequence dependencies of the key functions. When extracting features from smart contracts, this paper constructs a smart contract graph based on the call relationship between key functions and variables, which not only retains the code syntax call features, but also reduces the impact of irrelevant functions on smart contract feature extraction. In addition, this paper also notes the correlation between the occurrence frequency of different vulnerabilities and contract types. The smart contract is clustered into subgraphs of different functional categories through the code fragment-based sign sequence method, and the GCN and Self-Attention methods are used to extract the features of each functional category subgraph. In the final smart contract vulnerability classification, the model not only considers the functional category features implemented by each smart contract on the basis of the traditional code semantic syntax features, but also further improves the accuracy of the vulnerability classification results. Similarly, when classifying vulnerabilities in key functions, the functional category characteristics of the smart contract to which they belong are also attached to the key functions to enhance the input data characteristics, thereby improving the discrimination effect of the classifier.

[0037] A smart contract vulnerability detection and location method based on multi-task learning is described in detail, which specifically includes the following steps:

[0038] (1) Key function extraction and feature extraction layer (1.1) Key function extraction

[0039] For smart contracts in the data set, the key function extraction layer extracts key functions related to vulnerabilities according to predefined rules, and labels whether the key functions are the source of the vulnerabilities. Since in smart contracts, there are often only a few key functions involving call.value and block.timestamp that cause vulnerabilities, extracting key functions can reduce the impact of other ordinary functions in smart contracts on subsequent feature extraction. For example, first match the key variable block.timestamp according to the predefined rule model. Since the assignment of block.timestamp causes randomSeed to be marked as a key variable, check whether there is a return function or other errors thrown in the function. If so, the corresponding function will be marked. After the marking is completed, the function containing the key variable is the key function.

[0040] (1.2) Key function feature extraction

[0041] After extracting the key functions, we take each key function as a sequence for feature extraction. First, we use the word2vec method to generate the word vector corresponding to each word in the key function, and then use the CNN+Transformer method to generate the feature extraction of the key function to better capture the local features of the sequence. For the key function sequence, after word2vec word embedding, it is expressed as Where n is the sequence length and d is the word vector dimension. The CNN feature extractor can slide convolution kernels of different sizes on the input sequence to aggregate local features of sequences of different lengths. This paper uses M filters of different sizes for convolution operations. Each filter has R convolution kernels of size h×d. The feature vector obtained by the mth filter is expressed as:

[0042]

[0043] in, represents the weight matrix of the mth filter in the convolution operation, b is the bias, f(·) represents the activation function, max(·) represents the maximum pooling, Indicates the length is h m Function word sequence features, h m represents the convolution kernel dimension of the mth filter. Finally, all the feature vectors of the filters are concatenated into a complete sequence C = [c1, c2, ..., c m ] as the input of Transformer.

[0044] The Transformer encoding layer consists of a multi-head self-attention mechanism (Multi-Head Attention) and a feedforward neural network (Feedforward Neural Network). The input vector is first encoded through a self-attention layer, and then processed through a series of multi-head attention layers and feedforward networks to finally obtain the encoded text sequence representation. Specifically, the self-attention layer represents the importance of each input vector in the sequence by calculating the attention weights between the input feature vectors. The multi-head attention layer and feedforward network further process these encoded vectors to obtain a more semantic text representation. As shown below:

[0045]

[0046] Among them, Q, K, and V represent the query vector, key vector, and value vector respectively. k is the vector dimension. The self-attention mechanism can be implemented by multiple stacking to learn information at different abstract levels. The new sequence generated by the input sequence C through multi-head self-attention is represented as Through the feedforward neural network, a nonlinear transformation is applied to each token in the sequence to obtain the key function feature E f for:

[0047]

[0048] Among them, FFN represents the feedforward neural network processing process, W1, b1, W2 and b2 are learnable weight matrices and bias vectors.

[0049] (1.3) Smart Contract Feature Extraction

[0050] By converting the smart contract source code into a graph, the characteristics of the smart contract are obtained based on the time-series message propagation network TMP network. First, the calling relationship between the key functions in the smart contract is obtained, and the key functions in the smart contract are used as nodes. The calling relationship representation between the key functions is used as the edge to convert the smart contract source code into a smart contract graph; the edges in the smart contract graph are encoded based on the one-hot encoding to obtain the edge vector; Word2vec is used to encode the nodes of the smart contract graph to obtain the node features; then the TMP network is used to update the node features according to the time sequence of the edge vector, and finally the features of all nodes at the final moment are added and aggregated to obtain the smart contract features. Specifically:

[0051] First, after processing (1.1) and (1.2), the key functions in the smart contract are retained and used as nodes. The key function feature is E f . The function calls and variable calls between nodes are used as edges to construct the smart contract graph. The edge types can be divided into four categories: control-flow edge, data-flow edge, forward edge, and fallback edge. The edge vector is obtained based on the one-hot method. For the constructed smart contract graph, the feature E of each node is f Defined as the initial state feature of the node, in the TMP network, node information is transmitted in the order of edges. At time step t, the node information passes through edge e k It is passed to its end node. It is worth noting that the information m k is based on the initial node e k The hidden state of Perform the calculation:

[0052]

[0053] m k =W k x k +b k

[0054] in, Represents the splicing symbol, x k is the intermediate vector, W k and b k is a network parameter. After receiving the information feature, the end node of the edge can be connected through m k and its previous hidden state to update the current hidden state h ek :

[0055]

[0056]

[0057] Among them, U, Z and R are matrices, b3 and b4 are bias vectors.

[0058] Finally, we get the feature h of each node at the final moment. i ′ , for a smart contract graph containing |V| nodes, the smart contract feature E obtained by node feature aggregation c for:

[0059]

[0060] (2) Clustering steps based on contract function categories

[0061] Unsupervised clustering is performed on typical smart contracts and typical risk functions with similar functions, and smart contracts and key functions are divided into different functional categories. The smart contracts in the dataset are clustered using the identification sequence method to form different smart contract clusters. Naturally, the key functions corresponding to each smart contract also belong to different function clusters. At the same time, in order to subsequently mine the feature embedding representation corresponding to each cluster, this paper generates edge connection relationships for the smart contracts contained in the same cluster, and defines that if the semantic grammatical similarity between two smart contracts exceeds 70%, an edge is generated between the two smart contract nodes, thereby converting each cluster into a subgraph. Similarly, the key functions belonging to different smart contracts can also form edges based on the connection relationship between each smart contract, thereby converting them into key function subgraphs.

[0062] (3) Multi-task sharing steps

[0063] For the subgraphs of smart contracts and key functions of different functional categories obtained by clustering, this step aims to mine the typical features of each type of functional subgraph, splice them with the features of the original input data, perform feature enhancement, and improve the accuracy of the final classification. In the multi-task learning sharing layer, the present invention extracts the pattern features of each type of typical smart contract and risk function through the graph embedding method, and learns the correlation information between different pattern features through the attention mechanism. First, the number of categories obtained by clustering smart contracts and key functions is defined as n, and the various subgraphs of smart contracts are defined as Similarly, various subgraphs of key functions are defined as The various subgraph representations of smart contracts obtained by GCN and maximum pooling are defined as Similarly, the various subgraph representations of key functions are defined as We can calculate it as follows:

[0064]

[0065] in I is the unit diagonal matrix of the adjacency matrix A of the self-loops in each node, and G represents the specific input subgraph, S represents the generated subgraph representation, and W is a trainable weight matrix. However, in actual scenarios, a smart contract may contain functions that implement multiple functions. For example, a game-type smart contract may also involve the exchange and distribution of virtual currency. Therefore, the present invention proposes to use the self-attention mechanism to learn the potential connections between the features of different functional subgraph patterns, and to exchange information between different types of smart contracts and key function subgraphs by generating attention weight coefficients. For the smart contract and key function subgraph representations, the new representations obtained by the self-attention mechanism are defined as and

[0066] (4) Result output step

[0067] This step defines two classification tasks, and improves the overall performance of the model by sharing the training information in the two tasks. Task 1 is to train a CNN-based binary classifier to detect whether there are vulnerabilities in the smart contract as a whole; Task 2 is also to train a CNN-based binary classifier to detect whether there are vulnerabilities in the key functions of the smart contract. The multi-task-based training method can simultaneously detect whether there are vulnerabilities in the smart contract and locate the specific function code snippet that causes the vulnerability. Before performing specific classification tasks, first concatenate the key function features E learned in the feature embedding layer f , Smart Contract Features E c , and its key function subgraph representation Smart Contract Subgraph Representation As the whole input. For the smart contract detection task, extract the features related to the smart contract in the input, that is, As the input of the CNN classifier in the smart contract detection task. The output of the classifier is defined as y 1 For the real sample labels, we use the cross entropy loss function to train the model, namely:

[0068]

[0069] For the vulnerability function location task, the features related to the key functions in the input are extracted, namely As the input of the CNN classifier in the vulnerability function location task. The output of the classifier is defined as y 2 is the real sample label, and the cross entropy loss function is also used to train the model:

[0070]

[0071] The proposed model uses the same dataset to learn and obtain features. In addition, the two tasks share information and optimize parameters through mutual adjustment of loss functions in multi-task learning, and then the loss function is fed back to each subtask to improve model performance. The calculation method of the shared loss function is as follows:

[0072]

[0073] Although specific illustrative embodiments of the present invention are described above to facilitate those skilled in the art to understand the present invention, it should be apparent that the present invention is not limited to the scope of the specific embodiments.

Claims

1. A smart contract vulnerability detection and location method based on multi-task learning, characterized in that: The following steps are involved: 1) Key function extraction steps Extract the functions related to the vulnerability from the smart contract as key functions according to predefined rules, and label whether the key functions are the source of the vulnerability; 2) Extract key function features based on key functions; 3) Extract smart contract features based on smart contracts; 4) Clustering step based on contract function categories: First, unsupervised clustering is performed on smart contracts with similar functions to form different smart contract clusters. The key functions corresponding to the smart contracts in each smart contract cluster also belong to different function clusters. Calculate the similarity between any two smart contracts in a smart contract cluster; After obtaining the similarity values ​​between all smart contracts, by setting a similarity threshold, two smart contracts with a similarity greater than the threshold are considered to have a connection relationship; then, each smart contract cluster is converted into a smart contract subgraph with smart contracts as nodes and the connection relationship between smart contracts as edges; Then, using key functions as points and the connections between smart contracts as edges, each function cluster is converted into a key function subgraph; 5) Multi-task sharing steps: Then, the features of the smart contract subgraph and the key function subgraph are extracted through the graph convolutional network, and the features of the smart contract subgraph and the key function subgraph are processed by maximum pooling respectively to obtain the smart contract subgraph representation and the key function subgraph representation; the key function features and the key function subgraph representation are concatenated as the input of the vulnerability detection model, and the smart contract features and the smart contract subgraph representation are concatenated as the input of the vulnerability location model; 6) Result output steps: The vulnerability detection model is a binary classifier based on the convolutional neural network (CNN) that has been trained. It outputs a binary classification result of whether the currently detected smart contract as a whole has a vulnerability. The vulnerability location model is a binary classifier based on the convolutional neural network (CNN) that has been trained. It outputs a binary classification result of whether the currently detected key function has a vulnerability, thereby obtaining the code snippet location of the function that causes the vulnerability in the source code.

2. The method according to claim 1, characterized in that: The specific steps of extracting key function features are as follows: after extracting the key functions, generate a corresponding word vector for each key function; then input the word vector into the feature extractor of the convolutional neural network CNN. The CNN feature extractor uses convolution kernels of different sizes to slide on the word vector, thereby aggregating sequence local feature vectors of different lengths. Finally, all sequence local features are concatenated into a feature sequence and input into the Transformer encoding layer. The Transformer encoding layer outputs the encoded text sequence representation as the key function feature.

3. The method according to claim 1, characterized in that: The specific steps of extracting smart contract features are: obtaining the calling relationship between key functions in the smart contract, taking the key functions in the smart contract as nodes, and converting the smart contract source code into a smart contract graph without using the calling relationship representation between key functions as edges; obtaining edge vectors based on one-hot encoding of the edges in the smart contract graph; using Word2vec to encode the nodes of the smart contract graph to obtain node features; Then use the time message propagation network TMP to update the node features according to the timing of the edge vector, and finally obtain the smart contract features by adding and aggregating the features of all nodes at the final moment.

4. The method according to claim 1, characterized in that: The vulnerability detection model and the vulnerability location model both use the cross entropy loss function to constrain the training process during training, and the two models share information and optimize parameters by sharing the loss function during the training process, sharing the loss function Loss: in, is the cross entropy loss function of the vulnerability detection model during training, This is the cross entropy loss function of the vulnerability localization model during training.