Smart contract transaction abnormality maintenance method, device, equipment and readable storage medium

By recording and tracking the stack status of the Ethereum virtual machine, judging the abnormality of smart contract transactions, modifying transaction parameters based on the abnormal source code, and re-executing transactions, the problem of abnormal positioning and repair of smart contract transactions is solved, and the reliability and user experience of transactions are improved.

CN114202215BActive Publication Date: 2025-03-04SUN YAT SEN UNIV +2
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111538076.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-15
Publication Date
2025-03-04
Estimated Expiration
2041-12-15

AI Technical Summary

Technical Problem

The existing technology lacks the positioning and repair methods for smart contract transaction exceptions, which leads to users being unable to obtain refunds of handling fees when transactions fail, hindering the development of smart contracts.

Method used

By recording the stack status of the Ethereum virtual machine, tracking the transaction process of the smart contract, determining whether the transaction is abnormal, and determining the abnormal source code based on the correspondence between the preset program counter value and the smart contract source code, modifying the transaction-related parameters, and re-executing the transaction.

Benefits of technology

It realizes the positioning and repair of smart contract transaction exceptions, avoids economic losses when transaction failure, and improves the reliability and user experience of smart contracts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114202215B_ABST
    Figure CN114202215B_ABST
Patent Text Reader

Abstract

The present application discloses a method, device, equipment and readable storage medium for maintaining abnormal transactions of smart contracts. The method includes: recording the current stack state of the Ethereum virtual machine; tracking the transaction process of the smart contract on the Ethereum virtual machine to obtain the transaction information of the transaction; when the transaction is completed, determining whether the transaction is executed abnormally; if so, determining the abnormal source code corresponding to the abnormal program counter value contained in the transaction information according to the correspondence between the preset program counter value and the source code of the smart contract; modifying the relevant parameters of the transaction according to the abnormal source code; and executing the modified transaction on the Ethereum virtual machine with the same stack state. Obviously, the present application can determine the abnormal source code that triggers the smart contract transaction according to the preset correspondence, and can modify the transaction according to the abnormal source code, and then execute the modified transaction on the same Ethereum virtual machine as before the transaction modification, so as to verify whether the modified transaction can be executed successfully.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of blockchain technology, and more specifically, to a method, device, equipment and readable storage medium for maintaining abnormal smart contract transactions. Background Art

[0002] In recent years, decentralized application smart contracts based on blockchain have received more and more attention. Ethereum is one of the most popular smart contract platforms. Smart contracts on Ethereum are executed on the Ethereum virtual machine. Users can call smart contracts on Ethereum in the form of transactions by paying a certain fee. When the transaction fails, the fee paid by the user will not be refunded. Since the transaction still needs to pay the fee when the transaction fails, these transactions have caused certain losses to users and hindered the development of smart contracts.

[0003] Currently, most of the research on smart contracts on Ethereum focuses on vulnerability detection, fuzz testing tools, static analysis, etc. These studies are all based on the smart contract itself to detect possible vulnerabilities, and are more inclined to the preventive role before smart contract transactions. They lack abnormal location and repair methods after the transaction occurs abnormally.

[0004] Therefore, how to locate and repair smart contract transaction anomalies is an issue worthy of study. Summary of the invention

[0005] In view of this, the present application provides a smart contract transaction anomaly maintenance method, device, equipment and readable storage medium for locating and repairing smart contract transaction anomalies.

[0006] In order to achieve the above objectives, the proposed solution is as follows:

[0007] A method for maintaining abnormal smart contract transactions, comprising:

[0008] Record the current stack status of the Ethereum virtual machine;

[0009] Tracking the transaction process of the smart contract on the Ethereum virtual machine to obtain transaction information of the transaction;

[0010] When the transaction is completed, determining whether the transaction is executed abnormally;

[0011] If yes, determining the abnormal source code corresponding to the abnormal program counter value contained in the transaction information according to the correspondence between the preset program counter value and the source code of the smart contract;

[0012] Modify relevant parameters of the transaction according to the abnormal source code;

[0013] Executing the modified transaction on the same Ethereum virtual machine as the stack state.

[0014] Preferably, the process of establishing the correspondence between the value of the program counter and the source code of the smart contract includes:

