Data recovery method, device, terminal device and storage medium for smart contract

通过获取智能合约的区块链交易合约函数并生成逆向函数,解决了智能合约异常数据恢复的问题,实现了在不影响其他交易的数据恢复。

CN112650627BActive Publication Date: 2025-07-11HANGZHOU QULIAN TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011606527.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-28
Publication Date
2025-07-11
Estimated Expiration
2040-12-28

AI Technical Summary

Technical Problem

On the blockchain platform, after a logical error or operation error occurs in a smart contract, how to restore abnormal data without affecting other transactions.

Method used

By determining the target smart contract, obtaining blockchain transactions that generate exception data, analyzing the contract functions, and generating an inverse function to recover exception data, and using the inverse function to recover exception data.

Benefits of technology

Without affecting other transactions on the blockchain platform, the recovery of abnormal data of smart contracts is achieved, which is highly operable.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112650627B_ABST
    Figure CN112650627B_ABST
Patent Text Reader

Abstract

This application is applicable to the field of blockchain technology, and provides a method, apparatus, terminal device and storage medium for data recovery of smart contracts, including: determining a target smart contract, where the target smart contract refers to a smart contract with abnormal data; obtaining a first blockchain transaction that generates the abnormal data according to the target smart contract; obtaining the contract function of each of the first blockchain transactions; obtaining the inverse function of the contract function according to the contract function of each of the first blockchain transactions, where the logic of the inverse function is opposite to the logic of the contract function; recovering the abnormal data generated by each of the first blockchain transactions according to the inverse function of the contract function of each of the first blockchain transactions to obtain the recovered data. Through this application, the abnormal data of the smart contract can be recovered without affecting other transactions on the blockchain platform.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the technical field of blockchain, and particularly relates to a method, apparatus, terminal device, and storage medium for data recovery of smart contracts. Background Art

[0002] A smart contract is an executable program running on a blockchain platform, with programmable data processing and data storage capabilities. Each data processing is executed through a blockchain transaction. Due to the chain structure and immutability characteristics of the blockchain itself, once a blockchain transaction is executed, it cannot be tampered with.

[0003] When a logical error or operation error occurs in a smart contract, abnormal data will be generated. Without affecting other transactions on the blockchain platform, how to restore the abnormal data to the state before the execution of the error operation is a technical problem to be solved urgently. Summary of the Invention

[0004] Embodiments of this application provide a method, apparatus, terminal device, and storage medium for data recovery of smart contracts to recover abnormal data of smart contracts without affecting other transactions on the blockchain platform.

[0005] In a first aspect, embodiments of this application provide a method for data recovery of smart contracts. The data recovery method includes:

[0006] Determine a target smart contract, where the target smart contract refers to a smart contract with abnormal data;

[0007] According to the target smart contract, obtain a first blockchain transaction that generates the abnormal data;

[0008] Obtain the contract function of each of the first blockchain transactions;

[0009] According to the contract function of each of the first blockchain transactions, obtain an inverse function of the contract function, where the logic of the inverse function is opposite to the logic of the contract function;

[0010] According to the inverse function of the contract function of each of the first blockchain transactions, recover the abnormal data generated by the first blockchain transaction to obtain recovered data.

[0011] In a second aspect, embodiments of this application provide a data recovery apparatus for smart contracts. The data recovery apparatus includes:

[0012] A contract determination module, configured to determine a target smart contract, where the target smart contract refers to a smart contract with abnormal data;

[0013] A transaction acquisition module, configured to obtain a first blockchain transaction that generates the abnormal data according to the target smart contract;

[0014] A function acquisition module, configured to obtain the contract function of each of the first blockchain transactions;

[0015] A reverse acquisition module, configured to obtain the reverse function of the contract function according to the contract function of each of the first blockchain transactions, where the logic of the reverse function is opposite to the logic of the contract function;

[0016] A data recovery module, configured to recover the abnormal data generated by each of the first blockchain transactions according to the reverse function of the contract function of each of the first blockchain transactions, to obtain the recovered data.

[0017] In a third aspect, an embodiment of the present application provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the data recovery method described in the first aspect above are implemented.

[0018] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium storing a computer program, and when the computer program is executed by a processor, the steps of the data recovery method described in the first aspect above are implemented.

[0019] In a fifth aspect, an embodiment of the present application provides a computer program product, and when the computer program product runs on a terminal device, the terminal device is enabled to execute the steps of the data recovery method described in the first aspect above.

[0020] As can be seen from the above, after determining the target smart contract with abnormal data, the present application can obtain the first blockchain transaction that generates the abnormal data according to the target smart contract, and obtain the contract function of each first blockchain transaction. Through the reverse function with the opposite logic to the contract function, the abnormal data generated by each first blockchain transaction can be recovered, so as to realize the recovery of abnormal data without affecting other transactions on the blockchain platform, and has strong operability. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0022] Figure 1It is an example diagram of the composition of blockchain data;

[0023] Figure 2 It is a schematic diagram of the implementation process of the data recovery method for the smart contract provided in the first embodiment of this application;

[0024] Figure 3 It is a schematic diagram of the implementation process of the data recovery method for the smart contract provided in the second embodiment of this application;

[0025] Figure 4a It is an example diagram of the first transaction list; Figure 4b It is an example diagram of the second transaction list; Figure 4c It is an example diagram of the third transaction list; Figure 4d It is an example diagram of the fourth transaction list;

[0026] Figure 5 It is an example diagram of the upgrade of the target smart contract;

[0027] Figure 6 It is a schematic diagram of the structure of the data recovery device for the smart contract provided in the third embodiment of this application;

