A multi-platform blockchain smart contract classification method, system and electronic device
By obtaining and counting the transaction and code characteristics of smart contracts, and using the XGBoost model for classification, the problem of smart contract classification that cannot be applied to multiple platforms is solved, and the multi-platform classification and function identification of smart contracts is realized, reducing the risk of fraud , and improve classification accuracy and scalability.
Patent Information
- Application Number
- CN202110452238.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-26
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2041-04-26
AI Technical Summary
The existing smart contract classification methods cannot be applied to multiple blockchain platforms and cannot be extended to other platforms for classification.
By obtaining smart contracts on different platforms, obtaining their category tags and on-chain data, counting transaction data and code features, combining them into feature vectors, inputting them into XGBoost model for training, and generating a classification model for classification of smart contracts.
It realizes multi-platform classification of smart contracts, reduces the risk of users being fraudulent, improves classification accuracy, and expands to multiple blockchain platforms, with stronger versatility and scalability.
Smart Images

Figure CN113486915B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of classification methods for blockchain smart contracts, and in particular to a multi-platform-based blockchain smart contract classification method, system and electronic equipment. Background Art
[0002] At present, blockchain technology is a new distributed infrastructure and computing paradigm that uses block chain data structures to verify and store data, consensus algorithms to update data and ensure data consistency, cryptography to ensure the security of data transmission and access, and smart contracts composed of automated script code to program and operate data. Blockchain technology is a peer-to-peer distributed ledger technology based on cryptographic algorithms. Since early blockchain platforms did not support Turing-complete programming paradigms, the development of blockchain technology was greatly restricted. Therefore, most of the subsequent blockchain platforms support Turing-complete smart contracts to meet the needs of various business scenarios. By introducing smart contracts and programming logic into the blockchain system, people can put customized execution logic on the blockchain for operation, rather than just simple transaction transfers. With the advent of smart contracts, the application of blockchain systems has become richer, and its practicality has entered a new stage. Smart contracts that can customize program functions make blockchain systems more powerful and more flexible. The programming ecology and tool chains of smart contracts on different blockchain platforms are also different, such as supporting different programming languages, using different compilers and virtual machines, etc.; this can meet the development needs of developers with different programming preferences or different application scenarios. The code formats of smart contracts deployed on the chain are also different.
[0003] At present, the identification framework proposed by it cannot be extended to other blockchain platforms to classify smart contracts because the instruction sets of different platforms are not the same. Therefore, this solution cannot be applied to the classification of smart contracts on other platforms. Summary of the invention
[0004] The present invention provides a multi-platform blockchain smart contract classification method, system and electronic device, aiming to solve the problem that the existing smart contract classification method cannot be applied to multi-platform classification.
[0005] According to an embodiment of the present application, a multi-platform blockchain smart contract classification method is provided, comprising the following steps:
[0006] Step S1: Obtain multiple smart contracts on different platforms and obtain the category label of each smart contract; Step S2: For each smart contract, obtain the on-chain data on the corresponding platform, including code and transaction data; Step S3: Count the transaction data and code in all smart contracts to obtain the corresponding transaction feature vector and code feature vector; Step S4: Merge the transaction feature vector and the code feature vector to obtain the final feature vector, input the category label and the final feature vector into the XGBoost model to obtain a classification model; and Step S5: Classify the smart contracts based on the classification model obtained through training.
[0007] Preferably, step S2 specifically includes: step S21: deploying a node on each blockchain platform to synchronize the on-chain data; and step S22: preprocessing and screening the on-chain data to obtain the transaction data and codes of all smart contracts.
[0008] Preferably, the above step S3 specifically includes: step S31: counting the transaction data in all smart contracts, dividing the types of transaction data into multiple features, obtaining a transaction feature matrix, and converting the transaction feature matrix into a transaction feature vector;
[0009] Step S32: Collect the instruction set of the virtual machine of each blockchain platform and establish a smart contract instruction library for each platform; and Step S33: Count the codes in all smart contracts, combine with the instruction library, count the number of times each instruction appears in each smart contract, establish a code feature matrix, and convert the code feature matrix into a code feature vector.
[0010] Preferably, in step S4, the XGBoost model is trained based on a ratio mode of 2:8 between the training set and the test set.
[0011] Preferably, step S5 specifically includes: step S51: based on the classification model obtained through training, inputting a smart contract on any platform; step S52: the classification model outputs a multidimensional vector, the dimension of the multidimensional vector is the same as the number of category labels; and step S53: obtaining the classification result of the smart contract based on the multidimensional vector.
[0012] The present invention also provides a multi-platform blockchain smart contract classification system, including: a contract acquisition unit, used to acquire multiple smart contracts on different platforms, and obtain the category label of each smart contract; a data acquisition unit, used to acquire the on-chain data on the corresponding platform for each smart contract, including code and transaction data; a vector calculation unit, used to count the transaction data and code in all smart contracts, and obtain the corresponding transaction feature vector and code feature vector; a model training unit, used to merge the transaction feature vector and the code feature vector to obtain the final feature vector, and input the category label and the final feature vector into the XGBoost model to obtain a classification model; and a contract classification unit, used to classify the smart contracts based on the classification model obtained through training.
[0013] Preferably, the data acquisition unit also includes: a node deployment unit, which is used to deploy a node on each blockchain platform to synchronize the on-chain data; and a data screening unit, which is used to pre-process and screen the on-chain data to obtain the transaction data and code of all smart contracts.
[0014] Preferably, the vector calculation unit also includes: a transaction vector calculation unit, which is used to count the transaction data in all smart contracts, divide the types of transaction data into multiple features, obtain a transaction feature matrix, and convert the transaction feature matrix into a transaction feature vector; an instruction library establishment unit, which is used to collect the instruction set of the virtual machine of each blockchain platform and establish a smart contract instruction library for each platform; and a code vector calculation unit, which is used to count the codes in all smart contracts, combine with the instruction library, count the number of times each instruction appears in each smart contract, and establish a code feature matrix, which is converted into a code feature vector.
[0015] The present invention also provides an electronic device, comprising a memory and a processor, wherein a computer program is stored in the memory, and the computer program is configured to execute any of the above-mentioned multi-platform blockchain smart contract classification methods when running; the processor is configured to execute any of the above-mentioned multi-platform blockchain smart contract classification methods through the computer program.
[0016] The multi-platform blockchain smart contract classification method, system and electronic device provided by the present invention have the following beneficial effects:
[0017] By obtaining smart contracts and corresponding category labels on multiple platforms, and obtaining code and transaction data for smart contracts, converting them into transaction feature vectors and code feature vectors and merging them, the final feature vector is obtained, and it is input into the XGBoost model with the category label for training to obtain a classification model. Based on the classification model, smart contracts on different platforms can be classified. This method is applicable to the multi-classification model of smart contracts on multiple blockchain platforms, which can be used for the classification and function identification of smart contracts, and the real purpose of smart contracts is informed to users, reducing the risk of users being defrauded by contracts. At the same time, this method extracts common transaction features applicable to smart contracts on different blockchain platforms, establishes smart contract instruction libraries for different blockchain platforms, and finally extracts the code features of the contract for classification and identification of smart contracts, making full use of the transaction and code features of a smart contract, improving the accuracy of the smart contract multi-classification problem, and can be extended to multiple platforms. Furthermore, the multi-classification method of smart contracts proposed by this method is not specific to a certain blockchain platform, and the proposed transaction-related features can be collected on most mainstream blockchain platforms. At the same time, by gradually establishing smart contract instruction libraries for different platforms, it can be used for smart contract classification on more blockchain platforms. The scheme proposed by this method is more versatile and more scalable. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying any creative work.
[0019] Figure 1 It is a flowchart of the multi-platform blockchain smart contract classification method provided by the first embodiment of the present invention.
[0020] Figure 2 It is a flowchart of step S2 in the multi-platform blockchain smart contract classification method provided by the first embodiment of the present invention.
[0021] Figure 3 It is a flowchart of step S3 in the multi-platform blockchain smart contract classification method provided by the first embodiment of the present invention.
[0022] Figure 4 It is a flowchart of step S5 in the multi-platform blockchain smart contract classification method provided by the first embodiment of the present invention.
[0023] Figure 5 It is a module diagram of a multi-platform blockchain smart contract classification system provided by the second embodiment of the present invention.
[0024] Figure 6 It is a module diagram of a data acquisition unit in a multi-platform blockchain smart contract classification system provided by the second embodiment of the present invention.
[0025] Figure 7 It is a module diagram of a vector computing unit in a multi-platform blockchain smart contract classification system provided by the second embodiment of the present invention.
[0026] Figure 8 It is a module diagram of an electronic device provided by the third embodiment of the present invention.
[0027] Explanation of numbers: 1. Contract acquisition unit; 2. Data acquisition unit; 3. Vector calculation unit; 4. Model training unit; 5. Contract classification unit; 21. Node deployment unit; 22. Data screening unit; 31. Transaction vector calculation unit; 32. Instruction library establishment unit; 33. Code vector calculation unit; 10. Memory; 20. Processor. DETAILED DESCRIPTION
[0028] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are 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.
[0029] It should also be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0030] It should be further understood that the term "and / or" used in the present description and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
[0031] See also Figure 1 The first embodiment of the present invention discloses a multi-platform blockchain smart contract classification method, comprising the following steps:
[0032] Step S1: Obtain multiple smart contracts on different platforms and obtain the category label of each smart contract.
[0033] Step S2: For each smart contract, obtain the on-chain data on the corresponding platform, including code and transaction data.
[0034] Step S3: Count the transaction data and codes in all smart contracts to obtain the corresponding transaction feature vectors and code feature vectors.
[0035] Step S4: Merge the transaction feature vector and the code feature vector to obtain the final feature vector, input the category label and the final feature vector into the XGBoost model to obtain a classification model.
[0036] Step S5: Classify the smart contracts based on the trained classification model.
[0037] It can be understood that in step S1, contract data with labels are crawled from three websites: DappReview, Dapp, and DappRadar. The data includes the platform corresponding to each contract, its on-chain address, and the category label of the contract, which mainly includes six categories, such as division by transaction field.
[0038] It can be understood that in step S2, transaction data of corresponding codes are collected on different platforms of the blockchain, so that multiple data on multiple platforms are used as the basis for subsequent classification and identification, which includes the characteristics of multiple platforms.
[0039] It can be understood that in step S3, the collected transaction data is divided into multiple features according to the data type. For example, the transaction data includes the contract balance, the transaction transfer amount, the transfer amount, the number of transactions, etc., and the following n features of each contract are calculated, that is, the vector X = [x1, x2, x3, ..., xn]. The semantics of these 18 features are applicable to different blockchain platforms and can be extracted and calculated from the transaction data. Similarly, in the collected code, each code corresponds to an instruction. Based on the number of times the instruction appears in the contract, a vector Y = [y1, y2, y3, ..., ym] is established, where ym represents the number of times the mth instruction appears in the contract, and the size of m depends on the platform's virtual machine design. For example, the virtual machine is designed with 147 instructions, and m = 147 at this time.
[0040] It can be understood that in step S4, the transaction feature vector X and the code feature vector Y are merged, that is, Z = [x1, x2, x3.......xn, y1, y2, y3......., ym], and finally Z and the labels collected in step S1 are input into the XGBoost model, and the training is performed in a ratio mode of 2:8 between the training set and the test set. Finally, a smart contract multi-classification model is obtained, and the classification model can input smart contracts from multiple different platforms and perform identification and classification.
[0041] It can be understood that by obtaining smart contracts and corresponding category labels on multiple platforms, and obtaining code and transaction data for smart contracts, converting them into transaction feature vectors and code feature vectors and merging them, the final feature vector is obtained, and it is input into the XGBoost model with the category label for training to obtain a classification model. Based on the classification model, smart contracts on different platforms can be classified. This method is applicable to the multi-classification model of smart contracts on multiple blockchain platforms, which can be used for the classification and functional identification of smart contracts, and the real purpose of smart contracts is informed to users, reducing the risk of users being defrauded by contracts. At the same time, the method extracts common transaction features applicable to smart contracts on different blockchain platforms, establishes smart contract instruction libraries for different blockchain platforms, and finally extracts the code features of the contract for classification and identification of smart contracts, making full use of the transaction and code features of a smart contract, improving the accuracy of the smart contract multi-classification problem, and can be extended to multiple platforms. Further, the multi-classification method of smart contracts proposed by this method is not specific to a certain blockchain platform, and the proposed transaction-related features can be collected on most mainstream blockchain platforms. At the same time, by gradually establishing smart contract instruction libraries for different platforms, it can be used for smart contract classification on more blockchain platforms. The scheme proposed by this method is more versatile and more scalable.
[0042] See also Figure 2 , step S2 specifically includes:
[0043] Step S21: Deploy a node on each blockchain platform to synchronize the data on the chain.
[0044] Step S22: Preprocess and filter the on-chain data to obtain the transaction data and codes of all smart contracts.
[0045] It can be understood that in step S21, a node is deployed on the platform of each blockchain, and the node is used to synchronize on-chain data, mainly including on-chain data such as blocks, transactions and codes.
[0046] It can be understood that the on-chain data obtained in step S21 contains data of various different contracts. In order to simplify the calculation, step S22 mainly filters the transaction data and codes that meet the category labels in step S1. That is, the category labels obtained in step S1 determine the condition range of step S22 data filtering.
[0047] See also Figure 3 , the above step S3 specifically includes:
[0048] Step S31: Count the transaction data in all smart contracts, divide the types of transaction data into multiple features, obtain a transaction feature matrix, and convert the transaction feature matrix into a transaction feature vector.
[0049] Step S32: Collect the instruction set of the virtual machine of each blockchain platform and establish the smart contract instruction library of each platform.
[0050] Step S33: Count the codes in all smart contracts, combine with the instruction library, count the number of times each instruction appears in each smart contract, establish a code feature matrix, and convert the code feature matrix into a code feature vector.
[0051] It can be understood that in step S31, the collected contract-related transaction data calculates the following 18 features for each contract, namely, vector X=[x1, x2, x3, . . . , x18]. The semantics of these 18 features are applicable to different blockchain platforms and can be extracted and calculated from the transaction data. In this embodiment, the features of the transaction data mainly include: Feature 1: The balance of the contract. Feature 2: The amount transferred in from the external transaction of the contract. Feature 3: The amount transferred in from the internal transaction of the contract. Feature 4: The amount transferred out from the internal transaction of the contract. Feature 5: The number of contract transactions. Feature 6: The number of transfer-in transactions from the external transaction of the contract. Feature 7: The number of transfer-in transactions from the internal transaction of the contract. Feature 8: The number of transfer-out transactions from the internal transaction of the contract. Feature 9: The number of addresses that have generated transfer-in transactions with the contract in the external transaction of the contract. Feature 10: The number of addresses that have generated transfer-in transactions with the contract in the internal transaction of the contract. Feature 11: The number of addresses that have generated transfer-out transactions with the contract in the internal transaction of the contract. Feature 12: The average transaction amount per transaction of the contract. Feature 13: The average amount of transfer-in in the contract's internal transactions. Feature 14: The average amount of transfer-out in the contract's internal transactions. Feature 15: The average amount of transfer-in in the contract's external transactions. Feature 16: The variance of the amount of transfer-in in the contract's internal transactions. Feature 17: The variance of the amount of transfer-out in the contract's internal transactions. Feature 18: The variance of the amount of transfer-in in the contract's external transactions.
[0052] It can be understood that in step S31, each feature corresponds to a feature matrix, and the feature matrices of all transaction data are converted into feature vectors to obtain vector X.
[0053] It can be understood that in step S32, each code has a corresponding instruction set. According to the virtual machine design and relevant white papers of each blockchain platform, the instruction set of each blockchain platform virtual machine is collected, and a smart contract instruction library of each platform is established. The instruction library includes all instructions that may be used by the virtual machine during operation.
[0054] It can be understood that in step S33, the collected contract-related code data is processed, combined with the instruction library established in step S32, the number of times each instruction appears in each smart contract is counted, and the code feature vector is obtained.
[0055] See also Figure 4, step S5 specifically includes:
[0056] Step S51: Based on the classification model obtained through training, input the smart contract on any platform.
[0057] Step S52: The classification model outputs a multi-dimensional vector, the dimension of which is the same as the number of category labels.
[0058] Step S53: Obtain the classification result of the smart contract based on the multi-dimensional vector.
[0059] It can be understood that in step S51, in the classification model after training, smart contracts on any platform can be used as input for identification and classification.
[0060] It can be understood that in step S52, the output multidimensional vector is determined by the number of category labels preset in step S1. In the present embodiment, the multidimensional vector is a six-dimensional vector, and the value of each dimension is 0 or 1. If the value is 1, it means that the category represented by the dimension is the most likely category of the contract to be detected.
[0061] See also Figure 5 The second embodiment of the present invention provides a multi-platform blockchain smart contract classification system, which adopts a multi-platform blockchain smart contract classification method provided in the first embodiment, and includes:
[0062] The contract acquisition unit 1 is used to acquire multiple smart contracts on different platforms and acquire a category label of each smart contract.
[0063] The data acquisition unit 2 is used to acquire the on-chain data on the corresponding platform for each smart contract, including code and transaction data.
[0064] The vector calculation unit 3 is used to count the transaction data and codes in all smart contracts to obtain the corresponding transaction feature vectors and code feature vectors.
[0065] The model training unit 4 is used to merge the transaction feature vector and the code feature vector to obtain a final feature vector, and input the category label and the final feature vector into the XGBoost model to obtain a classification model.
[0066] The contract classification unit 5 is used to classify the smart contracts based on the classification model obtained through training.
[0067] See also Figure 6 , the data acquisition unit 2 also includes:
[0068] The node deployment unit 21 is used to deploy a node on each blockchain platform to synchronize the data on the chain.
[0069] The data screening unit 22 is used to pre-process and screen the on-chain data to obtain the transaction data and codes of all smart contracts.
[0070] See also Figure 7 , the vector calculation unit 3 also includes:
[0071] The transaction vector calculation unit 31 is used to count the transaction data in all smart contracts, divide the types of transaction data into multiple features, obtain a transaction feature matrix, and convert the transaction feature matrix into a transaction feature vector.
[0072] The instruction library building unit 32 is used to collect the instruction set of the virtual machine of each blockchain platform and build the smart contract instruction library of each platform.
[0073] The code vector calculation unit 33 is used to count the codes in all smart contracts, combine with the instruction library, count the number of times each instruction appears in each smart contract, and establish a code feature matrix, which is converted into a code feature vector.
[0074] See also Figure 8 The third embodiment of the present invention provides an electronic device, the electronic device includes a memory 10 and a processor 20, the memory 10 stores a computer program, and the computer program is configured to execute the steps of any of the above-mentioned multi-platform blockchain smart contract classification method embodiments when running. The processor 20 is configured to execute the steps of any of the above-mentioned multi-platform blockchain smart contract classification method embodiments through the computer program.
[0075] Optionally, in this embodiment, the electronic device may be located in at least one network device among a plurality of network devices of a computer network.
[0076] The multi-platform blockchain smart contract classification method, system and electronic device provided by the present invention have the following beneficial effects:
[0077] By obtaining smart contracts and corresponding category labels on multiple platforms, and obtaining codes and transaction data for smart contracts, converting them into transaction feature vectors and code feature vectors, and then merging them to obtain the final feature vector, which is then combined with the category labels.
[0078] The labels are input into the XGBoost model for training to obtain a classification model. Based on the classification model, smart contracts on different platforms can be classified. This method is applicable to the multi-classification model of smart contracts on multiple blockchain platforms, which can be used for the classification and functional identification of smart contracts, and can inform users of the true purpose of smart contracts, thereby reducing the risk of users being defrauded by contracts. At the same time, this method extracts common transaction features applicable to smart contracts on different blockchain platforms, establishes smart contract instruction libraries on different blockchain platforms, and finally extracts the code features of the contract for classification and identification of smart contracts, making full use of the transaction and code features of a smart contract, improving the accuracy of the smart contract multi-classification problem, and can be extended to multiple platforms. Furthermore, the smart contract multi-classification method proposed by this method is not specific to a certain blockchain platform, and the proposed transaction-related features can be collected on most mainstream blockchain platforms. At the same time, by gradually establishing smart contract instruction libraries on different platforms, it can be used for smart contract classification on more blockchain platforms. The scheme proposed by this method is more versatile and more scalable.
[0079] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed by the present invention, and these modifications or replacements should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.
Claims
1. A multi-platform blockchain smart contract classification method, Features: The following steps are involved: Step S1: Obtain multiple smart contracts on different platforms and obtain the category label of each smart contract; Step S2: For each smart contract, obtain the on-chain data on the corresponding platform, including code and transaction data; Step S3: Count the transaction data and codes in all smart contracts to obtain the corresponding transaction feature vectors and code feature vectors; Step S4: merge the transaction feature vector and the code feature vector to obtain a final feature vector, input the category label and the final feature vector into the XGBoost model to obtain a classification model; and Step S5: Classify the smart contracts based on the classification model obtained through training; The above step S3 specifically includes: Step S31: Count the transaction data in all smart contracts, divide the types of transaction data into multiple features, obtain a transaction feature matrix, and convert the transaction feature matrix into a transaction feature vector; Step S32: Collect the instruction set of the virtual machine of each blockchain platform and establish a smart contract instruction library for each platform; and Step S33: Count the codes in all smart contracts, combine with the instruction library, count the number of times each instruction in each smart contract appears, establish a code feature matrix, and convert the code feature matrix into a code feature vector; In step S31, the collected contract-related transaction data is used to calculate the following 18 features for each contract, namely, vector X = [x1, x2, x3, ..., x18]. The semantics of these 18 features are applicable to different blockchain platforms and can be extracted and calculated from the transaction data. The features of the transaction data include: Feature 1: the balance of the contract, Feature 2: the amount transferred in from external transactions of the contract, Feature 3: the amount transferred in from internal transactions of the contract, Feature 4: the amount transferred out from internal transactions of the contract, Feature 5: the number of contract transactions, Feature 6: the number of transfer-in transactions from external transactions of the contract, Feature 7: the number of transfer-in transactions from internal transactions of the contract, Feature 8: the number of transfer-out transactions from internal transactions of the contract, Feature 9: the number of addresses that have generated transfer-in transactions with the contract in external transactions of the contract, Feature 10: the number of addresses that have generated transfer-in transactions with the contract, Feature 11: the number of addresses that have generated transfer-in transactions with the contract, Feature 12: the number of addresses that have generated transfer-in transactions with the contract, Feature 13: the number of addresses that have generated transfer-in transactions with the contract, Feature 14: the number of addresses that have generated transfer-in transactions with the contract, Feature 15: the number of addresses that have generated transfer-in transactions with the contract, Feature 16: the number of addresses that have generated transfer-in transactions with the contract, Feature 17: the number of addresses that have generated transfer-in transactions with the contract, Feature 18: the number of addresses that have generated transfer-in transactions with the contract, Feature 19: the number of addresses that have generated transfer-in transactions with the contract, Feature 20: the number of addresses that have generated transfer-in transactions with the contract, Feature 21: the number of addresses that have generated transfer-in transactions with the contract, Feature 22: the number of addresses that have generated transfer-in transactions with the contract, Feature 23: the number of addresses that have generated transfer-in transactions with the contract, Feature 24: Feature 10: The number of addresses that have generated transfer-in transactions with the contract in the internal transactions of the contract, Feature 11: The number of addresses that have generated transfer-out transactions with the contract in the internal transactions of the contract, Feature 12: The average transaction amount of each transaction of the contract, Feature 13: The average value of the transfer-in amount in the internal transactions of the contract, Feature 14: The average value of the transfer-out amount in the internal transactions of the contract, Feature 15: The average value of the transfer-in amount in the external transactions of the contract, Feature 16: The variance of the transfer-in amount in the internal transactions of the contract, Feature 17: The variance of the transfer-out amount in the internal transactions of the contract, Feature 18: The variance of the transfer-in amount in the external transactions of the contract; In step S3, in the collected codes, each code corresponds to an instruction, and based on the number of times the instruction appears in the contract, a vector Y=[y1, y2, y3, ..., ym] is established, where ym represents the number of times the mth instruction appears in the contract, and the size of m depends on the virtual machine design of the platform; In step S4, the transaction feature vector X and the code feature vector Y are merged, that is, Z = [x1, x2, x3.......xn, y1, y2, y3......., ym]. Finally, Z and the labels collected in step S1 are input into the XGBoost model, and training is performed using a training set and a test set ratio of 2:
8. Finally, a smart contract multi-classification model is obtained. The classification model can input smart contracts from multiple different platforms and perform identification and classification.
2. According to the multi-platform blockchain smart contract classification method described in claim 1, Features: Step S2 specifically includes: Step S21: deploy a node on each blockchain platform to synchronize the data on the chain; and Step S22: Preprocess and filter the on-chain data to obtain the transaction data and codes of all smart contracts.
3. According to the multi-platform blockchain smart contract classification method according to claim 1, Features: Step S5 specifically includes: Step S51: Based on the classification model obtained through training, input the smart contract on any platform; Step S52: the classification model outputs a multi-dimensional vector, the dimension of the multi-dimensional vector is the same as the number of category labels; and Step S53: Obtain the classification result of the smart contract based on the multi-dimensional vector.
4. A multi-platform blockchain smart contract classification system, Features: include: The contract acquisition unit is used to acquire multiple smart contracts on different platforms and obtain the category label of each smart contract; The data acquisition unit is used to obtain the on-chain data on the corresponding platform for each smart contract, including code and transaction data; Vector calculation unit, used to count the transaction data and codes in all smart contracts and obtain the corresponding transaction feature vectors and code feature vectors; A model training unit is used to merge the transaction feature vector and the code feature vector to obtain a final feature vector, and input the category label and the final feature vector into the XGBoost model to obtain a classification model; and The contract classification unit is used to classify smart contracts based on the trained classification model; The vector calculation unit also includes: A transaction vector calculation unit, used to count the transaction data in all smart contracts, divide the types of transaction data into multiple features, obtain a transaction feature matrix, and convert the transaction feature matrix into a transaction feature vector; An instruction library building unit, used to collect the instruction set of the virtual machine of each blockchain platform and build a smart contract instruction library for each platform; and A code vector calculation unit is used to count the codes in all smart contracts, combine the instruction library, count the number of times each instruction appears in each smart contract, and establish a code feature matrix, which is converted into a code feature vector; Among them, in the transaction vector calculation unit, the contract-related transaction data collected is used to calculate the following 18 features for each contract, namely, vector X = [x1, x2, x3, ..., x18]. The semantics of these 18 features are applicable to different blockchain platforms and can be extracted and calculated from the transaction data. The features of the transaction data include: Feature 1: the balance of the contract, Feature 2: the amount transferred in from external transactions of the contract, Feature 3: the amount transferred in from internal transactions of the contract, Feature 4: the amount transferred out from internal transactions of the contract, Feature 5: the number of contract transactions, Feature 6: the number of transfer-in transactions from external transactions of the contract, Feature 7: the number of transfer-in transactions from internal transactions of the contract, Feature 8: the number of transfer-out transactions from internal transactions of the contract, Feature 9: the number of addresses that have generated transfer-in transactions with the contract in external transactions of the contract, Feature Feature 10: The number of addresses that have generated transfer-in transactions with the contract in the internal transactions of the contract, Feature 11: The number of addresses that have generated transfer-out transactions with the contract in the internal transactions of the contract, Feature 12: The average transaction amount of each transaction of the contract, Feature 13: The average value of the transfer-in amount in the internal transactions of the contract, Feature 14: The average value of the transfer-out amount in the internal transactions of the contract, Feature 15: The average value of the transfer-in amount in the external transactions of the contract, Feature 16: The variance of the transfer-in amount in the internal transactions of the contract, Feature 17: The variance of the transfer-out amount in the internal transactions of the contract, Feature 18: The variance of the transfer-in amount in the external transactions of the contract; In the vector computing unit, in the collected codes, each code corresponds to an instruction. Based on the number of times the instruction appears in the contract, a vector Y = [y1, y2, y3, ..., ym] is established, where ym represents the number of times the mth instruction appears in the contract, and the size of m depends on the virtual machine design of the platform; In the model training unit, the transaction feature vector X and the code feature vector Y are merged, that is, Z = [x1, x2, x3.......xn, y1, y2, y3......., ym]. Finally, Z and the labels collected in step S1 are input into the XGBoost model, and the training is performed in a ratio mode of 2:8 between the training set and the test set. Finally, a smart contract multi-classification model is obtained. The classification model can input smart contracts from multiple different platforms and perform recognition and classification.
5. According to the multi-platform blockchain smart contract classification system of claim 4, Features: The data acquisition unit also includes: A node deployment unit, which is used to deploy a node on each blockchain platform and synchronize the data on the chain; and The data screening unit is used to pre-process and screen the on-chain data to obtain the transaction data and codes of all smart contracts.
6. An electronic device comprising a memory and a processor, Features: A computer program is stored in the memory, and the computer program is configured to execute the multi-platform blockchain smart contract classification method described in any one of claims 1 to 3 at runtime; the processor is configured to execute the multi-platform blockchain smart contract classification method described in any one of claims 1 to 3 through the computer program.