[0015] Compile the smart contract to obtain a contract assembly code, wherein the contract assembly code includes: a plurality of bytecode instructions, an instruction value of each bytecode instruction, and a correspondence between each bytecode instruction and a source code of the smart contract;

[0016] Obtaining a value of a program counter corresponding to each of the bytecode instructions according to the instruction value and the initial value of the program counter;

[0017] According to the correspondence between each of the bytecode instructions and the source code of the smart contract, the correspondence between the value of each of the program counters and the source code of the smart contract is determined.

[0018] Preferably, modifying the relevant parameters of the transaction according to the abnormal source code includes:

[0019] Determining, according to the abnormal source code, that the abnormal type of the transaction is insufficient gas fee;

[0020] Adjust the gas fee allowed to be consumed by the account initiating the transaction in the Ethereum virtual machine so that the gas fee allowed to be consumed is greater than the gas fee required for the transaction contained in the transaction information;

[0021] or,

[0022] Determining, according to the abnormal source code, that the abnormal type of the transaction is an abnormal execution of a bytecode instruction of the smart contract;

[0023] Determine, according to the value of the abnormal program counter, stack information of the bytecode instruction corresponding to the value of the abnormal program counter;

[0024] Modify relevant parameters of the transaction according to the first two elements at the top of the stack information.

[0025] Preferably, the step of modifying the relevant parameters of the transaction according to the first two elements at the top of the stack information includes:

[0026] Matching the first top element and the second top element of the stack with the relevant parameters of the transaction respectively, to obtain a first transaction parameter that matches the first top element of the stack in the relevant parameters of the transaction, and / or a second transaction parameter that matches the second top element of the stack in the relevant parameters of the transaction, wherein the first top element and the second top element of the stack are the first two elements of the stack;

[0027] Modify the first transaction parameter or the second transaction parameter so that the logical relationship between the first transaction parameter and the second stack top element, or the second transaction parameter and the first stack top element, is consistent with the logical relationship between the operators included in the exception source code.

[0028] Preferably, executing the modified transaction on the same Ethereum virtual machine as the current state comprises:

[0029] Create a new Ethereum virtual machine according to the current state;

[0030] The modified transaction is executed on the newly created Ethereum virtual machine.

[0031] Preferably, it also includes:

[0032] If the modified transaction is successfully executed, the abnormal source code and its location in the smart contract, as well as modification suggestions are output, and the modification suggestions include: how to modify the relevant parameters of the transaction;

[0033] If the modified transaction is executed abnormally, the abnormal source code location and its location in the smart contract are output.

[0034] A smart contract transaction abnormality maintenance device, comprising:

[0035] The stack record unit is used to record the current stack state of the Ethereum virtual machine;

[0036] A transaction tracking unit, used to track the transaction process of the smart contract on the Ethereum virtual machine and obtain transaction information of the transaction;

[0037] An abnormality judgment unit, used for judging whether the transaction is executed abnormally after the transaction is completed;

[0038] an abnormal source code determining unit, configured to determine, if the transaction is executed abnormally, the abnormal source code corresponding to the abnormal program counter value contained in the transaction information according to the correspondence between the preset program counter value and the source code of the smart contract;

[0039] A transaction modification unit, used to modify relevant parameters of the transaction according to the abnormal source code;

[0040] A transaction re-execution unit is used to execute the modified transaction on the Ethereum virtual machine with the same stack state.

[0041] Preferably, the abnormal source code determining unit includes a correspondence establishing unit, which is used to establish a correspondence between the value of the program counter and the source code of the smart contract, and the correspondence establishing unit includes:

[0042] A contract compiling unit, used to compile the smart contract to obtain a contract assembly code, wherein the contract assembly code includes: a plurality of bytecode instructions, an instruction value of each bytecode instruction, and a correspondence between each bytecode instruction and a source code of the smart contract;

[0043] a program counter value determination unit, configured to obtain a value of a program counter corresponding to each of the bytecode instructions according to the instruction value and the initial value of the program counter;

[0044] A correspondence determination unit is used to determine the correspondence between the value of each program counter and the source code of the smart contract according to the correspondence between each bytecode instruction and the source code of the smart contract.