[0028] Figure 7 It is a schematic diagram of the structure of the terminal device provided in the fourth embodiment of this application. Detailed implementation manners

[0029] In the following description, for the purpose of illustration rather than limitation, specific details such as specific system structures and technologies are set forth in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art should clearly understand that this application can also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid unnecessary details from interfering with the description of this application.

[0030] It should be understood that when used in the specification and appended claims of this application, the term "including" indicates the presence of the described features, wholes, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components, and / or their combinations.

[0031] It should also be understood that the term "and / or" as used in the specification and appended claims of this application refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0032] As used in the specification and appended claims of the present application, the term "if" may be construed, depending on the context, as "when", "once", "in response to determining", or "in response to detecting". Similarly, the phrases "if determined" or "if [described condition or event] is detected" may be construed, depending on the context, as meaning "once determined", "in response to determining", "once [described condition or event] is detected", or "in response to detecting [described condition or event]".

[0033] In addition, in the description of the specification and appended claims of the present application, the terms "first", "second", "third", etc. are only used for differential description and cannot be construed as indicating or implying relative importance.

[0034] Reference to "one embodiment" or "some embodiments" or the like described in the specification of the present application means that a specific feature, structure, or characteristic described in connection with that embodiment is included in one or more embodiments of the present application. Thus, statements such as "in one embodiment", "in some embodiments", "in other some embodiments", "in still other embodiments", etc. that appear in different places in this specification do not necessarily all refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in another way. The terms "comprising", "including", "having", and their variants all mean "including but not limited to", unless otherwise specifically emphasized in another way.

[0035] Before describing the embodiments of the present application, for the convenience of the reader's understanding, the nouns involved in the embodiments of the present application are first explained.

[0036] A blockchain platform is a distributed trusted storage system, usually composed of multiple blockchain nodes. The blockchain platform has characteristics such as data immutability, decentralization, and a block-chain storage structure.

[0037] A smart contract is an executable program that can run on a blockchain platform and provides services through an open interface. A smart contract has a specific programming language, and the contract code has a certain logic.

[0038] After a smart contract is developed, it needs to be deployed to the blockchain platform to send the smart contract to all blockchain nodes in the blockchain platform. Among them, the deployment of the smart contract is the process of the smart contract going on-chain.

[0039] The address of a smart contract is the unique identifier that the smart contract has after being deployed on the blockchain platform.

[0040] A smart contract deployed on the blockchain platform can modify its access rights through freezing and thawing methods.

[0041] Freezing a smart contract means closing the interface service permissions of the smart contract, that is, not allowing the smart contract to conduct transactions any more. The contract owner has the permission to freeze the smart contract.

[0042] Thawing a smart contract means opening the interface service permissions of the smart contract, that is, allowing the smart contract to conduct transactions.

[0043] A smart contract includes a storage structure and a logical structure. The storage structure is used to store the state data of the smart contract, and the state data of the smart contract is changed by the execution of each blockchain transaction related to the smart contract.

[0044] The state data of a smart contract refers to the data stored in the smart contract.

[0045] The logical structure of a smart contract refers to the function of the smart contract (i.e., the contract function), which can also be called a method.

[0046] As Figure 1 shown is an example diagram of the composition of blockchain data. Blockchain data includes block data and the state data of smart contracts. Block data can be understood as a block.

[0047] A block is a chain structure and continuously grows with the generation of transactions. The block height increases sequentially with the generation time of the block, and the generation time of the block is stored in the block.

[0048] A transaction (i.e., a blockchain transaction) refers to a record of changes in blockchain data. All operations on the blockchain platform are completed through transactions. After a transaction is executed, the transaction itself is stored in a block. One block can store one or at least two transactions.

[0049] A logical error refers to a vulnerability generated by the smart contract writer during coding, that is, the implemented function does not conform to the business objective, or a code vulnerability caused by an insufficient understanding of grammar. For example: the grammar is "a=a+1", and when the value of a exceeds the unit256 range, an overflow event will occur.

[0050] A smart contract is used to provide an interface for the business system to call. An operation error means that the caller finds that the original operation is not what is needed after calling the smart contract, but due to mechanisms such as the immutability of the blockchain platform, it cannot be rolled back.

[0051] Rolling back refers to the behavior of restoring a program or data to the previous correct state due to a program or data processing error.

[0052] It should be understood that the magnitudes of the sequence numbers of the steps in this embodiment do not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of this application.

[0053] To illustrate the technical solution described in this application, the following will be described through specific embodiments.

[0054] Refer to Figure 2 , which is a schematic diagram of the implementation process of the data recovery method for smart contracts provided in the first embodiment of this application. This data recovery method is applied to a terminal device. As shown in the figure, this data recovery method may include the following steps:

[0055] Step 201: Determine the target smart contract.

[0056] Among them, the target smart contract refers to a smart contract with abnormal data. Abnormal data refers to the data generated when a logical error or operation error occurs in the smart contract. Abnormal data can also be referred to as dirty data or invalid data.

[0057] When determining the target smart contract, it can be manually detected whether there is abnormal data in the smart contract. When there is abnormal data, the smart contract with abnormal data is determined as the target smart contract. For example, when the contract administrator discovers a smart contract with abnormal data, a smart contract confirmation instruction is sent to the terminal device through the account. The smart contract confirmation instruction includes the address of the target smart contract. After receiving the smart contract confirmation instruction, the terminal device determines the target smart contract of the smart contract at the above address. Among them, the account of the contract administrator refers to the account for deploying the target smart contract.

[0058] When determining the target smart contract, the above target smart contract can also be frozen to prevent the generation of more abnormal data.

[0059] Step 202: According to the target smart contract, obtain the first blockchain transaction that generates abnormal data.

