Smart contract deployment method, execution method, device and terminal equipment
By calculating and storing the execution consumption of smart contract boundary instructions, the problem of low measurement efficiency of smart contract bytecode execution consumption in the prior art is solved, and rapid and efficient evaluation of resource consumption and improvement of execution stability is achieved.
Patent Information
- Application Number
- CN202011586959.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-28
- Publication Date
- 2024-11-29
- Estimated Expiration
- 2040-12-28
AI Technical Summary
The prior art methods for measuring bytecode execution of smart contracts are inefficient, making it difficult to quickly and efficiently evaluate and control resource consumption.
By reading the boundary instructions in the smart contract, the execution consumption of the corresponding program block is calculated, and the consumption is accumulated during the execution process, and the calculation bytecode is stored as execution consumption, so as to directly calculate the execution consumption of the boundary instructions and avoid one by one calculation Instruction consumption.
It realizes a fast and efficient measurement of resource consumption during smart contract execution, improves execution stability, and avoids unnecessary execution caused by consumption exceeding the threshold.
Smart Images

Figure CN112631729B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a deployment method, execution method, apparatus and terminal device of a smart contract. Background Art
[0002] With the rapid development of computer technology, smart contracts have been increasingly used. A smart contract is an event-driven, stateful program that runs on a replicated and shareable ledger and can keep assets on the ledger. In other words, a smart contract is a programmed contract that is automatically executed when preset conditions are met. For example, smart contracts can be deployed in blockchain systems.
[0003] Usually, in the process of executing a smart contract, the bytecode of the smart contract can be loaded and run by a virtual machine. When executing the bytecode of a smart contract, there will be execution consumption (i.e., gas), which is the computing resource required to provide computing power for the smart contract. The current method of measuring the execution consumption of the bytecode of a smart contract is inefficient. Summary of the invention
[0004] The embodiments of the present application provide a deployment method, execution method, apparatus, terminal device and storage medium for a smart contract, aiming to solve the problem of low efficiency of existing methods for measuring the execution consumption of bytecodes of smart contracts.
[0005] In a first aspect, an embodiment of the present application provides a method for deploying a smart contract, including:
[0006] When receiving a request instruction to deploy the smart contract, reading the bytecode instructions in the smart contract in sequence;
[0007] When the bytecode instruction in the smart contract read is a boundary instruction, calculating the first consumption of the program block corresponding to the boundary instruction; wherein the boundary instruction includes a start instruction and an end instruction indicating that the bytecode instruction is a branch execution instruction or a loop execution instruction;
[0008] Associating the first consumption with a preset instruction to obtain an execution consumption calculation bytecode of a program block corresponding to the boundary instruction;
[0009] The execution consumption calculation bytecode is associated with the boundary instruction for storage, so that the smart contract executes the execution consumption calculation bytecode to obtain the first execution consumption of the program block corresponding to the boundary instruction during the execution of the boundary instruction;
[0010] When all bytecode instructions in the smart contract have been read, it is determined that the bytecode instructions of the smart contract have been processed.
[0011] In one embodiment, when the bytecode instruction in the smart contract read is a boundary instruction, calculating the first consumption of the program block corresponding to the boundary instruction includes:
[0012] When the bytecode instruction in the smart contract read is a boundary instruction, the execution consumption of each instruction in the program block corresponding to the boundary instruction is accumulated to obtain the first consumption.
[0013] In one embodiment, the storing of the execution consumption calculation bytecode in association with the boundary instruction so that the smart contract executes the execution consumption calculation bytecode to obtain the first execution consumption of the program block corresponding to the boundary instruction during the execution of the boundary instruction comprises: storing the execution consumption calculation bytecode in association with the boundary instruction so that during the execution of the smart contract, each time the execution of the boundary instruction is detected, the first consumption associated with the boundary instruction is accumulated once to the first execution consumption to update the first execution consumption;
[0014] Among them, the first consumption is the consumption required for executing the boundary instruction once, which is calculated and stored when the smart contract is deployed, and the first execution consumption is the total execution consumption of the program block corresponding to the boundary instruction calculated according to the number of executions of the boundary instruction and the first consumption when executing the smart contract.
[0015] In a second aspect, an embodiment of the present application provides a method for executing a smart contract, including:
[0016] When receiving a request instruction to execute a deployed smart contract, obtain the instruction consumption threshold;
[0017] When the currently executed bytecode instruction is a boundary instruction, the execution consumption calculation bytecode associated with the boundary instruction is executed to obtain the first execution consumption of the program block corresponding to the boundary instruction; wherein the boundary instruction includes a start instruction and an end instruction indicating that the bytecode instruction is a branch execution instruction or a loop execution instruction, and the execution consumption calculation bytecode is an executable program obtained by calculating the first consumption association preset instruction of the program block corresponding to the boundary instruction during the smart contract deployment process;
[0018] Obtain a second execution cost, and add the second execution cost to the first execution cost to obtain a third execution cost; wherein the second execution cost is the total execution cost of all bytecode instructions executed before the current boundary instruction;
[0019] When it is detected that the third execution consumption is greater than the instruction consumption threshold, the execution of the smart contract is exited.
[0020] In one embodiment, executing the execution cost calculation bytecode associated with the boundary instruction to obtain the first execution cost of the program block corresponding to the boundary instruction includes:
[0021] In the process of executing the execution cost calculation bytecode associated with the boundary instruction, each time it is detected that the execution of the boundary instruction starts, the first cost associated with the boundary instruction is accumulated once to the first execution cost to update the first execution cost;
[0022] Among them, the first consumption is the consumption required for executing the boundary instruction once, which is calculated and stored when the smart contract is deployed, and the first execution consumption is the total execution consumption of the program block corresponding to the boundary instruction calculated according to the number of executions of the boundary instruction and the first consumption when executing the smart contract.
[0023] In one embodiment, the execution method further includes:
[0024] When the currently executed bytecode instruction is a sequential execution instruction, obtaining a fourth execution cost of the sequential execution instruction;
[0025] Obtain a fifth execution cost, and add the fifth execution cost to the fourth execution cost to obtain a sixth execution cost; wherein the fifth execution cost is the total execution cost of all bytecode instructions executed before the currently sequentially executed instruction;
[0026] When it is detected that the sixth execution consumption is greater than the instruction consumption threshold, the execution of the smart contract is exited.
[0027] In a third aspect, the embodiment of the present application provides a deployment device for a smart contract, including:
[0028] A receiving module, configured to read the bytecode instructions in the smart contract in sequence when receiving a request instruction to deploy the smart contract;
[0029] A calculation module, configured to calculate a first consumption of a program block corresponding to a boundary instruction when the bytecode instruction read in the smart contract is a boundary instruction; wherein the boundary instruction includes a start instruction and an end instruction indicating that the bytecode instruction is a branch execution instruction or a loop execution instruction;
[0030] An obtaining module, used for associating the first consumption with a preset instruction, and obtaining an execution consumption calculation bytecode of a program block corresponding to the boundary instruction;
[0031] An association module, used to associate the execution consumption calculation bytecode with the boundary instruction for storage, so that the smart contract executes the execution consumption calculation bytecode to obtain the first execution consumption of the program block corresponding to the boundary instruction during the execution of the boundary instruction;
[0032] The processing completion module is used to determine that the bytecode instructions of the smart contract have been processed when all bytecode instructions in the smart contract have been read.
[0033] In a fourth aspect, an embodiment of the present application provides an execution device of a smart contract, including:
[0034] A first acquisition module is used to acquire an instruction consumption threshold when receiving a request instruction to execute a deployed smart contract;
[0035] A calculation module, configured to execute the execution consumption calculation bytecode associated with the boundary instruction when the currently executed bytecode instruction is a boundary instruction, and obtain the first execution consumption of the program block corresponding to the boundary instruction; wherein the boundary instruction includes a start instruction and an end instruction indicating that the bytecode instruction is a branch execution instruction or a loop execution instruction, and the execution consumption calculation bytecode is an executable program obtained by calculating the first consumption associated with the preset instruction of the program block corresponding to the boundary instruction during the deployment of the smart contract;
[0036] A second acquisition module is used to acquire a second execution cost, and accumulate the second execution cost with the first execution cost to obtain a third execution cost; wherein the second execution cost is the total execution cost of all bytecode instructions executed before the current boundary instruction;
[0037] The first exit module is used to exit the execution of the smart contract when it is detected that the third execution consumption is greater than the instruction consumption threshold.
[0038] In a fifth aspect, an embodiment of the present application provides a terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the smart contract deployment method of the first aspect when executing the computer program; or implements the steps of the smart contract execution method of the second aspect when the processor executes the computer program.
[0039] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the smart contract deployment method of the first aspect are implemented; or when the computer program is executed by a processor, the steps of the smart contract execution method of the second aspect are implemented.
[0040] In the seventh aspect, an embodiment of the present application provides a computer program product. When the computer program product is run on an electronic device, it enables the electronic device to execute the steps of the smart contract deployment method of the above-mentioned first aspect; or enables the electronic device to execute the steps of the smart contract execution method of the above-mentioned second aspect.
[0041] The first aspect of the embodiment of the present application has the beneficial effect compared with the prior art: during the deployment process of the smart contract, if the bytecode instruction read is a boundary instruction, the first consumption of the boundary instruction is calculated, the first consumption is associated with the preset instruction to obtain the execution consumption calculation bytecode of the program block corresponding to the boundary instruction, and the execution consumption calculation bytecode is associated with the boundary instruction for storage. This allows the first execution consumption to be calculated directly according to the execution consumption calculation bytecode associated with the first consumption in the deployment stage during the execution of the smart contract, without the need to calculate the instructions in the program block corresponding to the boundary instruction one by one, and can quickly and efficiently measure resource consumption.
[0042] The second aspect of the embodiment of the present application has the following beneficial effects compared with the prior art: during the execution of a smart contract, when the executed bytecode is a boundary instruction, the execution consumption calculation bytecode associated with the boundary instruction is used to calculate the first execution consumption of the program block corresponding to the boundary instruction; since the execution consumption calculation bytecode is an executable program obtained by associating the first consumption of the program block corresponding to the boundary instruction with the preset instruction during the deployment of the smart contract, the first execution consumption of the program block corresponding to the boundary instruction is obtained directly according to the execution consumption calculation bytecode, and there is no need to calculate the instructions in the program block corresponding to the boundary instruction one by one, so that resource consumption can be measured quickly and efficiently. And the second execution consumption is obtained, and the second execution consumption is accumulated with the first execution consumption to obtain the third execution consumption; wherein the second execution consumption is the total execution consumption of all bytecode instructions executed before the current boundary instruction; when it is detected that the third execution consumption is greater than the instruction consumption threshold, the execution of the smart contract is exited, and when the third execution consumption is greater than the instruction consumption threshold, the execution of the smart contract can be exited, thereby improving the execution stability of the smart contract.
[0043] It can be understood that the beneficial effects of the third to seventh aspects mentioned above can be found in the relevant descriptions in the first or second aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions in the embodiments of the present application, 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 some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0045] Figure 1 It is a flowchart of the deployment method of the smart contract provided in Example 1 of the present application;
[0046] Figure 2 It is a flowchart of the execution method of the smart contract provided in Example 2 of the present application;
[0047] Figure 3 It is a flowchart of the execution method of the smart contract provided in Example 2 of the present application;
[0048] Figure 4 It is a flow chart of a deployment device for a smart contract provided in Example 3 of the present application;
[0049] Figure 5 This is a flow chart of the execution device of the smart contract provided in the fourth embodiment of the present application;
[0050] Figure 6 It is a structural diagram of the terminal device provided in Example 5 of the present application. DETAILED DESCRIPTION
[0051] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may 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 prevent unnecessary details from obstructing the description of the present application.
[0052] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of 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 combinations thereof.
[0053] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0054] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.
[0055] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.
[0056] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0057] The deployment method of the smart contract provided in the embodiment of the present application can be applied to the blockchain node in the blockchain network, and the blockchain node can be a server, a tablet computer, a wearable device, an in-vehicle device, an augmented reality (AR) / virtual reality (VR) device, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), a mobile phone, or other various terminal devices capable of data processing. The embodiment of the present application does not impose any restrictions on the specific type of the device.
[0058] In order to illustrate the technical solution described in this application, the following embodiments are used for illustration.
[0059] Embodiment 1
[0060] See also Figure 1 , a smart contract deployment method provided in an embodiment of the present application includes:
[0061] Step S101, when a request instruction to deploy the smart contract is received, the bytecode instructions in the smart contract are read sequentially.
[0062] Specifically, the request instruction for deploying the smart contract includes multiple bytecode instructions for executing the smart contract. When the request instruction for deploying the smart contract is received, the bytecode instructions in the smart contract are read sequentially for processing. The bytecode instructions may be wasm bytecode instructions.
[0063] Step S102, when the bytecode instruction read in the smart contract is a boundary instruction, calculate the first consumption of the program block corresponding to the boundary instruction; wherein the boundary instruction includes a start instruction and an end instruction indicating that the bytecode instruction is a branch execution instruction or a loop execution instruction.
[0064] Specifically, when the bytecode instruction in the smart contract read is a boundary instruction, the boundary instruction may be a branch execution instruction or a loop execution instruction. The start instruction and the end instruction of the boundary instruction may include multiple instructions, that is, the boundary instruction may correspond to a program block. Therefore, in the process of deploying the smart contract, the execution consumption of all instructions in the program block corresponding to the boundary instruction may be calculated, and the execution consumption of all instructions in the program block corresponding to the boundary instruction is called the first consumption.
[0065] In one embodiment, when the bytecode instruction in the smart contract being read is a boundary instruction, calculating the first consumption of the program block corresponding to the boundary instruction includes: when the bytecode instruction in the smart contract being read is a boundary instruction, accumulating the execution consumption of each instruction in the program block corresponding to the boundary instruction to obtain the first consumption.
[0066] Specifically, when the bytecode instruction in the smart contract read is a boundary instruction, the first consumption of the program block corresponding to the boundary instruction can be calculated by: when calculating a single execution of the boundary instruction, the execution consumption of each instruction in the program block corresponding to the boundary instruction is accumulated to obtain the first consumption. The execution consumption of each instruction can be calculated according to the size of the bytecode occupied by the corresponding instruction.
[0067] Step S103, associating the first consumption with a preset instruction to obtain the execution consumption calculation bytecode of the program block corresponding to the boundary instruction.
[0068] Specifically, the preset instruction is a program pre-set for calculating the execution consumption of the program segment corresponding to the boundary instruction during the smart contract execution phase. The program needs to obtain the first consumption required for the current boundary instruction to execute once, so the first consumption is associated with the preset instruction to generate the corresponding execution consumption calculation bytecode.
[0069] Step S104, the execution consumption calculation bytecode is associated with the boundary instruction for storage, so that the smart contract executes the execution consumption calculation bytecode to obtain the first execution consumption of the program block corresponding to the boundary instruction during the execution of the boundary instruction.
[0070] Specifically, the execution consumption calculation bytecode is associated with the boundary instruction for storage, so that each time the smart contract executes a boundary instruction, the first execution consumption is calculated by first executing the execution consumption bytecode associated with the boundary instruction. For example, the execution consumption calculation bytecode is associated with the boundary instruction for storage, which may be inserted into a preset position before the boundary instruction, and the preset position may be a position between the boundary instruction and the previous instruction of the boundary instruction, so that each time the smart contract executes a boundary instruction, the first execution consumption is calculated by first executing the corresponding execution consumption bytecode. The execution consumption calculation bytecode may be executed during the execution of the smart contract, when the currently executed bytecode instruction is a boundary instruction, and the execution consumption calculation bytecode associated with the boundary instruction is executed to obtain the first execution consumption of the program block corresponding to the boundary instruction. The specific process of executing the execution consumption calculation bytecode associated with the boundary instruction can be that in the process of executing the execution consumption calculation bytecode associated with the boundary instruction, each time the execution of the boundary instruction is detected, the first consumption associated with the boundary instruction is accumulated once to the first execution consumption to update the first execution consumption, the first consumption represents the consumption required for the execution of the boundary instruction once, and the first execution consumption is the total execution consumption of the program block corresponding to the boundary instruction calculated according to the current number of executions of the boundary instruction and the first consumption when executing the smart contract. Therefore, when the smart contract executes the boundary instruction, the execution consumption calculation bytecode can be executed first, and the first execution consumption required by the boundary instruction can be calculated by executing the consumption calculation bytecode.
[0071] In one application scenario, the step implemented by the execution consumption calculation bytecode is to first obtain the single execution consumption of the boundary instruction (that is, the first consumption to be associated as mentioned above, the first consumption of different boundary instructions may be different, so it is necessary to calculate the first consumption of the program block corresponding to the boundary instruction when the bytecode instruction in the read smart contract is a boundary instruction). According to the single execution consumption of the boundary instruction and the current number of executions of the boundary instruction, the current total execution consumption of the boundary instruction (that is, the first execution consumption) can be calculated.
[0072] In one embodiment, the execution consumption calculation bytecode may be an executable program implemented by a wasm bytecode program, and the wasm bytecode program may be specifically implemented by a stack program.
[0073] Specifically, wasm (web assembly) bytecode is a target language developed for browsers. It is independent of various hardware architectures and has high portability and efficient network distribution efficiency. Wasm bytecode has been supported by major mainstream browsers. The target bytecode of smart contracts can be in the form of wasm bytecode, and an independent wasm virtual machine is used to execute the program code of the smart contract. Using wasm bytecode to represent and execute smart contract program code can greatly reduce the size of the target code file and improve the network distribution efficiency of the application because its binary format is highly compact. In addition, the runtime efficiency of wasm bytecode can be close to that of local machine code. At the same time, wasm can provide compilation targets for languages such as C / C++ and Rust, so that applications written in these languages can run in browsers.
[0074] In a specific application scenario, the steps of implementing the execution consumption calculation bytecode through a stack code program may be: first, through a preset first internal instruction (such as implemented by the instruction "EnvGet"), a variable A is obtained from the current execution environment (the variable can be understood as the total execution consumption of the program block corresponding to the first N minus 1 execution boundary instructions when the current boundary instruction is executed for the Nth time), and the variable A is first pushed into the pre-built stack; then, according to the preset first wasm standard instruction (such as implemented by the instruction "I64Const"), a constant B (the constant can be understood as the first consumption obtained above) is pushed into the stack; then, according to the preset second wasm standard instruction (such as implemented by the instruction "I64 Add” to implement) pops two numbers from the stack, adds them and then pushes the result into the stack. At this time, the stack already has variable A and constant B, so the two numbers popped from the stack are variable A and constant B, variable A and constant B are added and then the result is pushed into the stack; finally, a value is popped from the stack and written back to the environment variable by presetting a second internal instruction (such as implemented by the instruction “EnvPet”). At this time, the value in the stack is the result of adding variable A and constant B, and the result of adding variable A and constant B is written back to the environment variable, so that each time the execution of the boundary instruction is detected, the first consumption associated with the boundary instruction is accumulated once to the first execution consumption to update the first execution consumption.
[0075] In one embodiment, the storing of the execution consumption calculation bytecode in association with the boundary instruction so that the smart contract executes the execution consumption calculation bytecode to obtain the first execution consumption of the program block corresponding to the boundary instruction during the execution of the boundary instruction comprises: storing the execution consumption calculation bytecode in association with the boundary instruction so that during the execution of the smart contract, each time the execution of the boundary instruction is detected, the first consumption associated with the boundary instruction is accumulated once to the first execution consumption to update the first execution consumption;
[0076] Among them, the first consumption is the consumption required for executing the boundary instruction once, which is calculated and stored when the smart contract is deployed, and the first execution consumption is the total execution consumption of the program block corresponding to the boundary instruction calculated according to the number of executions of the boundary instruction and the first consumption when executing the smart contract.
[0077] In one embodiment, when the bytecode instruction read in the smart contract is a sequential execution instruction, the execution consumption of the sequential execution instruction is calculated, which is called the fourth execution consumption. The fourth execution consumption is associated with the sequential execution instruction and stored, so that during the execution of the smart contract, when the executed bytecode instruction is a sequential execution instruction, the fourth execution consumption of the sequential execution instruction is directly obtained, the fifth execution consumption is obtained, and the fifth execution consumption is accumulated with the fourth execution consumption to obtain the sixth execution consumption; wherein the fifth execution consumption is the total execution consumption of all bytecode instructions executed before the current sequential execution instruction; when it is detected that the sixth execution consumption is greater than the instruction consumption threshold, the execution of the smart contract is exited, and the instruction consumption threshold is the execution consumption limit indicating the execution of the corresponding smart contract.
[0078] Step S105, when all bytecode instructions in the smart contract have been read, it is determined that the bytecode instructions of the smart contract have been processed.
[0079] Specifically, when all bytecode instructions in the smart contract are read and processed accordingly through the above steps S101 to S104, it is determined that the bytecode instructions of the smart contract have been processed, so that the smart contract execution method provided in this application executes the smart contract deployed using the above deployment method.
[0080] In the embodiment of the present application, during the deployment process of the smart contract, if the bytecode instruction read is a boundary instruction, the first consumption of the boundary instruction is calculated, the first consumption is associated with the preset instruction to obtain the execution consumption calculation bytecode of the program block corresponding to the boundary instruction, and the execution consumption calculation bytecode is associated with the boundary instruction for storage. This allows, during the execution process of the smart contract, the first execution consumption to be calculated directly according to the execution consumption calculation bytecode associated with the first consumption in the deployment phase, without the need to calculate the instructions in the program block corresponding to the boundary instruction one by one, and can quickly and efficiently measure resource consumption.
[0081] Embodiment 2
[0082] The smart contract execution method provided in the embodiment of the present application can be applied to a terminal device on which a smart contract is deployed through the smart contract deployment method of embodiment 1.
[0083] See also Figure 2, a method for executing a smart contract provided in an embodiment of the present application includes:
[0084] Step S201, when receiving a request instruction to execute a deployed smart contract, obtain the instruction consumption threshold.
[0085] Specifically, the above-mentioned deployed smart contract is a smart contract deployed by the deployment method in Example 1, and the request instruction for executing the deployed smart contract includes an instruction consumption threshold, and the instruction consumption threshold represents the execution consumption limit of the corresponding smart contract.
[0086] Step S202: When the currently executed bytecode instruction is a boundary instruction, the execution cost calculation bytecode associated with the boundary instruction is executed to obtain the first execution cost of the program block corresponding to the boundary instruction.
[0087] Among them, the boundary instruction includes a start instruction and an end instruction indicating that the bytecode instruction is a branch execution instruction or a loop execution instruction, and the execution consumption calculation bytecode is an executable program obtained by calculating the first consumption associated preset instruction of the program block corresponding to the boundary instruction during the smart contract deployment process.
[0088] In one embodiment, the executing the execution cost calculation bytecode associated with the boundary instruction to obtain the first execution cost of the program block corresponding to the boundary instruction includes: in the process of executing the execution cost calculation bytecode associated with the boundary instruction, each time the execution of the boundary instruction is detected to start, the first cost associated with the boundary instruction is accumulated once to the first execution cost to update the first execution cost;
[0089] Among them, the first consumption is the consumption required for executing the boundary instruction once, which is calculated and stored when the smart contract is deployed. When the bytecode instruction currently executed is a boundary instruction, the first execution consumption is the total execution consumption of the program block corresponding to the boundary instruction calculated according to the number of executions of the boundary instruction and the first consumption when executing the smart contract.
[0090] Specifically, the same, corresponding or similar parts of the above-mentioned step S202 and the above-mentioned steps S102 to S104 can be specifically referred to the relevant descriptions of steps S102 to S104, which will not be repeated here.
[0091] Step S203, obtaining a second execution cost, and accumulating the second execution cost with the first execution cost to obtain a third execution cost; wherein the second execution cost is the total execution cost of all bytecode instructions executed before the current boundary instruction.
[0092] Specifically, during the execution of the smart contract, the total execution cost of the executed bytecode instructions is continuously accumulated. When the currently executed bytecode instruction is a boundary instruction, the first execution cost of the boundary instruction is calculated first, and the total execution cost of all bytecode instructions executed before the current boundary instruction (called the third execution cost) is added to the first execution cost to measure whether the execution cost of continuing to execute the boundary instruction will be greater than the instruction cost threshold.
[0093] Step S204: when it is detected that the third execution consumption is greater than the instruction consumption threshold, exit the execution of the smart contract.
[0094] Specifically, when it is detected that the third execution consumption is greater than the instruction consumption threshold, it means that it is measured that the execution consumption of continuing to execute the boundary instruction will be greater than the instruction consumption threshold, so the execution of the smart contract is directly exited.
[0095] In one embodiment, see Figure 3 , the execution method further includes:
[0096] Step S301, when the currently executed bytecode instruction is a sequential execution instruction, obtain the fourth execution cost of the sequential execution instruction.
[0097] Specifically, when the bytecode instruction executed to the smart contract is a sequential execution instruction, the execution consumption of the sequential instruction is first obtained, which is called the fourth execution consumption. The fourth execution consumption can be in the process of smart contract deployment, when the bytecode instruction read in the smart contract is a sequential execution instruction, the fourth execution consumption of the sequential execution instruction is calculated, and the fourth execution consumption is associated with the sequential execution instruction and stored, so that the fourth execution consumption can be directly obtained in the process of executing the smart contract; or the fourth execution consumption can also be in the process of executing the smart contract, when the bytecode instruction currently executed is a sequential execution instruction, the fourth execution consumption is calculated according to the size of the bytecode occupied by the sequential execution instruction.
[0098] Step S302, obtaining a fifth execution cost, and accumulating the fifth execution cost with the fourth execution cost to obtain a sixth execution cost; wherein the fifth execution cost is the total execution cost of all bytecode instructions executed before the current sequential execution instruction.
[0099] Specifically, during the execution of the smart contract, the total execution consumption of the executed bytecode instructions is continuously accumulated. When the currently executed bytecode instruction is a sequential execution instruction, the fourth execution consumption of the sequential execution instruction is first obtained, and the total execution consumption of all bytecode instructions executed before the current sequential execution instruction (called the fifth execution consumption) is added to the fourth execution consumption to measure whether the execution consumption of continuing to execute the sequential execution instruction will be greater than the instruction consumption threshold.
[0100] Step S303: when it is detected that the sixth execution consumption is greater than the instruction consumption threshold, exit the execution of the smart contract.
[0101] Specifically, when it is detected that the sixth execution consumption is greater than the instruction consumption threshold, it means that it is measured that the execution consumption of continuing to execute the sequential execution instructions will be greater than the instruction consumption threshold, so the execution of the smart contract is directly exited.
[0102] In a specific application, when it is detected that the third execution consumption is greater than the instruction consumption threshold, the execution of the smart contract is exited, and when it is detected that the sixth execution consumption is greater than the instruction consumption threshold, the execution of the smart contract is exited. This can be specifically implemented through a stack code program: for example, first, by presetting a third internal instruction (such as implemented by the instruction "EnvGet"), a variable C is obtained from the current execution environment (the variable C is the total execution consumption required to execute the current instruction and all instructions before the current instruction. If a boundary instruction is executed, the variable C is the third execution consumption mentioned above; if a sequential execution instruction is executed, the variable C is the sixth execution consumption mentioned above); then, according to the preset third wasm standard instruction (such as implemented by the instruction "I64Const"), the table Push the constant (limit value, i.e. instruction consumption threshold) into the stack; then compare the two values stored on the stack according to the preset fourth wasm standard instruction (such as implemented by instruction I64Ge_U). At this time, the first value on the stack is the instruction consumption threshold, and the second value on the stack is the third execution consumption or the sixth execution consumption. If the first value is greater than the second value, 1 is returned, and if the first value is less than or equal to the second value, 0 is returned, and the return value is pushed into the stack; then according to the preset fifth wasm standard instruction (such as implemented by if), determine whether the top of the stack is 0, which means that the instruction consumption threshold is less than or equal to the third execution consumption or the sixth execution consumption; when the top of the stack is judged to be 0, exit the execution and throw an error through the preset fourth internal instruction (such as implemented by instruction Break). The stack code program can be used to determine whether the current code execution consumption exceeds the execution limit, and stop execution if it exceeds the limit.
[0103] In the embodiment of the present application, during the execution of a smart contract, when the executed bytecode is a boundary instruction, the execution consumption calculation bytecode associated with the boundary instruction is used to calculate the first execution consumption of the program block corresponding to the boundary instruction; since the execution consumption calculation bytecode is an executable program obtained by associating the first consumption of the program block corresponding to the boundary instruction with the preset instruction during the deployment of the smart contract, the first execution consumption of the program block corresponding to the boundary instruction is obtained directly according to the execution consumption calculation bytecode, and there is no need to calculate the instructions in the program block corresponding to the boundary instruction one by one, so that resource consumption can be measured quickly and efficiently. And the second execution consumption is obtained, and the second execution consumption is accumulated with the first execution consumption to obtain the third execution consumption; wherein the second execution consumption is the total execution consumption of all bytecode instructions executed before the current boundary instruction; when it is detected that the third execution consumption is greater than the instruction consumption threshold, the execution of the smart contract is exited, and when the third execution consumption is greater than the instruction consumption threshold, the execution of the smart contract can be exited, thereby improving the execution stability of the smart contract.
[0104] Embodiment 3
[0105] The present application also provides a smart contract deployment device for executing the steps in the smart contract deployment method embodiment. Figure 4 As shown, the smart contract deployment device 400 provided in the embodiment of the present application includes:
[0106] The receiving module 401 is used to read the bytecode instructions in the smart contract in sequence when receiving a request instruction to deploy the smart contract;
[0107] A calculation module 402, configured to calculate a first consumption of a program block corresponding to a boundary instruction when the bytecode instruction read in the smart contract is a boundary instruction; wherein the boundary instruction includes a start instruction and an end instruction indicating that the bytecode instruction is a branch execution instruction or a loop execution instruction;
[0108] Obtaining module 403, used for associating the first consumption with a preset instruction, and obtaining the execution consumption calculation bytecode of the program block corresponding to the boundary instruction;
[0109] An association module 404 is used to associate the execution consumption calculation bytecode with the boundary instruction for storage, so that the smart contract executes the execution consumption calculation bytecode to obtain the first execution consumption of the program block corresponding to the boundary instruction during the execution of the boundary instruction;
[0110] The processing completion module 405 is used to determine that the bytecode instructions of the smart contract have been processed when all bytecode instructions in the smart contract have been read.
[0111] In one embodiment, the calculation module 402 is specifically used to accumulate the execution cost of each instruction in the program block corresponding to the boundary instruction when the bytecode instruction in the smart contract being read is a boundary instruction to obtain the first consumption.
[0112] In one embodiment, the association module is specifically used to: associate the execution consumption calculation bytecode with the boundary instruction for storage, so that during the execution process of the smart contract, each time the execution of the boundary instruction is detected, the first consumption associated with the boundary instruction is accumulated once to the first execution consumption to update the first execution consumption;
[0113] Among them, the first consumption is the consumption required for executing the boundary instruction once, which is calculated and stored when the smart contract is deployed, and the first execution consumption is the total execution consumption of the program block corresponding to the boundary instruction calculated according to the number of executions of the boundary instruction and the first consumption when executing the smart contract.
[0114] In the embodiment of the present application, during the deployment process of the smart contract, if the bytecode instruction read is a boundary instruction, the first consumption of the boundary instruction is calculated, the first consumption is associated with the preset instruction to obtain the execution consumption calculation bytecode of the program block corresponding to the boundary instruction, and the execution consumption calculation bytecode is associated with the boundary instruction for storage. This allows, during the execution process of the smart contract, the first execution consumption to be calculated directly according to the execution consumption calculation bytecode associated with the first consumption in the deployment phase, without the need to calculate the instructions in the program block corresponding to the boundary instruction one by one, and can quickly and efficiently measure resource consumption.
[0115] Embodiment 4
[0116] The present application also provides a smart contract execution device for executing the steps in the above-mentioned smart contract execution method embodiment. Figure 5 As shown, the smart contract execution device 500 provided in the embodiment of the present application includes:
[0117] The first acquisition module 501 is used to acquire the instruction consumption threshold when receiving a request instruction to execute a deployed smart contract;
[0118] The calculation module 502 is used to execute the execution consumption calculation bytecode associated with the boundary instruction when the currently executed bytecode instruction is a boundary instruction, and obtain the first execution consumption of the program block corresponding to the boundary instruction; wherein the boundary instruction includes a start instruction and an end instruction indicating that the bytecode instruction is a branch execution instruction or a loop execution instruction, and the execution consumption calculation bytecode is an executable program obtained by calculating the first consumption association preset instruction of the program block corresponding to the boundary instruction during the smart contract deployment process;
[0119] A second acquisition module 503 is used to acquire a second execution cost, and accumulate the second execution cost with the first execution cost to obtain a third execution cost; wherein the second execution cost is the total execution cost of all bytecode instructions executed before the current boundary instruction;
[0120] The first exit module 504 is used to exit the execution of the smart contract when it is detected that the third execution consumption is greater than the instruction consumption threshold.
[0121] In one embodiment, the calculation module 502 is specifically used to: during the process of executing the execution consumption calculation bytecode associated with the boundary instruction, each time the execution of the boundary instruction is detected to start, add the first consumption associated with the boundary instruction to the first execution consumption to update the first execution consumption;
[0122] Among them, the first consumption is the consumption required for executing the boundary instruction once, which is calculated and stored when the smart contract is deployed, and the first execution consumption is the total execution consumption of the program block corresponding to the boundary instruction calculated according to the number of executions of the boundary instruction and the first consumption when executing the smart contract.
[0123] In one embodiment, the execution device 500 further includes:
[0124] A third acquisition module, used for acquiring a fourth execution cost of the sequential execution instruction when the currently executed bytecode instruction is a sequential execution instruction;
[0125] A fourth acquisition module is used to acquire a fifth execution cost, and accumulate the fifth execution cost with the fourth execution cost to obtain a sixth execution cost; wherein the fifth execution cost is the total execution cost of all bytecode instructions executed before the currently sequentially executed instruction;
[0126] The second exit module is used to exit the execution of the smart contract when it is detected that the sixth execution consumption is greater than the instruction consumption threshold.
[0127] In the embodiment of the present application, during the execution of a smart contract, when the executed bytecode is a boundary instruction, the execution consumption calculation bytecode associated with the boundary instruction is used to calculate the first execution consumption of the program block corresponding to the boundary instruction; since the execution consumption calculation bytecode is an executable program obtained by associating the first consumption of the program block corresponding to the boundary instruction with the preset instruction during the deployment of the smart contract, the first execution consumption of the program block corresponding to the boundary instruction is obtained directly according to the execution consumption calculation bytecode, and there is no need to calculate the instructions in the program block corresponding to the boundary instruction one by one, so that resource consumption can be measured quickly and efficiently. And the second execution consumption is obtained, and the second execution consumption is accumulated with the first execution consumption to obtain the third execution consumption; wherein the second execution consumption is the total execution consumption of all bytecode instructions executed before the current boundary instruction; when it is detected that the third execution consumption is greater than the instruction consumption threshold, the execution of the smart contract is exited, and when the third execution consumption is greater than the instruction consumption threshold, the execution of the smart contract can be exited, thereby improving the execution stability of the smart contract.
[0128] Embodiment 5
[0129] like Figure 6 As shown, one embodiment of the present application also provides a terminal device 600 including: a processor 601, a memory 602, and a computer program 603 stored in the memory 602 and executable on the processor 601, such as a deployment program and / or execution program of a smart contract. When the processor 601 executes the computer program 603, the steps in the above-mentioned deployment method of each smart contract and / or the execution method of each smart contract are implemented. When the processor 601 executes the computer program 603, the functions of each module in the above-mentioned device embodiments are implemented, such as the functions of Embodiment 3 and / or Embodiment 4.
[0130] Exemplarily, the computer program 603 may be divided into one or more modules, which are stored in the memory 602 and executed by the processor 601 to complete the present application. The one or more modules may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program 603 in the terminal device 600.
[0131] The terminal device 600 may be a server, a tablet computer, a wearable device, an in-vehicle device, an augmented reality (AR) / virtual reality (VR) device, a laptop, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), a mobile phone, or other computing devices. The terminal device may include, but is not limited to, a processor 601 and a memory 602. Those skilled in the art will appreciate that Figure 6 It is only an example of the terminal device 600 and does not constitute a limitation of the terminal device 600. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the terminal device may also include input and output devices, network access devices, buses, etc.
[0132] The processor 601 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0133] The memory 602 may be an internal storage unit of the terminal device 600, such as a hard disk or memory of the terminal device 600. The memory 602 may also be an external storage device of the terminal device 600, 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 600. Further, the memory 602 may also include both an internal storage unit of the terminal device 600 and an external storage device. The memory 602 is used to store the computer program and other programs and data required by the terminal device. The memory 602 may also be used to temporarily store data that has been output or is to be output.
[0134] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, 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. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0135] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0136] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0137] In the embodiments provided in the present application, it should be understood that the disclosed devices / terminal equipment and methods can be implemented in other ways. For example, the device / terminal equipment embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as 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 mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0138] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0139] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0140] If the integrated module 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, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained 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, computer-readable media do not include electric carrier signals and telecommunication signals.
[0141] The embodiments described above 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 aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A method for deploying a smart contract. It is characterized in that include: When receiving a request instruction to deploy the smart contract, reading the bytecode instructions in the smart contract in sequence; When the bytecode instruction in the smart contract read is a boundary instruction, calculating the first consumption of the program block corresponding to the boundary instruction; wherein the boundary instruction includes a start instruction and an end instruction indicating that the bytecode instruction is a branch execution instruction or a loop execution instruction; Associating the first consumption with a preset instruction to obtain an execution consumption calculation bytecode of a program block corresponding to the boundary instruction; The execution consumption calculation bytecode is associated with the boundary instruction for storage, so that the smart contract executes the execution consumption calculation bytecode to obtain the first execution consumption of the program block corresponding to the boundary instruction during the execution of the boundary instruction; When all bytecode instructions in the smart contract have been read, it is determined that the bytecode instructions of the smart contract have been processed; Among them, the first consumption is the consumption required for executing the boundary instruction once, which is calculated and stored when the smart contract is deployed, and the first execution consumption is the total execution consumption of the program block corresponding to the boundary instruction calculated according to the number of executions of the boundary instruction and the first consumption when executing the smart contract.
2. The deployment method according to claim 1, It is characterized in that When the bytecode instruction in the smart contract read is a boundary instruction, calculating the first consumption of the program block corresponding to the boundary instruction includes: When the bytecode instruction in the smart contract read is a boundary instruction, the execution consumption of each instruction in the program block corresponding to the boundary instruction is accumulated to obtain the first consumption.
3. The deployment method according to claim 1, It is characterized in that The storing of the execution consumption calculation bytecode in association with the boundary instruction so that the smart contract executes the execution consumption calculation bytecode to obtain the first execution consumption of the program block corresponding to the boundary instruction during the execution of the boundary instruction includes: The execution consumption calculation bytecode is associated with the boundary instruction for storage, so that during the execution process of the smart contract, each time the execution of the boundary instruction is detected, the first consumption associated with the boundary instruction is added to the first execution consumption to update the first execution consumption.
4. A method for executing a smart contract, It is characterized in that include: When receiving a request instruction to execute a deployed smart contract, obtain the instruction consumption threshold; When the currently executed bytecode instruction is a boundary instruction, the execution consumption calculation bytecode associated with the boundary instruction is executed to obtain the first execution consumption of the program block corresponding to the boundary instruction; wherein the boundary instruction includes a start instruction and an end instruction indicating that the bytecode instruction is a branch execution instruction or a loop execution instruction, and the execution consumption calculation bytecode is an executable program obtained by calculating the first consumption association preset instruction of the program block corresponding to the boundary instruction during the smart contract deployment process; Obtain a second execution cost, and add the second execution cost to the first execution cost to obtain a third execution cost; wherein the second execution cost is the total execution cost of all bytecode instructions executed before the current boundary instruction; When it is detected that the third execution consumption is greater than the instruction consumption threshold, exiting the execution of the smart contract; Among them, the first consumption is the consumption required for executing the boundary instruction once, which is calculated and stored when the smart contract is deployed, and the first execution consumption is the total execution consumption of the program block corresponding to the boundary instruction calculated according to the number of executions of the boundary instruction and the first consumption when executing the smart contract.
5. The execution method according to claim 4, It is characterized in that The executing the execution cost calculation bytecode associated with the boundary instruction to obtain the first execution cost of the program block corresponding to the boundary instruction includes: During the process of executing the execution cost calculation bytecode associated with the boundary instruction, each time the start of executing the boundary instruction is detected, the first cost associated with the boundary instruction is accumulated once to the first execution cost to update the first execution cost.
6. The execution method according to claim 4, It is characterized in that The execution method further includes: When the currently executed bytecode instruction is a sequential execution instruction, obtaining a fourth execution cost of the sequential execution instruction; Obtain a fifth execution cost, and add the fifth execution cost to the fourth execution cost to obtain a sixth execution cost; wherein the fifth execution cost is the total execution cost of all bytecode instructions executed before the currently sequentially executed instruction; When it is detected that the sixth execution consumption is greater than the instruction consumption threshold, the execution of the smart contract is exited.
7. A smart contract deployment device, It is characterized in that include: A receiving module, configured to read the bytecode instructions in the smart contract in sequence when receiving a request instruction to deploy the smart contract; A calculation module, configured to calculate a first consumption of a program block corresponding to a boundary instruction when the bytecode instruction read in the smart contract is a boundary instruction; wherein the boundary instruction includes a start instruction and an end instruction indicating that the bytecode instruction is a branch execution instruction or a loop execution instruction; An obtaining module, used for associating the first consumption with a preset instruction, and obtaining an execution consumption calculation bytecode of a program block corresponding to the boundary instruction; An association module, used to associate the execution consumption calculation bytecode with the boundary instruction for storage, so that the smart contract executes the execution consumption calculation bytecode to obtain the first execution consumption of the program block corresponding to the boundary instruction during the execution of the boundary instruction; A processing completion module, used to determine that the bytecode instructions of the smart contract have been processed when all bytecode instructions in the smart contract have been read; Among them, the first consumption is the consumption required for executing the boundary instruction once, which is calculated and stored when the smart contract is deployed, and the first execution consumption is the total execution consumption of the program block corresponding to the boundary instruction calculated according to the number of executions of the boundary instruction and the first consumption when executing the smart contract.
8. A smart contract execution device, It is characterized in that include: A first acquisition module is used to acquire an instruction consumption threshold when receiving a request instruction to execute a deployed smart contract; A calculation module, configured to execute the execution consumption calculation bytecode associated with the boundary instruction when the currently executed bytecode instruction is a boundary instruction, and obtain the first execution consumption of the program block corresponding to the boundary instruction; wherein the boundary instruction includes a start instruction and an end instruction indicating that the bytecode instruction is a branch execution instruction or a loop execution instruction, and the execution consumption calculation bytecode is an executable program obtained by calculating the first consumption associated with the preset instruction of the program block corresponding to the boundary instruction during the deployment of the smart contract; A second acquisition module is used to acquire a second execution cost, and accumulate the second execution cost with the first execution cost to obtain a third execution cost; wherein the second execution cost is the total execution cost of all bytecode instructions executed before the current boundary instruction; A first exit module, configured to exit the execution of the smart contract when it is detected that the third execution consumption is greater than the instruction consumption threshold; Among them, the first consumption is the consumption required for executing the boundary instruction once, which is calculated and stored when the smart contract is deployed, and the first execution consumption is the total execution consumption of the program block corresponding to the boundary instruction calculated according to the number of executions of the boundary instruction and the first consumption when executing the smart contract.
9. A terminal device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the computer program, the method according to any one of claims 1 to 3 is implemented; or when the processor executes the computer program, the method according to any one of claims 4 to 6 is implemented.
10. A computer-readable storage medium storing a computer program. It is characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 3 is implemented; or when the computer program is executed by a processor, the method according to any one of claims 4 to 6 is implemented.
Citation Information
Patent Citations
Method for generating energy consumption information of instruction level password equipment
CN102508637A
Byte code optimization method, device, storage medium, processor and terminal
CN108153530A