[0045] A smart contract transaction abnormality maintenance device, comprising a memory and a processor;

[0046] The memory is used to store programs;

[0047] The processor is used to execute the program to implement the various steps of the above-mentioned smart contract transaction abnormality maintenance method.

[0048] A readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, each step of the above-mentioned smart contract transaction abnormality maintenance method is implemented.

[0049] It can be seen from the above scheme that the smart contract transaction abnormality maintenance method provided by this application includes: recording the current stack state of the Ethereum virtual machine; tracking the transaction process of the smart contract on the Ethereum virtual machine to obtain the transaction information of the transaction; when the transaction is completed, judging whether the transaction is executed abnormally; if so, determining the abnormal source code corresponding to the abnormal program counter value contained in the transaction information according to the correspondence between the preset program counter value and the source code of the smart contract; modifying the relevant parameters of the transaction according to the abnormal source code; executing the modified transaction on the Ethereum virtual machine with the same stack state. Obviously, this application can determine the source code that causes the smart contract transaction abnormality according to the correspondence between the preset program counter value and the source code of the smart contract, and can modify the smart contract transaction according to the abnormal source code, and then execute the modified transaction on the same Ethereum virtual machine before the transaction modification to verify whether the modified transaction can be executed successfully. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0051] Figure 1 A flowchart of a method for maintaining abnormal smart contract transactions provided in an embodiment of the present application;

[0052] Figure 2 A schematic diagram of the structure of a smart contract transaction abnormality maintenance device disclosed in an embodiment of the present application;

[0053] Figure 3 This is a hardware structure block diagram of a smart contract transaction abnormality maintenance device disclosed in an embodiment of the present application. DETAILED DESCRIPTION

[0054] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0055] Next, we will introduce the abnormal maintenance method of smart contract transactions in this application in detail. Please refer to Figure 1 , Figure 1 The following is a flow chart of a method for maintaining abnormal smart contract transactions provided in an embodiment of the present application, the method comprising:

[0056] Step S100: Record the current stack state of the Ethereum virtual machine.

[0057] Specifically, it is possible to record the stack state of the Ethereum virtual machine before the smart contract transaction is executed on the Ethereum virtual machine.

[0058] Step S110: Track the transaction process of the smart contract on the Ethereum virtual machine to obtain transaction information of the transaction.

[0059] Specifically, it can track and record the basic information of the transaction account on the Ethereum virtual machine and related information during the transaction execution process.

[0060] The basic information of the transaction account introduced above may include: transaction initiation address (tx_from), transaction target address (tx_to), gas fee (gas), gas fee unit price (gas_price), transaction parameters (calldata), block number and other information.

[0061] Relevant information during the transaction execution process may include: the value of each program counter (PC value), the operation instructions obtained after the smart contract source code is compiled, the gas fee consumption, the stack status and other information.

[0062] Step S120: After the transaction is completed, determine whether the transaction is executed abnormally. If the transaction is executed abnormally, execute step S130.

[0063] Specifically, whether the transaction is abnormal can be determined based on the various PC values ​​introduced in the above step 110. If the transaction is abnormal, the PC value corresponding to the abnormality will be marked with an abnormal flag. By judging whether each PC value obtained by tracking is marked with an abnormal flag, it can be determined whether the transaction is abnormal.

[0064] Step S130: Determine the abnormal source code corresponding to the abnormal program counter value contained in the transaction information according to the corresponding relationship between the preset program counter value and the source code of the smart contract.

[0065] Specifically, the value of the program counter, i.e., the PC value, can be pre-correlated with the source code of the smart contract, and then, based on the correspondence, the abnormal source code corresponding to the PC value marked with an abnormal identifier contained in the tracked transaction information can be determined.

[0066] Step S140: modify relevant parameters of the transaction according to the abnormal source code.

[0067] Specifically, the relevant parameters of the transaction can be modified according to the reason why the abnormal source code causes the abnormal transaction execution, so as to make the modified transaction execute successfully as much as possible.

[0068] Step S150: Execute the modified transaction on the Ethereum virtual machine with the same stack state.

[0069] Specifically, the modified transaction can be executed on an Ethereum virtual machine with the same stack state as before the transaction was executed.