[0060] Among them, the above first blockchain transaction refers to a transaction related to the target smart contract and generating abnormal data. A transaction related to the target smart contract may refer to a transaction whose recipient address is the address of the target smart contract.

[0061] According to the address of the target smart contract, it is possible to more accurately obtain the transaction related to the target smart contract and generating abnormal data to prevent obtaining transactions unrelated to the target smart contract. Transactions unrelated to the target smart contract include, but are not limited to, transactions generated by other smart contracts, transactions not generated by smart contracts, etc.

[0062] Optionally, before obtaining the first blockchain transaction that generates abnormal data according to the target smart contract, it further includes:

[0063] Obtain the target time, where the target time refers to the time when the abnormal data is generated;

[0064] Obtain all blockchain transactions generated within the target time;

[0065] According to the target smart contract, obtaining the first blockchain transaction that generates abnormal data includes:

[0066] According to the target smart contract, from all blockchain transactions, filter out the blockchain transactions belonging to the target smart contract, and determine the blockchain transactions belonging to the target smart contract as the first blockchain transaction.

[0067] When it is determined that there is abnormal data in the target smart contract, the time when the abnormal data is generated (i.e., the target time) can be obtained first, then all blockchain transactions generated on the blockchain platform within the target time are obtained, and finally, according to the address of the target smart contract, the blockchain transactions belonging to the target smart contract are filtered out from all the above blockchain transactions. Among them, the blockchain transactions belonging to the target smart contract can be understood as the blockchain transactions related to the target smart contract.

[0068] Exemplarily, the generation time of the abnormal data in the target smart contract is December 15, 2020, that is, the above target time is December 15, 2020. All blockchain transactions generated by the blockchain platform on December 15, 2020 can be obtained, and the blockchain transactions belonging to the target smart contract are filtered out from all the above blockchain transactions.

[0069] Optionally, obtaining all blockchain transactions generated within the target time includes:

[0070] Obtain all blocks generated within the target time;

[0071] Obtain the blockchain transactions included in each block among all blocks to obtain all blockchain transactions.

[0072] Since after the execution of a blockchain transaction is completed, the blockchain transaction itself is usually stored in a block, and one block can store one or at least two blockchain transactions, all blockchain transactions generated within the target time can be obtained by obtaining all blocks generated within the target time.

[0073] Exemplarily, the generation time of the abnormal data in the target smart contract is December 15, 2020, that is, the above target time is December 15, 2020. All blocks generated by the blockchain platform on December 15, 2020 can be obtained, and the blockchain transactions within all the above blocks are all blockchain transactions generated on December 15, 2020.

[0074] Generally, the generation time of a block is stored in the block. If the generation time of a block is within the above target time, it is determined that the block (i.e., the block with the generation time within the above target time) is the block generated within the above target time; if the generation time of a block is not within the above target time, it is determined that the block (i.e., the block with the generation time not within the above target time) is not the block generated within the above target time.

[0075] Since the block height increases in the order of the generation time of the blocks, the first block and the second block with the generation time within the above target time can be obtained. The first block is the block where abnormal data first appears, and the second block is the block where abnormal data appears last. The first block and the second block form a block interval, and all the blocks within this block interval are all the blocks generated within the target time. All the blockchain transactions included in all these blocks are all the blockchain transactions generated within the above target time. For example, if the block height of the first block is N and the block height of the second block is K, then the block interval formed by the first block and the second block is [N, K], and all the blockchain transactions between block N and block K are all the transactions generated within the target time. Herein, the above block height can also be understood as the block number.

[0076] Optionally, screening out the blockchain transactions belonging to the target smart contract from all the blockchain transactions according to the target smart contract includes:

[0077] Obtaining the recipient address of each blockchain transaction among all the blockchain transactions;

[0078] Detecting whether there is a blockchain transaction in all the blockchain transactions whose recipient address is the same as the target address, where the target address refers to the address of the target smart contract;

[0079] If there is a blockchain transaction in all the blockchain transactions whose recipient address is the same as the target address, it is determined that the blockchain transaction belongs to the target smart contract.

[0080] The blockchain transaction contains the addresses of both parties to the blockchain transaction, that is, the sender address and the recipient address of the blockchain transaction. The blockchain transactions belonging to the target smart contract can be screened out from all the above blockchain transactions by comparing the recipient address of each blockchain transaction in all the blockchain transactions generated within the target time with the address of the target smart contract.

[0081] Specifically, for the i-th blockchain transaction among all the above-mentioned blockchain transactions, the i-th blockchain transaction is any one of all the above-mentioned blockchain transactions, and i is a positive integer less than or equal to the total number of all the above-mentioned blockchain transactions; from the i-th blockchain transaction, obtain the recipient address of the i-th blockchain transaction; determine whether the recipient address of the i-th blockchain transaction is the same as the address of the target smart contract; if the recipient address of the i-th blockchain transaction is the same as the address of the target smart contract, then determine that the i-th blockchain transaction belongs to the target smart contract; if the recipient address of the i-th blockchain transaction is not the same as the address of the target smart contract, then determine that the i-th blockchain transaction does not belong to the target smart contract. By performing the above determination operation on each blockchain transaction among all the above-mentioned blockchain transactions, it is possible to determine whether each blockchain transaction among all the above-mentioned blockchain transactions belongs to the target smart contract, so as to screen out all the blockchain transactions that belong to the target smart contract from all the above-mentioned blockchain transactions. Among them, the above determination operation refers to the operation of determining whether the i-th blockchain transaction belongs to the target smart contract.

[0082] Step 203: Obtain the contract function of each first blockchain transaction.

[0083] In this embodiment, the number of first blockchain transactions that generate abnormal data is at least one. The contract function of each first blockchain transaction can be obtained by parsing each first blockchain transaction. For example, in step 202, three first blockchain transactions are obtained. The contract function of the first first blockchain transaction, the contract function of the second first blockchain transaction, and the contract function of the third first blockchain transaction can be obtained by parsing the first first blockchain transaction, the second first blockchain transaction, and the third first blockchain transaction respectively. Among them, specifically in the above step 203, the name and parameters of the contract function of each first blockchain transaction can be obtained.

[0084] Specifically, the syntax tree of the target smart contract can be used to parse the target data of each first blockchain transaction to obtain the contract function of the first blockchain transaction.

[0085] Among them, the syntax tree of the above target smart contract can specifically refer to the Abstract Syntax Code (AST) of the target smart contract. The AST of the target smart contract is a tree-like representation of the abstract syntax structure of the source code of the target smart contract. Each node on the tree represents a structure in the source code. The AST of the target smart contract is used to define the function, parameters, type names of return values, etc. of the target smart contract, so as to construct the blockchain transactions of the target smart contract and parse the blockchain transactions of the target smart contract. The above blockchain transactions of the target smart contract refer to the blockchain transactions that belong to the target smart contract.

[0086] It should be noted that the AST in the smart contract can also be named using the Application Binary Interface (ABI).

[0087] The target data of the above first blockchain transaction includes, but is not limited to, transaction contents such as the payload of the first blockchain transaction. By using the syntax tree of the target smart contract, the transaction contents such as the payload of the first blockchain transaction can be parsed to obtain the name and parameters of the contract function of the first blockchain transaction. Among them, the payload of the above first blockchain transaction is the encapsulated encoding of the name and parameters of the contract function of the first blockchain transaction.

[0088] The contract function of the above first blockchain transaction may refer to the function of the target smart contract called when generating the first blockchain transaction. The function of the target smart contract is used to implement the logic of the target smart contract, and the logic of the target smart contract can also be referred to as the logical structure of the target smart contract.

[0089] Step 204: According to the contract function of each first blockchain transaction, obtain the reverse function of the contract function, and the logic of the reverse function is opposite to the logic of the contract function.

[0090] Among them, the logic of a contract function is opposite to the logic of the reverse function of the contract function. The opposite logic can be understood as the opposite data operation. Exemplarily, if the logic of a contract function is "a = a + 1", then the logic of the reverse function of the contract function is "a = a - 1".

[0091] Step 205: According to the reverse function of the contract function of each first blockchain transaction, recover the abnormal data generated by the first blockchain transaction to obtain the recovered data.

[0092] For each first blockchain transaction obtained in step 202, since the reverse function of the first blockchain transaction (i.e., the reverse function of the contract function of the first blockchain transaction) is opposite to the logic of the contract function of the first blockchain transaction, the reverse function of the first blockchain transaction can be used to roll back the abnormal data and recover the abnormal data generated when the target smart contract has a logical error or an operation error to obtain the recovered data.

[0093] After determining the target smart contract with abnormal data in the embodiments of the present application, the first blockchain transaction that generates the abnormal data can be obtained according to the target smart contract, and the contract function of each first blockchain transaction can be obtained. Through the reverse function opposite to the logic of the contract function, the abnormal data generated by each first blockchain transaction can be restored, so as to realize the restoration of the abnormal data without affecting other transactions on the blockchain platform, which has strong operability.

[0094] See Figure 3 , which is a schematic diagram of the implementation process of the data restoration method for the smart contract provided in the second embodiment of the present application. This data restoration method is applied to a terminal device. As shown in the figure, this data restoration method may include the following steps:

[0095] Step 301, determine the target smart contract.

[0096] This step is the same as step 201. For specific details, please refer to the relevant description of step 201 and will not be elaborated here.

[0097] In addition, when determining the target smart contract, the target smart contract can also be frozen to prevent the generation of more abnormal data.

[0098] Specifically, the contract administrator can send a contract freezing transaction to the target smart contract through an account. After receiving the above contract freezing transaction, the target smart contract executes the above contract freezing transaction. After the execution of the above contract freezing transaction is successful, the terminal device freezes the above target smart contract. The above contract freezing transaction contains the address of the target smart contract to indicate freezing the smart contract at this address, that is, freezing the target smart contract.

[0099] Freezing the target smart contract may mean stopping the call permission for the target smart contract, that is, a blockchain transaction with the address of the target smart contract as the recipient address cannot be successfully executed.

[0100] Step 302, according to the target smart contract, obtain the first blockchain transaction that generates the abnormal data, and form a first transaction list from the first blockchain transactions.

[0101] This step is partially the same as step 202. For the same part, please refer to the relevant description of step 202 and will not be elaborated here.

[0102] In this embodiment, all the first blockchain transactions that generate the abnormal data obtained according to step 302 form a first transaction list. All the first blockchain transactions in the first transaction list are arranged in the order of the generation time. The earlier the generation time of the first blockchain transaction, the more forward its arrangement position in the first transaction list, and the later the generation time of the first blockchain transaction, the more backward its arrangement position in the first transaction list. As Figure 4aThe figure shown is an example diagram of a first transaction list, which contains n first blockchain transactions. The generation time of the first blockchain transaction 1 is the earliest, so it is arranged at the top of the first transaction list. The generation time of the first blockchain transaction n is the latest, so it is arranged at the end of the first transaction list. Figure 4a In Figure 4a , "from" represents the sender address and "to" represents the recipient address.

[0103] Since the blockchain is a chain structure and grows continuously with the generation of blockchain transactions, the chain relationship between blocks also indicates the order of generation time of the blocks. And all the first blockchain transactions that generate abnormal data are obtained based on the blocks. Therefore, the arrangement order of all the above-mentioned first blockchain transactions in the first transaction list can be obtained according to the chain relationship between the blocks.