[0070] It can be seen from the above scheme that the embodiment of the present application can determine the abnormal source code that triggers the smart contract transaction according to the preset corresponding relationship, and can modify the transaction according to the abnormal source code, and then execute the modified transaction on the same Ethereum virtual machine as before the transaction was modified, so as to verify whether the modified transaction can be executed successfully.

[0071] In some embodiments of the application, the above-mentioned step S130 is introduced, and the process of determining the abnormal source code corresponding to the abnormal program counter value contained in the transaction information is carried out according to the correspondence between the preset program counter value and the source code of the smart contract. Next, the process of establishing the correspondence between the program counter value and the smart contract source code will be introduced.

[0072] Specifically, the process may include the following steps:

[0073] S1. Compile the smart contract to obtain a contract combination code, where the contract combination code includes: multiple bytecode instructions, an instruction value of each bytecode instruction, and a corresponding relationship between each bytecode instruction and the source code of the smart contract.

[0074] Specifically, smart contracts can be written in different languages. Here, a smart contract written in solidity is taken as an example. The smart contract can be compiled first to obtain a compilation result, which can include: contract bytecode (Bytecode) and contract assembly code (Assmbly Code), where the contract assembly code can include: bytecode instructions, instruction values ​​of bytecode instructions, and source codes corresponding to bytecode instructions in the smart contract.

[0075] S2. Obtain the value of the program counter corresponding to each of the bytecode instructions according to the instruction value and the initial value of the program counter.

[0076] Specifically, since each instruction value may be different, the PC value corresponding to the obtained bytecode instruction may also be different.

[0077] Next, the process of determining each PC value is introduced by taking the contract assembly code (Assmbly Code) of the above step S1 as an example.

[0078] Specifically, according to the definition of bytecode instructions on the Ethereum virtual machine, the offset value corresponding to each bytecode instruction in the Assembly Code can be obtained. The initial value of PC can be 0. According to the offset value of the bytecode instruction, the initial value of PC is accumulated to obtain the PC value corresponding to each bytecode instruction in the Assembly Code. For example, the first two bytecode instructions of a contract are push1 and push2. The offset value of push1 instruction is 2, and the offset value of push2 instruction is 3. Then the PC value corresponding to push1 is 0, and the PC value corresponding to push2 is 2.

[0079] S3. Determine the correspondence between the value of each program counter and the source code of the smart contract according to the correspondence between each bytecode instruction and the source code of the smart contract.

[0080] Specifically, the correspondence between each PC value and the source code of the smart contract can be determined based on the correspondence between each bytecode instruction compiled in the above step S1 and the source code of the smart contract, and the correspondence between each bytecode instruction and the PC value calculated in the above step S2.

[0081] In some embodiments of the application, the above-mentioned step S140 is introduced, and the process of modifying the relevant parameters of the transaction according to the abnormal source code is further explained below.

[0082] Specifically, the process can determine relevant parameters of different transactions according to different types of transaction anomalies, including the following steps:

[0083] Case 1: According to the abnormal source code, it is determined that the abnormal type of the transaction is insufficient gas fee.

[0084] In such cases, the gas fee allowed to be consumed by the account initiating the transaction in the Ethereum virtual machine is adjusted so that the gas fee allowed to be consumed is greater than the gas fee required for the transaction contained in the transaction information.

[0085] Specifically, the relevant information obtained during the transaction execution process can be tracked to adjust the gas fee allowed to be consumed by the Ethereum virtual machine transaction initiating account so that it is greater than the gas fee required for normal transaction execution.

[0086] Case 2: According to the abnormal source code, it is determined that the abnormal type of the transaction is an abnormal execution of the bytecode instruction of the smart contract.

[0087] S21. Determine, according to the value of the abnormal program counter, stack information of the bytecode instruction corresponding to the value of the abnormal program counter.

[0088] Specifically, the abnormal bytecode instruction may be determined according to the abnormal PC value, and then the stack information of the abnormal bytecode instruction may be determined.

[0089] S22: Modify relevant parameters of the transaction according to the first two elements at the top of the stack information.

[0090] Specifically, the transaction can be modified according to the first two elements at the top of the stack information and the relevant parameters obtained by tracing the transaction.