[0104] Step 303: According to the arrangement order of the first blockchain transactions in the first transaction list, use the syntax tree of the target smart contract to parse the target data of each first blockchain transaction in turn, determine that the parsed first blockchain transaction is the second blockchain transaction, and form a second transaction list from the second blockchain transactions.

[0105] Specifically, according to the arrangement order of all the first blockchain transactions in the first transaction list, use the syntax tree of the target smart contract to parse the target data of each first blockchain transaction in turn, obtain the name and parameters of the contract function of each first blockchain transaction. After traversing all the first blockchain transactions in the first transaction list, the names and parameters of the contract functions of all the first blockchain transactions can be obtained.

[0106] Exemplarily, the first transaction list contains three first blockchain transactions. The arrangement order of the three first blockchain transactions in the first transaction list is the first blockchain transaction 1, the first blockchain transaction 2, and the first blockchain transaction 3 in turn. First, use the syntax tree of the target smart contract to parse the payload of the first blockchain transaction 1 to obtain the name and parameters of the contract function of the first blockchain transaction 1; then use the syntax tree of the target smart contract to parse the payload of the first blockchain transaction 2 to obtain the name and parameters of the contract function of the first blockchain transaction 2; finally, use the syntax tree of the target smart contract to parse the payload of the first blockchain transaction 3 to obtain the name and parameters of the contract function of the first blockchain transaction 3.

[0107] It should be noted that the syntax tree of the target smart contract, the target data, and the contract function have been introduced in Embodiment 1, and will not be elaborated here.

[0108] After parsing the payload of each first blockchain transaction, the name and parameters of the contract function of the first blockchain transaction can be obtained. Therefore, the name and parameters of the contract function are included in the parsed first blockchain transaction, that is, the name and parameters of the contract function are included in the second blockchain transaction corresponding to the first blockchain transaction.

[0109] After parsing the target data of all first blockchain transactions in the first transaction list, the second blockchain transactions corresponding to all first blockchain transactions can be obtained, and the second blockchain transactions corresponding to all first blockchain transactions form a second transaction list.

[0110] Since all second blockchain transactions in the second transaction list are obtained by parsing the above-mentioned all first blockchain transactions in sequence according to the arrangement order, the earlier the first blockchain transaction is parsed, the earlier the generation time of its corresponding second blockchain transaction, and the more forward its arrangement position in the second transaction list. The later the first blockchain transaction is parsed, the later the generation time of its corresponding second blockchain transaction, and the more backward its arrangement position in the second transaction list. As Figure 4b shown is an example diagram of the second transaction list. The second transaction list contains n second blockchain transactions. The above n second blockchain transactions are obtained by parsing Figure 4a the n first blockchain transactions in it. The generation time of the second blockchain transaction 1 is the earliest, so it is arranged at the top of the second transaction list. The generation time of the second blockchain transaction n is the latest, so it is arranged at the end of the second transaction list. Figure 4b In it, addr represents the target address, name represents the function name, params represents the parameters, and func1 represents the name of the contract function.

[0111] In an embodiment, after obtaining the reverse functions of the contract functions of all first blockchain transactions in the first transaction list, all the obtained reverse functions can also be added to the target smart contract to upgrade the target smart contract, obtain an upgraded contract (that is, the upgraded target smart contract), and update the smart contract located at the target address from the target smart contract to the upgraded contract. As Figure 5 shown is an example diagram of the upgrade of the target smart contract.

[0112] After obtaining the upgraded contract, it is necessary to deploy the upgraded contract to the blockchain platform to facilitate the blockchain platform to call the upgraded contract.

[0113] Step 304, in accordance with the arrangement order of the second blockchain transactions in the second transaction list, sequentially update the function name of each second blockchain transaction to the name of the reverse function, generate the third blockchain transaction corresponding to the second blockchain transaction, and arrange the third blockchain transactions in reverse order according to the generation time to form a third transaction list.

[0114] Specifically, according to the arrangement order of all the second blockchain transactions in the second transaction list, the function name of each second blockchain transaction can be updated from the name of the contract function to the name of the reverse function in sequence. The second blockchain transaction after the function name is updated is the third blockchain transaction corresponding to this second blockchain transaction. After traversing all the second blockchain transactions in the second transaction list, the third blockchain transactions corresponding to all the second blockchain transactions in the second transaction list can be obtained. Since the third blockchain transactions are generated by changing the function names of all the second blockchain transactions in sequence according to the arrangement order, all the third blockchain transactions can be arranged in reverse order according to the generation time of all the third blockchain transactions, that is, the earlier the generation time of a third blockchain transaction, the more backward its arrangement position in the third transaction list, and the later the generation time of a third blockchain transaction, the more forward its arrangement position in the third transaction list. As Figure 4c shown is an example diagram of the third transaction list. The third transaction list includes n third blockchain transactions. The above n third blockchain transactions are obtained by changing the function names of the n second blockchain transactions in Figure 4b . The generation time of the third blockchain transaction n is the latest, so it is arranged at the top of the third transaction list. The generation time of the third blockchain transaction 1 is the earliest, so it is arranged at the end of the third transaction list. Figure 4c In , addr represents the target address, name represents the function name, params represents the parameter, and Rfunc1 represents the name of the reverse function.

[0115] Step 305: According to the arrangement order of the third blockchain transactions in the third transaction list, encode each third blockchain transaction in sequence to generate the fourth blockchain transaction corresponding to this third blockchain transaction, and form a fourth transaction list from the fourth blockchain transactions.

[0116] Among them, encoding the third blockchain transaction may refer to encapsulating the third blockchain transaction to form an executable transaction. Specifically, encapsulating the third blockchain transaction refers to encapsulating the function name and parameter of the third blockchain transaction.

[0117] Specifically, according to the arrangement order of the third blockchain transactions in the third transaction list, each third blockchain transaction can be encoded in sequence to obtain the fourth blockchain transaction corresponding to this third blockchain transaction. After traversing all the third blockchain transactions in the third transaction list, the fourth blockchain transactions corresponding to all the third blockchain transactions in the third transaction list can be obtained. The fourth blockchain transactions corresponding to all the third blockchain transactions form a fourth transaction list.

[0118] Since all the fourth blockchain transactions in the fourth transaction list are encoded in sequence according to the above-mentioned third blockchain transactions in the order of arrangement, the earlier the third blockchain transaction is encoded, the earlier the generation time of the corresponding fourth blockchain transaction, and the more forward its position in the fourth transaction list; the later the third blockchain transaction is encoded, the later the generation time of the corresponding fourth blockchain transaction, and the more backward its position in the fourth transaction list. As Figure 4d shown in the example diagram of the fourth transaction list, which includes n fourth blockchain transactions. The above-mentioned n fourth blockchain transactions are obtained by encoding the n third blockchain transactions in Figure 4c . The generation time of the fourth blockchain transaction n is the earliest, so it is arranged at the top of the fourth transaction list. The generation time of the fourth blockchain transaction 1 is the latest, so it is arranged at the end of the fourth transaction list. Figure 4d In , "from" represents the sender address and "to" represents the recipient address.

[0119] Step 306: According to the order of arrangement of the fourth blockchain transactions in the fourth transaction list, sequentially send each fourth blockchain transaction to the blockchain platform to execute the fourth blockchain transaction through the blockchain platform and obtain the restored data corresponding to the fourth blockchain transaction.

[0120] Specifically, according to the order of arrangement of the fourth blockchain transactions in the fourth transaction list, each fourth blockchain transaction can be sequentially sent to the blockchain platform. After the blockchain platform receives the fourth blockchain transaction, it executes the fourth blockchain transaction. The data obtained after the execution is the restored data corresponding to the fourth blockchain transaction. After the blockchain platform executes all the fourth blockchain transactions in the fourth transaction list, the restored data corresponding to all the abnormal data of the target smart contract can be obtained.

[0121] Among them, for the jth fourth blockchain transaction, the jth fourth blockchain transaction is any fourth blockchain transaction in the fourth transaction list, and j is a positive integer less than or equal to the total number of fourth blockchain transactions. The restored data corresponding to the jth fourth blockchain transaction can be understood as: the restored data corresponding to the abnormal data generated by the first blockchain transaction corresponding to the jth fourth blockchain transaction. For example, Figure 4d the fourth blockchain transaction n in corresponds to Figure 4c the third blockchain transaction n in , Figure 4c the third blockchain transaction n in corresponds to Figure 4b the second blockchain transaction n in , Figure 4b the second blockchain transaction n in corresponds to Figure 4a the first blockchain transaction n in . Then Figure 4d the fourth blockchain transaction n in corresponds to Figure 4aIn the first blockchain transaction n, the restored data corresponding to the fourth blockchain transaction n is the restored data corresponding to the abnormal data generated by the first blockchain transaction n.

[0122] It should be noted that before sending the fourth blockchain transaction to the blockchain platform, it is necessary to thaw the smart contract (i.e., the upgrade contract) located at the target address so that the blockchain platform can call the upgrade contract to obtain the restored data when executing the fourth blockchain transaction.

[0123] In this embodiment, after restoring the abnormal data, it is also possible to verify the restored data by querying whether the restored data meets the restoration effect.

[0124] By obtaining the reverse function and the upgrade contract and sending the fourth blockchain transaction to the blockchain platform, the embodiment of the present application can restore the abnormal data through the blockchain platform without affecting other transactions on the blockchain platform, and has strong operability.

[0125] See Figure 6 , which is a schematic structural diagram of the data recovery device of the smart contract provided in the third embodiment of the present application. For the sake of simplicity, only the parts related to the embodiment of the present application are shown.

[0126] The data recovery device includes:

[0127] A contract determination module 61 for determining a target smart contract, where the target smart contract refers to a smart contract with abnormal data;

[0128] A transaction acquisition module 62 for acquiring the first blockchain transaction that generates abnormal data according to the target smart contract;

[0129] A function acquisition module 63 for acquiring the contract function of each first blockchain transaction;

[0130] A reverse acquisition module 64 for acquiring the reverse function of the contract function according to the contract function of each first blockchain transaction, where the logic of the reverse function is opposite to the logic of the contract function;

[0131] A data recovery module 65 for restoring the abnormal data generated by each first blockchain transaction according to the reverse function of the contract function of each first blockchain transaction to obtain the restored data.

[0132] Optionally, the above data recovery device further includes:

[0133] A time acquisition module for acquiring a target time, where the target time refers to the time when the abnormal data is generated;

[0134] A target acquisition module, configured to acquire all blockchain transactions generated within a target time;

[0135] The above-mentioned transaction acquisition module 62 is specifically configured to:

[0136] According to the target smart contract, filter out the blockchain transactions belonging to the target smart contract from all blockchain transactions, and determine the blockchain transactions belonging to the target smart contract as the first blockchain transactions.

[0137] Optionally, the above-mentioned target acquisition module is specifically configured to:

[0138] Acquire all blocks generated within the target time;

[0139] Acquire the blockchain transactions included in each block among all blocks to obtain all blockchain transactions.