[0091] In some embodiments of the present application, the above-mentioned step S22 is introduced, and the process of modifying the relevant parameters of the transaction according to the first two elements at the top of the stack information is introduced. This process can perform dynamic transaction repair on the relevant transactions containing the three operators of less than, equal to, and greater than in the abnormal source code. The process will be further explained below.

[0092] Specifically, the exception source code may include a binary operator, wherein the binary operator has two operands corresponding to the first top element and the second top element of the stack. The process may include the following steps:

[0093] S221. Match the first top element and the second top element with the relevant parameters of the transaction respectively to obtain a first transaction parameter that matches the first top element in the relevant parameters of the transaction, and / or a second transaction parameter that matches the second top element in the relevant parameters of the transaction, wherein the first top element and the second top element are the first two elements at the top of the stack.

[0094] Specifically, the first two elements at the top of the stack can be matched with the transaction parameters (calldata) in the relevant parameters of the transaction and the Ethereum information related to the transaction account, and different matching results can be obtained according to different situations, wherein the matching results may include: only obtaining the first transaction parameter that matches the first top element of the stack, or only obtaining the second transaction parameter that matches the second top element of the stack, or simultaneously obtaining the first transaction parameter that matches the first top element of the stack and the second transaction parameter that matches the second top element of the stack.

[0095] S222. Modify the first transaction parameter or the second transaction parameter so that the logical relationship between the first transaction parameter and the second top element of the stack, or the logical relationship between the second transaction parameter and the first top element of the stack is consistent with the logical relationship of the operator included in the exception source code.

[0096] Specifically, one or two elements at the top of the stack may be modified accordingly according to the operator included in the exception source code and the matching result of the above steps.

[0097] Next, we will use a specific example to introduce the process of modifying transaction related parameters.

[0098] a) For the case of a less than symbol, where the less than symbol includes: unsigned less than and signed less than, when the first two elements on the top of the stack on the Ethereum virtual machine match the transaction parameters or transaction account related information, adjust the parameters of the top element of the two stack top elements that match. For example: if the first top element matches, adjust its corresponding matching value to make it less than the second top element; if the second top element matches, adjust its corresponding matching value to make it greater than the first top element.

[0099] b) For the case of the equal symbol, the first top element of the stack needs to be successfully matched with the second top element of the stack. If either the first top element or the second top element of the stack matches the transaction parameters or the transaction account related information, the matching parameter corresponding to the matched top element of the stack can be modified to make the matching parameter the same as the other top element of the stack.

[0100] c) For the greater than symbol case, where the greater than symbol includes: unsigned greater than and signed greater than, it is necessary to satisfy that the first top element is greater than the second top element. In this case, the parameters of the top element that matches between the two top elements can be adjusted. For example: if the first top element matches, adjust its corresponding matching value to make it greater than the second top element; if the second top element matches, adjust its corresponding matching value to make it less than the first top element.

[0101] In order to let users know about the relevant circumstances of the transaction abnormality, the embodiment of the present application may also add a process of outputting the relevant circumstances of the transaction abnormality.

[0102] Specifically, the process may include the following steps:

[0103] Case 1: If the modified transaction is successfully executed, the abnormal source code and its location in the smart contract, as well as modification suggestions are output, and the modification suggestions include: how to modify the relevant parameters of the transaction.

[0104] Specifically, the modification method may include a modification method of transaction-related parameters obtained according to the re-execution result of the transaction, wherein the transaction-related parameters may include transaction parameters (calldata), transaction initiator information (sender), gas fee (gas), etc.

[0105] Case 2: If the modified transaction is executed abnormally, output the abnormal source code location and its location in the smart contract.

[0106] Specifically, if a transaction is executed abnormally, the source code that caused the exception and the location of the source code in the smart contract, as well as other information that caused the exception, can be output.

[0107] The following is a description of the smart contract transaction abnormality maintenance device provided in an embodiment of the present application. The smart contract transaction abnormality maintenance device described below and the smart contract transaction abnormality maintenance method described above can be referenced to each other.

[0108] First, combine Figure 2 Introduce the abnormal maintenance device for smart contract transactions, such as Figure 2 As shown, the smart contract transaction abnormality maintenance device may include:

[0109] A stack recording unit 100, used to record the current stack state of the Ethereum virtual machine;