[0140] The above-mentioned transaction acquisition module 62 is specifically configured to:

[0141] Acquire the recipient address of each blockchain transaction among all blockchain transactions;

[0142] Detect whether there is a blockchain transaction in all blockchain transactions whose recipient address is the same as the target address, where the target address refers to the address of the target smart contract;

[0143] If there is a blockchain transaction in all blockchain transactions whose recipient address is the same as the target address, determine that this blockchain transaction belongs to the target smart contract.

[0144] Optionally, the above-mentioned function acquisition module 63 is specifically configured to:

[0145] Use the syntax tree of the target smart contract to parse the target data of each first blockchain transaction to obtain the contract function of this first blockchain transaction.

[0146] Optionally, the above-mentioned data recovery device further includes:

[0147] A list formation module, configured to form a first transaction list from the first blockchain transactions.

[0148] Optionally, the above-mentioned function acquisition module 63 is specifically configured to:

[0149] According to the arrangement order of the first blockchain transactions in the first transaction list, use the syntax tree of the target smart contract to sequentially parse the target data of each first blockchain transaction.

[0150] Optionally, the above-mentioned data recovery device further includes:

[0151] A transaction determination module, configured to determine each parsed first blockchain transaction as a second blockchain transaction, and form a second transaction list from the second blockchain transactions;

[0152] The above data recovery module 65 includes:

[0153] A function update unit, configured to sequentially update the function name of each second blockchain transaction to the name of the reverse function according to the arrangement order of the second blockchain transactions in the second transaction list, generate a third blockchain transaction corresponding to the second blockchain transaction, and perform reverse sorting on the third blockchain transactions according to the generation time to form a third transaction list;

[0154] A transaction encoding unit, configured to sequentially encode each third blockchain transaction according to the arrangement order of the third blockchain transactions in the third transaction list, generate a fourth blockchain transaction corresponding to the third blockchain transaction, and form a fourth transaction list from the fourth blockchain transactions;

[0155] A transaction sending unit, configured to sequentially send each fourth blockchain transaction to the blockchain platform according to the arrangement order of the fourth blockchain transactions in the fourth transaction list, so as to execute the fourth blockchain transaction through the blockchain platform to obtain the restored data corresponding to the fourth blockchain transaction.

[0156] Optionally, the above data recovery device further includes:

[0157] A contract freezing module, configured to freeze a target smart contract located at a target address, where the target address refers to the address of the target smart contract;

[0158] A contract upgrade module, configured to add a reverse function to the target smart contract to obtain an upgraded contract, and the smart contract located at the target address is changed from the target smart contract to the upgraded contract;

[0159] A contract thawing module, configured to thaw the upgraded contract located at the target address.

[0160] The data recovery device provided in the embodiments of the present application can be applied to the first and second method embodiments described above. For details, please refer to the descriptions of the first and second method embodiments above, and details will not be repeated here.

[0161] Figure 7 It is a schematic structural diagram of a terminal device provided in the fourth embodiment of the present application. As Figure 7 shown, the terminal device 7 in this embodiment includes: one or more processors 70 (only one is shown in the figure), a memory 71, and a computer program 72 stored in the memory 71 and executable on at least one processor 70. When the processor 70 executes the computer program 72, the steps in the above various data recovery method embodiments are implemented.

[0162] The terminal device 7 can be a computing device such as a desktop computer, a notebook, a palm computer, and a cloud server. The terminal device may include, but is not limited to, a processor 70 and a memory 71. Those skilled in the art can understand that Figure 7 merely examples of the terminal device 7, which do not constitute a limitation on the terminal device 7, may include more or fewer components than shown in the figure, or combine certain components, or different components. For example, the terminal device may also include input / output devices, network access devices, a bus, etc.

[0163] The so-called processor 70 may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0164] The memory 71 may be an internal storage unit of the terminal device 7, such as the hard disk or memory of the terminal device 7. The memory 71 may also be an external storage device of the terminal device 7, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the terminal device 7. Further, the memory 71 may also include both the internal storage unit and the external storage device of the terminal device 7. The memory 71 is used to store computer programs and other programs and data required by the terminal device. The memory 71 may also be used to temporarily store data that has been output or is to be output.

[0165] Those skilled in the art can clearly understand that, for the convenience and conciseness of description, only the division of the above-mentioned functional units and modules is used as an example. In practical applications, the above functions can be allocated to different functional units and modules according to needs, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. Each functional unit and module in the embodiment can be integrated into a processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of a software functional unit. In addition, the specific names of the functional units and modules are only for the convenience of mutual distinction and do not limit the protection scope of this application. The specific working processes of the units and modules in the above system can refer to the corresponding processes in the foregoing method embodiments and will not be elaborated herein.

[0166] In the above embodiments, the descriptions of the various embodiments have their own emphases. For the parts not detailed or recorded in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0167] Those of ordinary skill in the art can realize that the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, or by a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professionals can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.

[0168] In the embodiments provided in this application, it should be understood that the disclosed device / terminal device and method can be implemented in other ways. For example, the device / terminal device embodiments described above are merely illustrative. For example, the division of modules or units is only a logical functional division. In actual implementation, there can be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection to each other can be through some interfaces. The indirect coupling or communication connection of the device or unit can be in an electrical, mechanical or other form.

[0169] The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they can be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0170] In addition, in each embodiment of the present application, the functional units may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit. The above-mentioned integrated units may be implemented in the form of hardware or in the form of software functional units.

[0171] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, to implement all or part of the processes in the above-mentioned embodiment methods of the present application, it can also be completed by a computer program instructing the relevant hardware. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, the steps of the above-mentioned various method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in the form of source code, object code, executable file or some intermediate form, etc. The computer-readable medium can include: any entity or device that can carry the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disc, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electrical carrier signal, telecommunication signal, and software distribution medium, etc. It should be noted that the content included in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electrical carrier signals and telecommunication signals.

[0172] To implement all or part of the processes in the above-mentioned embodiment methods of the present application, it can also be completed by a computer program product. When the computer program product runs on the terminal device, the terminal device can execute to implement the steps in the above-mentioned various method embodiments.

[0173] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the various embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A method for data recovery of a smart contract, characterized in that, The data recovery method includes: Determine a target smart contract, where the target smart contract refers to a smart contract with abnormal data; Obtain a first blockchain transaction that generates the abnormal data according to the target smart contract; Obtain the contract function of each of the first blockchain transactions; Obtain the reverse function of the contract function according to the contract function of each of the first blockchain transactions, where the logic of the reverse function is opposite to the logic of the contract function; Recover the abnormal data generated by each of the first blockchain transactions according to the reverse function of the contract function of each of the first blockchain transactions to obtain the recovered data.

2. The data recovery method according to claim 1, wherein Before obtaining the first blockchain transaction that generates the abnormal data according to the target smart contract, it further includes: Obtain a target time, where the target time refers to the time when the abnormal data is generated; Obtain all blockchain transactions generated within the target time; The obtaining the first blockchain transaction that generates the abnormal data according to the target smart contract includes: According to the target smart contract, screen out the blockchain transactions belonging to the target smart contract from all the blockchain transactions, and determine the blockchain transactions belonging to the target smart contract as the first blockchain transactions.

3. The data recovery method according to claim 2, wherein The obtaining all blockchain transactions generated within the target time includes: Obtain all blocks generated within the target time; Obtain the blockchain transactions included in each of the all blocks to obtain all the blockchain transactions.

4. The data recovery method according to claim 2, characterized in that, The screening out the blockchain transactions belonging to the target smart contract from all the blockchain transactions according to the target smart contract includes: Obtain the recipient address of each of the all blockchain transactions; Detect whether there is a blockchain transaction in all the blockchain transactions whose recipient address is the same as the target address, where the target address refers to the address of the target smart contract; If there is a blockchain transaction in all the blockchain transactions whose recipient address is the same as the target address, determine that this blockchain transaction belongs to the target smart contract.

5. The data recovery method according to any one of claims 1 to 4, characterized in that The obtaining the contract function of each of the first blockchain transactions includes: Use the syntax tree of the target smart contract to parse the target data of each of the first blockchain transactions to obtain the contract function of this first blockchain transaction.

6. The data recovery method according to claim 5, wherein After obtaining the first blockchain transaction that generates the abnormal data according to the target smart contract, it further includes: Form a first transaction list from the first blockchain transactions; The using the syntax tree of the target smart contract to parse the target data of each of the first blockchain transactions includes: According to the arrangement order of the first blockchain transactions in the first transaction list, use the syntax tree of the target smart contract to sequentially parse the target data of each of the first blockchain transactions; After sequentially parsing the target information of each of the first blockchain transactions, it further includes: Determine each of the first blockchain transactions after parsing as a second blockchain transaction, and form a second transaction list from the second blockchain transactions; Recovering the abnormal data generated by each first blockchain transaction according to the reverse function of the contract function of the first blockchain transaction, and the recovered data includes: According to the arrangement order of the second blockchain transactions in the second transaction list, sequentially update the function name of each second blockchain transaction to the name of the reverse function, generate a third blockchain transaction corresponding to the second blockchain transaction, and arrange the third blockchain transactions in reverse order according to the generation time to form a third transaction list; According to the arrangement order of the third blockchain transactions in the third transaction list, sequentially encode each third blockchain transaction to generate a fourth blockchain transaction corresponding to the third blockchain transaction, and form a fourth transaction list from the fourth blockchain transactions; According to the arrangement order of the fourth blockchain transactions in the fourth transaction list, sequentially send each fourth blockchain transaction to the blockchain platform to execute the fourth blockchain transaction through the blockchain platform, and obtain the recovered data corresponding to the fourth blockchain transaction.

7. The data recovery method according to claim 6, wherein Before obtaining the first blockchain transaction that generates the abnormal data according to the target smart contract, it further includes: Freezing the target smart contract located at the target address, where the target address refers to the address of the target smart contract; After obtaining the reverse function of each contract function of the first blockchain transaction according to the contract function of the first blockchain transaction, it further includes: Adding the reverse function to the target smart contract to obtain an upgraded contract, and the smart contract located at the target address is updated from the target smart contract to the upgraded contract; Before sequentially sending each fourth blockchain transaction to the blockchain platform according to the arrangement order of the fourth blockchain transactions in the fourth transaction list, it further includes: Thawing the upgraded contract located at the target address.

8. An intelligent contract data recovery device, characterized in that, The data recovery device includes: A contract determination module for determining a target smart contract, where the target smart contract refers to a smart contract with abnormal data; A transaction acquisition module for obtaining the first blockchain transaction that generates the abnormal data according to the target smart contract; A function acquisition module for obtaining the contract function of each first blockchain transaction; A reverse acquisition module for obtaining the reverse function of each contract function of the first blockchain transaction according to the contract function of the first blockchain transaction, where the logic of the reverse function is opposite to the logic of the contract function; A data recovery module for recovering the abnormal data generated by each first blockchain transaction according to the reverse function of the contract function of the first blockchain transaction to obtain the recovered data.

9. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the data recovery method according to any one of claims 1 to 7.

10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the steps of the data recovery method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Smart contract implementation method and device, user equipment and storage medium

    CN108876610A

  • Voting proposal life cycle management method based on smart contract

    CN111062060A