[0110] The transaction tracking unit 110 is used to track the transaction process of the smart contract on the Ethereum virtual machine and obtain the transaction information of the transaction;

[0111] The abnormality judgment unit 120 is used to judge whether the transaction is abnormal after the transaction is completed;

[0112] The abnormal source code determining unit 130 is used to determine the abnormal source code corresponding to the abnormal program counter value contained in the transaction information according to the correspondence between the preset program counter value and the source code of the smart contract if the transaction is executed abnormally;

[0113] A transaction modification unit 140, configured to modify relevant parameters of the transaction according to the abnormal source code;

[0114] The transaction re-execution unit 150 is used to execute the modified transaction on the Ethereum virtual machine with the same stack state.

[0115] Optionally, the abnormal source code determining unit 130 may include a correspondence establishing unit, which is used to establish a correspondence between the value of the program counter and the source code of the smart contract. The correspondence establishing unit may include:

[0116] A contract compiling unit, used to compile the smart contract to obtain a contract assembly code, wherein the contract assembly code includes: a plurality of bytecode instructions, an instruction value of each bytecode instruction, and a correspondence between each bytecode instruction and a source code of the smart contract;

[0117] a program counter value determination unit, configured to obtain a value of a program counter corresponding to each of the bytecode instructions according to the instruction value and the initial value of the program counter;

[0118] A correspondence determination unit is used to determine the correspondence between the value of each program counter and the source code of the smart contract according to the correspondence between each bytecode instruction and the source code of the smart contract.

[0119] Optionally, the transaction modification unit 140 may include:

[0120] A first abnormality determination unit, configured to determine, according to the abnormality source code, that the abnormality type of the transaction is insufficient gas fee;

[0121] A first transaction-related parameter modification unit, configured to adjust the gas fee allowed to be consumed by the account initiating the transaction in the Ethereum virtual machine, so that the gas fee allowed to be consumed is greater than the gas fee required for the transaction contained in the transaction information;

[0122] or,

[0123] A second exception determination unit, configured to determine, according to the exception source code, that the exception type of the transaction is an exception in the execution of a bytecode instruction of the smart contract;

[0124] an exception stack determination unit, configured to determine, according to the value of the program counter of the exception, stack information of the bytecode instruction corresponding to the value of the program counter of the exception;

[0125] The relevant parameter modification unit of the second transaction is used to modify the relevant parameters of the transaction according to the first two elements at the top of the stack information.

[0126] Optionally, the relevant parameter modification unit of the second transaction may include:

[0127] a stack top element matching unit, used to match the first stack top element and the second stack top element with the relevant parameters of the transaction respectively, to obtain a first transaction parameter that matches the first stack top element in the relevant parameters of the transaction, and / or a second transaction parameter that matches the second stack top element in the relevant parameters of the transaction, wherein the first stack top element and the second stack top element are the first two elements at the top of the stack;

[0128] A transaction parameter modification unit is used to modify the first transaction parameter or the second transaction parameter so that the logical relationship between the first transaction parameter and the second stack top element, or the second transaction parameter and the first stack top element is consistent with the logical relationship of the operator included in the exception source code.

[0129] Optionally, the transaction re-execution unit 150 may include:

[0130] A virtual machine creation unit, used to create a new Ethereum virtual machine according to the current state;

[0131] The new transaction execution unit is used to execute the modified transaction in the newly created Ethereum virtual machine.

[0132] Optionally, the smart contract transaction abnormality maintenance device may further include:

[0133] A modification success prompt unit, used for outputting the abnormal source code and its location in the smart contract, as well as modification suggestions if the modified transaction is successfully executed, wherein the modification suggestions include: a method for modifying relevant parameters of the transaction;

[0134] The modification failure prompt unit is used to output the abnormal source code location and its location in the smart contract if the modified transaction is executed abnormally.

[0135] The smart contract transaction abnormality maintenance device provided in the embodiment of the present application can be applied to smart contract transaction abnormality maintenance equipment. Figure 3 The hardware structure diagram of the smart contract transaction abnormality maintenance device is shown. Figure 3,The hardware structure of the smart contract transaction abnormality maintenance device may include: at least one processor 1, at least one communication interface 2, at least one memory 3 and at least one communication bus 4;

[0136] In the embodiment of the present application, the number of the processor 1, the communication interface 2, the memory 3, and the communication bus 4 is at least one, and the processor 1, the communication interface 2, and the memory 3 communicate with each other through the communication bus 4;

[0137] The processor 1 may be a central processing unit CPU, or an application-specific integrated circuit ASIC (Application Specific Integrated Circuit), or one or more integrated circuits configured to implement the embodiments of the present invention, etc.;

[0138] The memory 3 may include a high-speed RAM memory, and may also include a non-volatile memory, such as at least one disk memory;

[0139] The memory stores a program, and the processor can call the program stored in the memory, wherein the program is used to:

[0140] Record the current stack status of the Ethereum virtual machine;

[0141] Tracking the transaction process of the smart contract on the Ethereum virtual machine to obtain transaction information of the transaction;

[0142] When the transaction is completed, determining whether the transaction is executed abnormally;

[0143] If yes, determining the abnormal source code corresponding to the abnormal program counter value contained in the transaction information according to the correspondence between the preset program counter value and the source code of the smart contract;

[0144] Modify relevant parameters of the transaction according to the abnormal source code;

[0145] Executing the modified transaction on the same Ethereum virtual machine as the stack state.

[0146] Optionally, the detailed functions and extended functions of the program may refer to the above description.

[0147] The embodiment of the present application further provides a storage medium, which may store a program suitable for execution by a processor, wherein the program is used to:

[0148] Record the current stack status of the Ethereum virtual machine;

[0149] Tracking the transaction process of the smart contract on the Ethereum virtual machine to obtain transaction information of the transaction;

[0150] When the transaction is completed, determining whether the transaction is executed abnormally;

[0151] If yes, determining the abnormal source code corresponding to the abnormal program counter value contained in the transaction information according to the correspondence between the preset program counter value and the source code of the smart contract;

[0152] Modify relevant parameters of the transaction according to the abnormal source code;

[0153] Executing the modified transaction on the same Ethereum virtual machine as the stack state.

[0154] Optionally, the detailed functions and extended functions of the program may refer to the above description.

[0155] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0156] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0157] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for maintaining abnormal smart contract transactions, characterized in that: include: Record the current stack status of the Ethereum virtual machine; Tracking the transaction process of the smart contract on the Ethereum virtual machine to obtain transaction information of the transaction; When the transaction is completed, determining whether the transaction is executed abnormally; If yes, determining the abnormal source code corresponding to the abnormal program counter value contained in the transaction information according to the correspondence between the preset program counter value and the source code of the smart contract; Modify relevant parameters of the transaction according to the abnormal source code; Executing the modified transaction on the same Ethereum virtual machine as the stack state; The process of establishing the corresponding relationship between the value of the program counter and the source code of the smart contract includes: Compile the smart contract to obtain a contract assembly code, wherein the contract assembly code includes: a plurality of bytecode instructions, an instruction value of each bytecode instruction, and a correspondence between each bytecode instruction and a source code of the smart contract; Obtaining a value of a program counter corresponding to each of the bytecode instructions according to the instruction value and the initial value of the program counter; Determine the correspondence between the value of each program counter and the source code of the smart contract according to the correspondence between each bytecode instruction and the source code of the smart contract; Wherein, modifying the relevant parameters of the transaction according to the abnormal source code includes: Determining, according to the abnormal source code, that the abnormal type of the transaction is insufficient gas fee; Adjust the gas fee allowed to be consumed by the account initiating the transaction in the Ethereum virtual machine so that the gas fee allowed to be consumed is greater than the gas fee required for the transaction contained in the transaction information; or, Determining, according to the abnormal source code, that the abnormal type of the transaction is an abnormal execution of a bytecode instruction of the smart contract; Determine, according to the value of the abnormal program counter, stack information of the bytecode instruction corresponding to the value of the abnormal program counter; Matching the first top element and the second top element with the relevant parameters of the transaction respectively, to obtain a first transaction parameter that matches the first top element in the relevant parameters of the transaction, and / or a second transaction parameter that matches the second top element in the relevant parameters of the transaction, wherein the first top element and the second top element are the first two elements at the top of the stack information; Modify the first transaction parameter or the second transaction parameter so that the logical relationship between the first transaction parameter and the second stack top element, or the second transaction parameter and the first stack top element, is consistent with the logical relationship between the operators included in the exception source code.

2. The method according to claim 1, characterized in that Executing the modified transaction on the same Ethereum virtual machine as the current state includes: Create a new Ethereum virtual machine according to the current state; The modified transaction is executed on the newly created Ethereum virtual machine.

3. The method according to claim 1, characterized in that Also includes: If the modified transaction is successfully executed, the abnormal source code and its location in the smart contract, as well as modification suggestions are output, and the modification suggestions include: how to modify the relevant parameters of the transaction; If the modified transaction is executed abnormally, the abnormal source code location and its location in the smart contract are output.

4. A smart contract transaction abnormality maintenance device, characterized in that: include: The stack record unit is used to record the current stack state of the Ethereum virtual machine; A transaction tracking unit, used to track the transaction process of the smart contract on the Ethereum virtual machine and obtain transaction information of the transaction; An abnormality judgment unit, used for judging whether the transaction is executed abnormally after the transaction is completed; an abnormal source code determining unit, configured to determine, if the transaction is executed abnormally, the abnormal source code corresponding to the abnormal program counter value contained in the transaction information according to the correspondence between the preset program counter value and the source code of the smart contract; A transaction modification unit, used to modify relevant parameters of the transaction according to the abnormal source code; A transaction re-execution unit, used to execute the modified transaction on an Ethereum virtual machine with the same stack state; The abnormal source code determining unit includes a corresponding relationship establishing unit, which is used to establish a corresponding relationship between the value of the program counter and the source code of the smart contract, and the corresponding relationship establishing unit includes: A contract compiling unit, used to compile the smart contract to obtain a contract assembly code, wherein the contract assembly code includes: a plurality of bytecode instructions, an instruction value of each bytecode instruction, and a correspondence between each bytecode instruction and a source code of the smart contract; a program counter value determination unit, configured to obtain a value of a program counter corresponding to each of the bytecode instructions according to the instruction value and the initial value of the program counter; A correspondence determination unit, configured to determine a correspondence between the value of each program counter and the source code of the smart contract according to the correspondence between each bytecode instruction and the source code of the smart contract; Wherein, the transaction modification unit includes: A first abnormality determination unit, configured to determine, according to the abnormality source code, that the abnormality type of the transaction is insufficient gas fee; A first transaction-related parameter modification unit, configured to adjust the gas fee allowed to be consumed by the account initiating the transaction in the Ethereum virtual machine, so that the gas fee allowed to be consumed is greater than the gas fee required for the transaction contained in the transaction information; or, A second exception determination unit, configured to determine, according to the exception source code, that the exception type of the transaction is an exception in the execution of a bytecode instruction of the smart contract; an exception stack determination unit, configured to determine, according to the value of the program counter of the exception, stack information of the bytecode instruction corresponding to the value of the program counter of the exception; The relevant parameter modification unit of the second transaction specifically includes: a stack top element matching unit, used to match the first stack top element and the second stack top element with the relevant parameters of the transaction respectively, to obtain a first transaction parameter that matches the first stack top element in the relevant parameters of the transaction, and / or a second transaction parameter that matches the second stack top element in the relevant parameters of the transaction, wherein the first stack top element and the second stack top element are the first two elements at the top of the stack information; A transaction parameter modification unit is used to modify the first transaction parameter or the second transaction parameter so that the logical relationship between the first transaction parameter and the second stack top element, or the second transaction parameter and the first stack top element is consistent with the logical relationship of the operator included in the exception source code.

5. A smart contract transaction abnormality maintenance device, characterized in that: including memory and processor; The memory is used to store programs; The processor is used to execute the program to implement each step of the smart contract transaction abnormality maintenance method as claimed in any one of claims 1 to 3.

6. A readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, each step of the smart contract transaction abnormality maintenance method as claimed in any one of claims 1 to 3 is implemented.

Citation Information

Patent Citations

  • An exception handling method working in a hybrid mode execution engine

    CN102262537A

  • Intelligent contract processing method and device based on Ethernet virtual machine

    CN109034814A