WO2022140947A1 - Smart contract deployment method and apparatus, smart contract execution method and apparatus, and terminal device - Google Patents

Smart contract deployment method and apparatus, smart contract execution method and apparatus, and terminal device Download PDF

Info

Publication number
WO2022140947A1
WO2022140947A1 PCT/CN2020/140281 CN2020140281W WO2022140947A1 WO 2022140947 A1 WO2022140947 A1 WO 2022140947A1 CN 2020140281 W CN2020140281 W CN 2020140281W WO 2022140947 A1 WO2022140947 A1 WO 2022140947A1
Authority
WO
WIPO (PCT)
Prior art keywords
instruction
execution
consumption
bytecode
smart contract
Prior art date
Application number
PCT/CN2020/140281
Other languages
French (fr)
Chinese (zh)
Inventor
邱炜伟
李伟
黄方蕾
张珂杰
何奇
Original Assignee
杭州趣链科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 杭州趣链科技有限公司 filed Critical 杭州趣链科技有限公司
Priority to PCT/CN2020/140281 priority Critical patent/WO2022140947A1/en
Publication of WO2022140947A1 publication Critical patent/WO2022140947A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines

Definitions

  • the present application belongs to the field of computer technology, and in particular, relates to a deployment method, execution method, device and terminal equipment of a smart contract.
  • Smart contracts are event-driven, stateful, run on a replicated and shareable ledger, and can keep assets on the ledger.
  • the program that is, a smart contract is a programmed contract that is automatically executed when preset conditions are met, such as smart contracts that can be deployed in a blockchain system.
  • the bytecode of the smart contract can be loaded and run by a virtual machine.
  • execution consumption ie gas
  • Gas is the computing resource required to provide computing power for the smart contract.
  • the current measurement method for the execution consumption of the bytecode of the smart contract is inefficient.
  • One of the purposes of the embodiments of the present application is to provide a smart contract deployment method, execution method, device, terminal device and storage medium, aiming to solve the low efficiency of the existing measurement method for the execution consumption of the bytecode of the smart contract The problem.
  • an embodiment of the present application provides a method for deploying a smart contract, including:
  • the read bytecode instruction in the smart contract is a boundary instruction
  • the smart contract executes the execution consumption calculation bytecode to obtain a program corresponding to the boundary instruction the first execution consumption of the block;
  • calculating the first consumption of the program block corresponding to the boundary instruction includes:
  • 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 calculation bytecode is stored in association with the boundary instruction, so that the smart contract executes the execution consumption calculation bytecode in the process of executing the boundary instruction
  • Obtaining the first execution consumption of the program block corresponding to the boundary instruction includes: storing the execution consumption calculation bytecode in association with the boundary instruction, so that during the execution process of the smart contract, every time it detects that the execution starts When the boundary instruction is executed once, the first consumption associated with the boundary instruction is accumulated to the first execution consumption, so as to update the first execution consumption;
  • the first consumption is the consumption required for one execution of the boundary instruction calculated and stored when the smart contract is deployed
  • the first execution consumption is the consumption according to the boundary instruction when the smart contract is executed The number of executions of and the total execution consumption of the program block corresponding to the boundary instruction of the first consumption calculation.
  • the embodiments of the present application provide a method for executing a smart contract, including:
  • the execution consumption associated with the boundary instruction is executed to calculate the bytecode, and the first execution consumption of the program block corresponding to the boundary instruction is obtained;
  • the boundary instruction includes a pointer
  • the section code instruction is the start instruction and the end instruction of the branch execution instruction or the loop execution instruction
  • the execution consumption calculation bytecode is a preset instruction that associates the first consumption of the program block corresponding to the boundary instruction with the calculation during the smart contract deployment process the resulting executable program
  • the second execution consumption is all bytecode instructions that have been executed before the current boundary instruction The total execution cost of ;
  • the execution of the execution consumption associated with the boundary instruction is performed to calculate the bytecode, and the first execution consumption of the program block corresponding to the boundary instruction is obtained, including:
  • 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 is the consumption required for one execution of the boundary instruction calculated and stored when the smart contract is deployed
  • the first execution consumption is the consumption according to the boundary instruction when the smart contract is executed The number of executions of and the total execution consumption of the program block corresponding to the boundary instruction of the first consumption calculation.
  • the executing method further includes:
  • the fifth execution consumption is all bytecodes that have been executed before the current sequential execution instruction The total execution cost of the instruction;
  • a smart contract deployment device including:
  • a receiving module configured to read bytecode instructions in the smart contract in sequence when receiving the request instruction for deploying the smart contract
  • a calculation module configured 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; wherein the boundary instruction includes indicating that the bytecode instruction is The start and end instructions of branch execution instructions or loop execution instructions;
  • obtaining module for associating the first consumption with a preset instruction to obtain the execution consumption calculation bytecode of the program block corresponding to the boundary instruction
  • an association module configured to associate the execution consumption calculation bytecode with the boundary instruction for storage, so that in the process of executing the boundary instruction, the smart contract executes the execution consumption calculation bytecode to obtain all the first execution consumption of the program block corresponding to the boundary instruction;
  • the processing completion module is configured to determine that the bytecode instructions of the smart contract have been processed when all bytecode instructions in the smart contract are read.
  • an embodiment of the present application provides a device for executing a smart contract, including:
  • a first obtaining module configured to obtain a command consumption threshold when receiving a request command for executing the 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;
  • the 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.
  • the executable program obtained by consuming the associated preset instruction;
  • the second obtaining module is configured to obtain the second execution consumption, and accumulate the second execution consumption and the first execution consumption to obtain the third execution consumption; wherein, the second execution consumption is the value that has been executed before the current boundary instruction.
  • the first exit module is 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.
  • an embodiment of the present application provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, when the processor executes the computer program.
  • an embodiment of the present application provides a computer-readable storage medium, where a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the method for deploying a smart contract according to the first aspect is implemented. steps; or the steps of implementing the smart contract execution method of the second aspect above when the above computer program is executed by the processor.
  • an embodiment of the present application provides a computer program product that, when the computer program product runs on an electronic device, causes the electronic device to execute the steps of the smart contract deployment method of the above-mentioned first aspect; Execute the steps of the smart contract execution method of the second aspect above.
  • the first aspect of the embodiments of the present application has the following beneficial effects: in the deployment process of the smart contract, if the read bytecode instruction is a boundary instruction, the first consumption of the boundary instruction is calculated, and the first consumption of the boundary instruction is calculated. Obtaining the execution consumption calculation bytecode of the program block corresponding to the boundary instruction by consuming the associated preset instruction, and storing the execution consumption calculation bytecode in association with the boundary instruction, so that in the execution process of the smart contract, directly according to the In the deployment phase, the execution consumption of the first consumption is associated with the bytecode calculation of the first execution consumption, and there is no need to calculate the instructions in the program block corresponding to the boundary instruction one by one, and the resource consumption can be measured quickly and efficiently.
  • the second aspect of the embodiment of the present application has the following beneficial effects: during the execution of the smart contract, when the executed bytecode is a boundary instruction, the bytecode is calculated according to the execution consumption associated with the boundary instruction , calculate the first execution consumption of the program block corresponding to the boundary instruction; since the execution consumption calculation bytecode is an executable obtained by correlating the first consumption of the program block corresponding to the boundary instruction with the preset instruction in the smart contract deployment process The program directly calculates the bytecode according to the execution consumption, obtains the first execution consumption of the program block corresponding to the boundary instruction, does not need to calculate the instructions in the program block corresponding to the boundary instruction one by one, and can quickly and efficiently measure the resource consumption .
  • the second execution consumption accumulate the second execution consumption and the first execution consumption, and obtain the third execution consumption; wherein, the second execution consumption is all bytecodes that have been executed before the current boundary instruction
  • the total execution consumption of the instruction when it is detected that the third execution consumption is greater than the instruction consumption threshold, the execution of the smart contract is terminated, and the execution of the smart contract can be quit when the third execution consumption is greater than the instruction consumption threshold,
  • the execution stability of smart contracts can be improved.
  • FIG. 1 is a schematic flowchart of a method for deploying a smart contract provided in Embodiment 1 of the present application;
  • FIG. 2 is a schematic flowchart of a method for executing a smart contract provided in Embodiment 2 of the present application;
  • FIG. 3 is a schematic flowchart of a method for executing a smart contract provided in Embodiment 2 of the present application;
  • FIG. 4 is a schematic flowchart of a smart contract deployment device provided in Embodiment 3 of the present application.
  • FIG. 5 is a schematic flowchart of a smart contract execution device provided in Embodiment 4 of the present application.
  • FIG. 6 is a schematic structural diagram of a terminal device provided in Embodiment 5 of the present application.
  • the smart contract deployment method provided by the embodiments of this application can be applied to a blockchain node in a blockchain network
  • the blockchain node can be a server, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality , AR)/virtual reality (VR) devices, laptops, ultra-mobile personal computers computer, UMPC), netbooks, personal digital assistants (personal digital assistants) assistant, PDA), mobile phone, or other various terminal devices capable of data processing.
  • the embodiments of the present application do not limit any specific types of devices.
  • a method for deploying a smart contract provided by an embodiment of the present application includes:
  • Step S101 when receiving a request instruction for deploying the smart contract, read bytecode instructions in the smart contract in sequence.
  • the request instruction for deploying the smart contract includes a plurality of bytecode instructions for executing the smart contract.
  • the bytecode instructions in the smart contract are sequentially read.
  • the bytecode instruction may be a wasm bytecode instruction.
  • Step S102 when the read bytecode instruction 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 indicating that the bytecode instruction is branch execution The start and end instructions of an instruction or a cyclic execution 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 will include multiple instructions , that is, the boundary instruction will correspond to a program block, so in the process of deploying the smart contract, the execution consumption of all instructions in the program block corresponding to the boundary instruction can be calculated, and the cost of all instructions in the program block corresponding to the boundary instruction can be calculated.
  • the execution cost is called the first cost.
  • calculating the first consumption of the program block corresponding to the boundary instruction includes: When the bytecode instruction in the smart contract 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.
  • calculating the first consumption of the program block corresponding to the boundary instruction may be: when calculating a single execution of the boundary instruction, the The boundary instructions are accumulated corresponding to the execution consumption of each instruction in the program block to obtain the first consumption.
  • the execution consumption of each instruction may be calculated according to the size of the bytecode occupied by the corresponding instruction.
  • Step S103 associate the first consumption with a preset instruction to obtain the execution consumption calculation bytecode of the program block corresponding to the boundary instruction.
  • the preset instruction is a program preset for calculating the execution consumption of the program segment corresponding to the boundary instruction during the execution stage of the smart contract.
  • the program needs to obtain the first consumption required for executing the current boundary instruction once, so the The first consumption is associated with a preset instruction, and a corresponding execution consumption calculation bytecode is generated.
  • Step S104 storing 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 boundary in the process of executing the boundary instruction
  • the instruction corresponds to the first execution cost of the program block.
  • the execution consumption calculation bytecode is stored in association with the boundary instruction, so that each time the smart contract executes the boundary instruction, it first calculates the first execution by executing the execution consumption bytecode associated with the boundary instruction. consume.
  • storing the execution consumption calculation bytecode in association with the boundary instruction may be inserting the execution consumption calculation bytecode into a preset position before the boundary instruction, and the preset position may be the boundary instruction and the boundary instruction. The position in the middle of the previous instruction of the boundary instruction allows the smart contract to calculate the first execution consumption by executing the corresponding execution consumption bytecode each time the boundary instruction is executed.
  • the execution consumption calculation bytecode can be executed in the smart contract execution process, when the currently executed bytecode instruction is a boundary instruction, execute the execution consumption calculation bytecode associated with the boundary instruction, and obtain the program block corresponding to the boundary instruction The first execution consumes.
  • the specific process of executing the execution consumption calculation bytecode associated with the boundary instruction may be in the process of executing the execution consumption calculation bytecode associated with the boundary instruction, every time it is detected that the boundary instruction starts to be executed once, the boundary instruction is executed.
  • the first consumption associated with the instruction is accumulated once to the first execution consumption to update the first execution consumption, the first consumption represents the consumption required for executing the boundary instruction once, and the first execution consumption is when executing the smart contract,
  • the total execution consumption of the program block corresponding to the boundary instruction is calculated according to the current execution times of the boundary instruction and the first consumption. 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.
  • the step implemented by the execution consumption calculation bytecode is to first obtain the single execution consumption of the boundary instruction (that is, the above-mentioned first consumption to be associated, the first consumption of different boundary instructions may be different) Therefore, 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 boundary instruction The execution times of , the total current execution consumption of the boundary instruction (ie the first execution consumption) can be calculated.
  • the execution consumption calculation bytecode may be an executable program implemented by a wasm bytecode program, and the wasm bytecode program may specifically be implemented by a stack program.
  • 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 used by major mainstream Supported by browsers, the target bytecode of the smart contract 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.
  • wasm bytecode to represent and execute smart contract program code, because its binary format has high compactness, it can greatly reduce the size of the object code file and improve the network distribution efficiency of the application.
  • the runtime efficiency of wasm bytecode can be close to the efficiency of native machine code, and wasm can provide compilation targets for types of languages such as C/C++ and Rust, so that applications written in these languages can run in the browser.
  • the step of implementing the execution consumption calculation bytecode through a stack code program may be: first, by presetting the first internal instruction (for example, through the instruction "EnvGet"), obtaining from the current execution environment Variable A (this variable can be understood as the total execution consumption of the program block corresponding to the first N minus 1 execution of the boundary instruction when the current boundary instruction is executed for the Nth time), and the variable A is first pushed into the pre-built stack; Preset the first wasm standard instruction (such as through the instruction "I64Const”) to push the constant B (this constant can be understood as the first consumption of the above acquisition) into the stack; then according to the preset second wasm standard instruction (such as through the instruction "I64Add” implementation) pops two numbers from the stack and adds the result and pushes the result into the stack.
  • the first wasm standard instruction such as through the instruction "I64Const”
  • variable A and constant B there are variable A and constant B in the stack, so the two numbers popped from the stack are variable A and constant B.
  • the variable A and the constant B are added and the result is pushed onto the stack; finally, a value is popped from the stack and written back to the environment variable by a preset second internal instruction (such as through the instruction "EnvPet") and written back to the environment variable.
  • the value is the result of adding the variable A and the constant B, and the result of adding the variable A and the constant B is written back to the environment variable, so as to realize that every time it is detected that the boundary instruction starts to be executed once, the boundary instruction is associated with the
  • the first consumption is accumulated once to the first execution consumption to update the first execution consumption.
  • the execution consumption calculation bytecode is stored in association with the boundary instruction, so that the smart contract executes the execution consumption calculation bytecode in the process of executing the boundary instruction
  • Obtaining the first execution consumption of the program block corresponding to the boundary instruction includes: storing the execution consumption calculation bytecode in association with the boundary instruction, so that during the execution process of the smart contract, every time it detects that the execution starts When the boundary instruction is executed once, the first consumption associated with the boundary instruction is accumulated to the first execution consumption, so as to update the first execution consumption;
  • the first consumption is the consumption required for one execution of the boundary instruction calculated and stored when the smart contract is deployed
  • the first execution consumption is the consumption according to the boundary instruction when the smart contract is executed The number of executions of and the total execution consumption of the program block corresponding to the boundary instruction of the first consumption calculation.
  • the execution consumption of the sequential execution instruction is calculated, which is called the fourth execution consumption, and the fourth execution consumption is combined with the sequential execution instruction.
  • Associative storage 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 obtained.
  • the 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 that have been executed before the current sequential execution instruction; 6.
  • the execution consumption is greater than the instruction consumption threshold, the execution of the smart contract is terminated, and the instruction consumption threshold indicates that the execution of the corresponding smart contract limits the execution consumption.
  • Step S105 when all bytecode instructions in the smart contract are read, it is determined that the bytecode instructions of the smart contract have been processed.
  • the read bytecode instruction is a boundary instruction
  • the first consumption of the boundary instruction is calculated, and the first consumption is associated with the preset instruction to obtain the execution consumption of the program block corresponding to the boundary instruction.
  • the first execution consumption does not need to calculate the instructions in the program block corresponding to the boundary instruction one by one, which can quickly and efficiently measure the resource consumption.
  • the smart contract execution method provided in the embodiment of the present application can be applied to a terminal device in which a smart contract is deployed through the smart contract deployment method in Embodiment 1.
  • a method for executing a smart contract includes:
  • Step S201 when a request instruction for executing the deployed smart contract is received, obtain an instruction consumption threshold.
  • the above-mentioned deployed smart contract is a smart contract deployed by the deployment method in Embodiment 1, and the request instruction to execute the deployed smart contract includes an instruction consumption threshold, and the instruction consumption threshold is a limit indicating the execution of the corresponding smart contract Execute consumption.
  • Step S202 when the currently executed bytecode instruction is a boundary instruction, execute the execution consumption calculation bytecode associated with the boundary instruction, and obtain the first execution consumption of the program block corresponding to the boundary instruction.
  • 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 a program corresponding to the boundary instruction that will be calculated during the smart contract deployment process
  • the first consumption of the block is associated with the executable program obtained by the preset instruction.
  • executing the execution consumption calculation bytecode associated with the boundary instruction, and obtaining the first execution consumption of the program block corresponding to the boundary instruction includes: executing the execution consumption calculation word associated with the boundary instruction In the process of saving the code, each time it is detected that the boundary instruction starts to be executed once, the first consumption associated with the boundary instruction is accumulated once to the first execution consumption, so as to update the first execution consumption;
  • the first consumption is the consumption required to execute the boundary instruction calculated and stored when the smart contract is deployed, and when the currently executed bytecode instruction is the boundary instruction, the first execution consumption is When executing the smart contract, the total execution consumption of the program block corresponding to the boundary instruction is calculated according to the execution times of the boundary instruction and the first consumption.
  • step S202 is the same, corresponding or similar to the above-mentioned steps S102 to S104.
  • steps S102 to S104 please refer to the relevant descriptions of the steps S102 to S104, which will not be repeated here.
  • Step S203 obtaining the second execution consumption, accumulating the second execution consumption and the first execution consumption to obtain the third execution consumption; wherein, the second execution consumption is all words executed before the current boundary instruction Total execution cost of section code instructions.
  • the total execution consumption of the executed bytecode instructions is continuously accumulated, and when the currently executed bytecode instruction is a boundary instruction, the first execution consumption of the boundary instruction is calculated first, and the The total execution consumption of all bytecode instructions executed before the current boundary instruction (called the third execution consumption) is added to the first execution to measure whether the execution consumption of continuing to execute the boundary instruction will be greater than the instruction consumption threshold .
  • 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.
  • 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.
  • the execution method further includes:
  • Step S301 when the currently executed bytecode instruction is a sequential execution instruction, obtain the fourth execution consumption of the sequential execution instruction.
  • the execution consumption of the sequential instruction is obtained first, which is called the fourth execution consumption.
  • the fourth execution cost may be, in the process of smart contract deployment, when the bytecode instruction in the smart contract is read as a sequential execution instruction, the fourth execution cost of the sequential execution instruction is calculated, and the fourth execution cost is compared with the sequence.
  • the execution instructions are stored associatively, so the fourth execution consumption can be directly obtained during the execution of the smart contract; or the fourth execution consumption can also be in the process of executing the smart contract, and the currently executed bytecode instruction is a sequential execution instruction , the fourth execution consumption is obtained by calculating according to the size of the bytecode occupied by the sequentially executed instructions.
  • Step S302 obtaining the fifth execution consumption, and accumulating the fifth execution consumption and the fourth execution consumption to obtain the sixth execution consumption; wherein, the fifth execution consumption is all the executed instructions before the current sequential execution instruction. Total execution cost of bytecode instructions.
  • the total execution consumption of the executed bytecode instructions is continuously accumulated, and when the currently executed bytecode instruction is a sequential execution instruction, the fourth execution consumption of the sequential execution instruction is obtained first, and The total execution cost of all bytecode instructions executed before the current sequential execution instruction (called the fifth execution cost) is added to the fourth execution cost to measure whether the execution cost of continuing the sequential execution of the instruction will be Greater than the instruction consumption threshold.
  • 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.
  • the smart contract can be specifically implemented through a stack code program: for example, by presetting the third internal instruction (such as through the instruction "EnvGet"), the variable C is obtained from the current execution environment (the variable C is the execution of the current instruction and the current The total execution consumption required by all the instructions before the instruction, if the boundary instruction is executed, the variable C is the above-mentioned third execution consumption; if the sequential execution instruction is executed, the variable C is the above-mentioned sixth execution consumption); and then according to the preset third
  • the wasm standard instruction (such as implemented by the instruction "I64Const”) means to push the constant (limit value, that is, the instruction consumption threshold) into the stack; then according to the preset fourth wasm standard instruction (such as implemented by the instruction I64Ge_U), the stack is stored
  • the first value on the stack is the instruction consumption threshold
  • 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 returns 1, if The first value is less than or equal to the second value and returns 0, and pushes the return value into the stack; then according to the preset fifth wasm standard instruction (such as through if), it is judged whether the top of the stack is 0, and 0 means the instruction
  • the consumption threshold is less than or equal to the third execution consumption or the sixth execution consumption; when it is judged that the top of the stack is 0, the fourth internal instruction is preset (for example, implemented by the instruction Break) to exit the execution and throw an error.
  • the stack code program it is possible to judge whether the current code execution consumption exceeds the execution limit, and stop the execution if it exceeds the limit.
  • the bytecode when the executed bytecode is a boundary instruction, the bytecode is calculated according to the execution consumption associated with the boundary instruction, and the first execution consumption of the program block corresponding to the boundary instruction is calculated; Since the execution consumption calculation bytecode is an executable program obtained by correlating the first consumption of the program block corresponding to the boundary instruction with the preset instruction in the smart contract deployment process, the bytecode is directly calculated according to the execution consumption to obtain the boundary The first execution consumption of the program block corresponding to the instruction does not need to be calculated one by one in the program block corresponding to the boundary instruction, and the resource consumption can be measured quickly and efficiently.
  • the second execution consumption accumulate the second execution consumption and the first execution consumption, and obtain the third execution consumption; wherein, the second execution consumption is all bytecodes that have been executed before the current boundary instruction
  • the total execution consumption of the 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 the execution of the smart contract can be exited when the third execution consumption is greater than the instruction consumption threshold,
  • the execution stability of smart contracts can be improved.
  • the embodiments of the present application further provide a smart contract deployment device, which is used to execute the steps in the above smart contract deployment method embodiments.
  • the smart contract deployment device 400 provided in the embodiment of the present application includes:
  • a receiving module 401 configured to read bytecode instructions in the smart contract in sequence when receiving a request instruction for deploying the smart contract;
  • the calculation module 402 is configured to calculate the first consumption of the program block corresponding to the boundary instruction when the read bytecode instruction in the smart contract is a boundary instruction; wherein, the boundary instruction includes an instruction bytecode instruction Start and end instructions for branch execution instructions or loop execution instructions;
  • the association module 404 is configured to associate the execution consumption calculation bytecode with the boundary instruction for storage, so that in the process of executing the boundary instruction, the smart contract executes the execution consumption calculation bytecode to obtain The boundary instruction corresponds to the first execution consumption of the program block;
  • the processing completion module 405 is configured to determine that the bytecode instructions of the smart contract have been processed when all bytecode instructions in the smart contract are read.
  • the computing module 402 is specifically configured to, when the read bytecode instruction in the smart contract is a boundary instruction, consume the execution consumption of each instruction in the program block corresponding to the boundary instruction Accumulation is performed to obtain the first consumption.
  • the associating module is specifically configured 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 it detects that it starts to execute the When the boundary instruction is used, the first consumption associated with the boundary instruction is accumulated to the first execution consumption once to update the first execution consumption;
  • the first consumption is the consumption required for one execution of the boundary instruction calculated and stored when the smart contract is deployed
  • the first execution consumption is the consumption according to the boundary instruction when the smart contract is executed The number of executions of and the total execution consumption of the program block corresponding to the boundary instruction of the first consumption calculation.
  • the read bytecode instruction is a boundary instruction
  • the first consumption of the boundary instruction is calculated, and the first consumption is associated with the preset instruction to obtain the execution consumption of the program block corresponding to the boundary instruction.
  • the first execution consumption does not need to calculate the instructions in the program block corresponding to the boundary instruction one by one, which can quickly and efficiently measure the resource consumption.
  • Embodiments of the present application further provide an apparatus for executing a smart contract, which is used to execute the steps in the above-mentioned embodiments of the method for executing a smart contract.
  • the execution device 500 of the smart contract provided by the embodiment of the present application includes:
  • the first obtaining module 501 is configured to obtain the instruction consumption threshold when receiving the request instruction for executing the deployed smart contract;
  • the calculation module 502 is 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;
  • 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 executable program obtained by consuming the associated preset instruction;
  • the second obtaining module 503 is configured to obtain the second execution consumption, and accumulate the second execution consumption and the first execution consumption to obtain the third execution consumption; wherein, the second execution consumption is before the current boundary instruction The total execution cost of all bytecode instructions executed;
  • the first exit module 504 is 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.
  • the calculation module 502 is specifically configured to: in the process of executing the execution consumption calculation bytecode associated with the boundary instruction, every time it is detected that the boundary instruction starts to be executed once, calculate the boundary instruction The associated first consumption is accumulated once to the first execution consumption to update the first execution consumption;
  • the first consumption is the consumption required for one execution of the boundary instruction calculated and stored when the smart contract is deployed
  • the first execution consumption is the consumption according to the boundary instruction when the smart contract is executed The number of executions of and the total execution consumption of the program block corresponding to the boundary instruction of the first consumption calculation.
  • the execution device 500 further includes:
  • a third obtaining module configured to obtain the fourth execution consumption of the sequential execution instruction when the currently executed bytecode instruction is a sequential execution instruction
  • a fourth acquisition module configured to acquire the fifth execution consumption, and accumulate the fifth execution consumption and the fourth execution consumption to obtain the sixth execution consumption; wherein, the fifth execution consumption is before the current sequential execution instruction The total execution cost of all bytecode instructions executed;
  • the second exit module is configured to exit the execution of the smart contract when it is detected that the sixth execution consumption is greater than the instruction consumption threshold.
  • the bytecode when the executed bytecode is a boundary instruction, the bytecode is calculated according to the execution consumption associated with the boundary instruction, and the first execution consumption of the program block corresponding to the boundary instruction is calculated; Since the execution consumption calculation bytecode is an executable program obtained by correlating the first consumption of the program block corresponding to the boundary instruction with the preset instruction in the smart contract deployment process, the bytecode is directly calculated according to the execution consumption to obtain the boundary The first execution consumption of the program block corresponding to the instruction does not need to be calculated one by one in the program block corresponding to the boundary instruction, and the resource consumption can be measured quickly and efficiently.
  • the second execution consumption accumulate the second execution consumption and the first execution consumption, and obtain the third execution consumption; wherein, the second execution consumption is all bytecodes that have been executed before the current boundary instruction
  • the total execution consumption of the 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 the execution of the smart contract can be exited when the third execution consumption is greater than the instruction consumption threshold,
  • the execution stability of smart contracts can be improved.
  • an embodiment of the present application further provides a terminal device 600 including: a processor 601, a memory 602, and a computer program 603 stored in the memory 602 and running on the processor 601, For example, the deployer and/or the executor of the smart contract.
  • the processor 601 executes the computer program 603, the steps in the above-mentioned embodiments of the deployment method of each smart contract and/or the execution method of each smart contract are implemented.
  • the processor 601 executes the computer program 603, the functions of the modules in the foregoing apparatus embodiments are implemented, for example, the functions of the third embodiment and/or the fourth embodiment.
  • the computer program 603 may be divided into one or more modules, and the one or more modules 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 accomplishing specific functions, and the instruction segments are used to describe the execution process of the computer program 603 in the terminal device 600 .
  • 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, and an ultra-mobile personal computer (ultra-mobile personal computer).
  • computer UMPC
  • netbooks personal digital assistants (personal digital assistants) assistant, PDA), cell phone, or other computing device.
  • the terminal device may include, but is not limited to, the processor 601 and the memory 602 .

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

A smart contract deployment method and apparatus, a smart contract execution method and apparatus, a terminal device, and a storage medium. The deployment method comprises: when a request instruction for deploying a smart contract is received, reading a bytecode instruction in the smart contract in sequence (S101); when the read bytecode instruction in the smart contract is a boundary instruction, calculating first consumption of a program block corresponding to the boundary instruction, wherein the boundary instruction comprises a start instruction and an end instruction that indicate that the bytecode instruction is a branch execution instruction or a loop execution instruction (S102); associating the first consumption with a preset instruction to obtain an execution consumption calculation bytecode of the program block corresponding to the boundary instruction (S103); and storing the execution consumption calculation bytecode in association with the boundary instruction, so that the execution consumption calculation bytecode is executed in the process of executing the boundary instruction of the smart contract to obtain first execution consumption of the program block corresponding to the boundary instruction (S104). According to the method, in the execution process of the smart contract, first execution consumption is calculated directly according to the execution consumption calculation bytecode associated with the first consumption in the deployment stage, and resource consumption can be quickly and efficiently measured.

Description

智能合约的部署方法、执行方法、装置及终端设备Deployment method, execution method, device and terminal device of smart contract 技术领域technical field
本申请属于计算机技术领域,尤其涉及一种智能合约的部署方法、执行方法、装置及终端设备。The present application belongs to the field of computer technology, and in particular, relates to a deployment method, execution method, device and terminal equipment of a smart contract.
背景技术Background technique
随着计算机技术领域的快速发展,智能合约得到了越来越多的应用,智能合约是一段由事件驱动、具有状态的、运行在一个复制且可分享的账本之上,并且能够保管账本上资产的程序,即智能合约是一种程序化合约,在满足预设条件时自动执行,如智能合约可部署在区块链系统中。With the rapid development of computer technology, smart contracts have been used more and more. Smart contracts are event-driven, stateful, run on a replicated and shareable ledger, and can keep assets on the ledger. The program, that is, a smart contract is a programmed contract that is automatically executed when preset conditions are met, such as smart contracts that can be deployed in a blockchain system.
通常在执行智能合约的过程中,可通过虚拟机加载并运行智能合约的字节码实现。执行智能合约的字节码时会有执行消耗(即gas),gas是为智能合约提供算力所需的计算资源,目前对智能合约的字节码的执行消耗的衡量方法效率低。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 the smart contract, there will be execution consumption (ie gas). Gas is the computing resource required to provide computing power for the smart contract. The current measurement method for the execution consumption of the bytecode of the smart contract is inefficient.
技术问题technical problem
本申请实施例的目的之一在于:提供一种智能合约的部署方法、执行方法、装置、终端设备及存储介质,旨在解决现有对智能合约的字节码的执行消耗的衡量方法效率低的问题。One of the purposes of the embodiments of the present application is to provide a smart contract deployment method, execution method, device, terminal device and storage medium, aiming to solve the low efficiency of the existing measurement method for the execution consumption of the bytecode of the smart contract The problem.
技术解决方案technical solutions
为解决上述技术问题,本申请实施例采用的技术方案是:In order to solve the above-mentioned technical problems, the technical solutions adopted in the embodiments of the present application are:
第一方面,本申请实施例提供了一种智能合约的部署方法,包括:In a first aspect, an embodiment of the present application provides a method for deploying a smart contract, including:
当接收到部署所述智能合约的请求指令时,按顺序读取所述智能合约中的字节码指令;When receiving the request instruction for deploying the smart contract, read the bytecode instructions in the smart contract in sequence;
在读取的所述智能合约中的字节码指令为边界指令时,计算所述边界指令对应程序块的第一消耗;其中,所述边界指令包括指示字节码指令为分支执行指令或循环执行指令的开始指令和结束指令;When the read bytecode instruction 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 indicating that the bytecode instruction is a branch execution instruction or a loop Execute the start command and end command of the command;
将所述第一消耗关联预设指令,得到所述边界指令对应程序块的执行消耗计算字节码;Associating the first consumption with a preset instruction to obtain the execution consumption calculation bytecode of the program block corresponding to the boundary instruction;
将所述执行消耗计算字节码关联所述边界指令进行存储,以使所述智能合约在执行所述边界指令的过程中,执行所述执行消耗计算字节码以获得所述边界指令对应程序块的第一执行消耗;storing the execution consumption calculation bytecode in association with the boundary instruction, so that in the process of executing the boundary instruction, the smart contract executes the execution consumption calculation bytecode to obtain a program corresponding to the boundary instruction the first execution consumption of the block;
在所述智能合约中所有字节码指令读取完成时,判定所述智能合约的字节码指令已处理完成。When all bytecode instructions in the smart contract are read, it is determined that the bytecode instructions of the smart contract have been processed.
在一个实施例中,所述在读取的所述智能合约中的字节码指令为边界指令时,计算所述边界指令对应程序块的第一消耗,包括:In one embodiment, when the read bytecode instruction in the smart contract is a boundary instruction, calculating the first consumption of the program block corresponding to the boundary instruction includes:
所述在读取的所述智能合约中的字节码指令为边界指令时,将所述边界指令对应程序块中每一条指令的执行消耗进行累加,得到所述第一消耗。When the read bytecode instruction in the smart contract 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.
在一个实施例中,所述将所述执行消耗计算字节码关联所述边界指令进行存储,以使所述智能合约在执行所述边界指令的过程中,执行所述执行消耗计算字节码以获得所述边界指令对应程序块的第一执行消耗,包括:将所述执行消耗计算字节码关联所述边界指令进行存储,以使所述智能合约在执行过程中,每检测到开始执行一次所述边界指令时,将所述边界指令关联的第一消耗累加一次至所述第一执行消耗,以更新所述第一执行消耗;In one embodiment, the execution consumption calculation bytecode is stored in association with the boundary instruction, so that the smart contract executes the execution consumption calculation bytecode in the process of executing the boundary instruction Obtaining the first execution consumption of the program block corresponding to the boundary instruction includes: storing the execution consumption calculation bytecode in association with the boundary instruction, so that during the execution process of the smart contract, every time it detects that the execution starts When the boundary instruction is executed once, the first consumption associated with the boundary instruction is accumulated to the first execution consumption, so as to update the first execution consumption;
其中,所述第一消耗为在所述智能合约部署时计算出并存储的所述边界指令执行一次需要的消耗,所述第一执行消耗为所述在执行智能合约时,根据所述边界指令的执行次数和第一消耗计算的所述边界指令对应程序块的总执行消耗。Wherein, the first consumption is the consumption required for one execution of the boundary instruction calculated and stored when the smart contract is deployed, and the first execution consumption is the consumption according to the boundary instruction when the smart contract is executed The number of executions of and the total execution consumption of the program block corresponding to the boundary instruction of the first consumption calculation.
第二方面,本申请实施例提供一种智能合约的执行方法,包括:In a second aspect, the embodiments of the present application provide a method for executing a smart contract, including:
在接收到执行已部署的智能合约的请求指令时,获取指令消耗阈值;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 associated with the boundary instruction is executed to calculate the bytecode, and the first execution consumption of the program block corresponding to the boundary instruction is obtained; wherein, the boundary instruction includes a pointer The section code instruction is the start instruction and the end instruction of the branch execution instruction or the loop execution instruction, and the execution consumption calculation bytecode is a preset instruction that associates the first consumption of the program block corresponding to the boundary instruction with the calculation during the smart contract deployment process the resulting executable program;
获取第二执行消耗,将所述第二执行消耗与所述第一执行消耗进行累加,获得第三执行消耗;其中,所述第二执行消耗为当前边界指令之前已执行的所有字节码指令的总执行消耗;Obtain the second execution consumption, accumulate the second execution consumption and the first execution consumption, and obtain the third execution consumption; wherein, the second execution consumption is all bytecode instructions that have been executed before the current boundary instruction The total execution cost of ;
在检测到所述第三执行消耗大于所述指令消耗阈值时,退出执行所述智能合约。When it is detected that the third execution consumption is greater than the instruction consumption threshold, the execution of the smart contract is exited.
在一个实施例中,所述执行所述边界指令关联的执行消耗计算字节码,获得所述边界指令对应程序块的第一执行消耗,包括:In one embodiment, the execution of the execution consumption associated with the boundary instruction is performed to calculate the bytecode, and the first execution consumption of the program block corresponding to the boundary instruction is obtained, including:
在执行所述边界指令关联的执行消耗计算字节码的过程中,每检测到开始执行一次所述边界指令时,将所述边界指令关联的第一消耗累加一次至所述第一执行消耗,以更新所述第一执行消耗;In the process of calculating the bytecode of execution consumption associated with the boundary instruction, each time it is detected that the boundary instruction starts to be executed once, the first consumption associated with the boundary instruction is accumulated once to the first execution consumption, to update the first execution consumption;
其中,所述第一消耗为在所述智能合约部署时计算出并存储的所述边界指令执行一次需要的消耗,所述第一执行消耗为所述在执行智能合约时,根据所述边界指令的执行次数和第一消耗计算的所述边界指令对应程序块的总执行消耗。Wherein, the first consumption is the consumption required for one execution of the boundary instruction calculated and stored when the smart contract is deployed, and the first execution consumption is the consumption according to the boundary instruction when the smart contract is executed The number of executions of and the total execution consumption of the program block corresponding to the boundary instruction of the first consumption calculation.
在一个实施例中,所述执行方法还包括:In one embodiment, the executing method further includes:
在当前执行的字节码指令为顺序执行指令时,获取所述顺序执行指令的第四执行消耗;When the currently executed bytecode instruction is a sequential execution instruction, obtain the fourth execution consumption of the sequential execution instruction;
获取第五执行消耗,将所述第五执行消耗与所述第四执行消耗进行累加,获得第六执行消耗;其中,所述第五执行消耗为当前顺序执行指令之前已执行的所有字节码指令的总执行消耗;Obtain the fifth execution consumption, and accumulate the fifth execution consumption and the fourth execution consumption to obtain the sixth execution consumption; wherein, the fifth execution consumption is all bytecodes that have been executed before the current sequential execution instruction The total execution cost of the 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.
第三方面,本申请实施例提供了智能合约的部署装置,包括:In a third aspect, the embodiments of the present application provide a smart contract deployment device, including:
接收模块,用于当接收到部署所述智能合约的请求指令时,按顺序读取所述智能合约中的字节码指令;a receiving module, configured to read bytecode instructions in the smart contract in sequence when receiving the request instruction for deploying the smart contract;
计算模块,用于在读取的所述智能合约中的字节码指令为边界指令时,计算所述边界指令对应程序块的第一消耗;其中,所述边界指令包括指示字节码指令为分支执行指令或循环执行指令的开始指令和结束指令;A calculation module, configured 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; wherein the boundary instruction includes indicating that the bytecode instruction is The start and end instructions of branch execution instructions or loop execution instructions;
得到模块,用于将所述第一消耗关联预设指令,得到所述边界指令对应程序块的执行消耗计算字节码;obtaining module, for associating the first consumption with a preset instruction to obtain the execution consumption calculation bytecode of the program block corresponding to the boundary instruction;
关联模块,用于将所述执行消耗计算字节码关联所述边界指令进行存储,以使所述智能合约在执行所述边界指令的过程中,执行所述执行消耗计算字节码以获得所述边界指令对应程序块的第一执行消耗;an association module, configured to associate the execution consumption calculation bytecode with the boundary instruction for storage, so that in the process of executing the boundary instruction, the smart contract executes the execution consumption calculation bytecode to obtain all the first execution consumption of the program block corresponding to the boundary instruction;
处理完成模块,用于在所述智能合约中所有字节码指令读取完成时,判定所述智能合约的字节码指令已处理完成。The processing completion module is configured to determine that the bytecode instructions of the smart contract have been processed when all bytecode instructions in the smart contract are read.
第四方面,本申请实施例提供了一种智能合约的执行装置,包括:In a fourth aspect, an embodiment of the present application provides a device for executing a smart contract, including:
第一获取模块,用于在接收到执行已部署的智能合约的请求指令时,获取指令消耗阈值;a first obtaining module, configured to obtain a command consumption threshold when receiving a request command for executing the 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 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. The executable program obtained by consuming the associated preset instruction;
第二获取模块,用于获取第二执行消耗,将所述第二执行消耗与所述第一执行消耗进行累加,获得第三执行消耗;其中,所述第二执行消耗为当前边界指令之前已执行的所有字节码指令的总执行消耗;The second obtaining module is configured to obtain the second execution consumption, and accumulate the second execution consumption and the first execution consumption to obtain the third execution consumption; wherein, the second execution consumption is the value that has been executed before the current boundary instruction. The total execution cost of all bytecode instructions executed;
第一退出模块,用于在检测到所述第三执行消耗大于所述指令消耗阈值时,退出执行所述智能合约。The first exit module is 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.
第五方面,本申请实施例提供了一种终端设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现上述第一方面的智能合约的部署方法的步骤;或者所述处理器执行所述计算机程序时实现上述第二方面的智能合约的执行方法的步骤。In a fifth aspect, an embodiment of the present application provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, when the processor executes the computer program The steps of implementing the smart contract deployment method of the first aspect above; or the steps of implementing the smart contract execution method of the second aspect when the processor executes the computer program.
第六方面,本申请实施例提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,上述计算机程序被处理器执行时实现上述第一方面的智能合约的部署方法的步骤;或者上述计算机程序被处理器执行时实现上述第二方面的智能合约的执行方法的步骤。In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium, where a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the method for deploying a smart contract according to the first aspect is implemented. steps; or the steps of implementing the smart contract execution method of the second aspect above when the above computer program is executed by the processor.
第七方面,本申请实施例提供了一种计算机程序产品,当计算机程序产品在电子设备上运行时,使得电子设备执行上述现上述第一方面的智能合约的部署方法的步骤;或者使得电子设备执行上述第二方面的智能合约的执行方法的步骤。In a seventh aspect, an embodiment of the present application provides a computer program product that, when the computer program product runs on an electronic device, causes the electronic device to execute the steps of the smart contract deployment method of the above-mentioned first aspect; Execute the steps of the smart contract execution method of the second aspect above.
有益效果beneficial effect
本申请实施例第一方面与现有技术相比存在的有益效果是:在智能合约的部署过程中,若读取的字节码指令为边界指令,计算该边界指令的第一消耗,将第一消耗关联预设指令得到边界指令对应程序块的执行消耗计算字节码,并将所述执行消耗计算字节码关联所述边界指令进行存储,可以使得在智能合约的执行过程中,直接根据部署阶段关联了第一消耗的执行消耗计算字节码计算第一执行消耗,不需要对边界指令对应程序块中的指令一条一条进行计算,能快速高效的对资源消耗进行衡量。Compared with the prior art, the first aspect of the embodiments of the present application has the following beneficial effects: in the deployment process of the smart contract, if the read bytecode instruction is a boundary instruction, the first consumption of the boundary instruction is calculated, and the first consumption of the boundary instruction is calculated. Obtaining the execution consumption calculation bytecode of the program block corresponding to the boundary instruction by consuming the associated preset instruction, and storing the execution consumption calculation bytecode in association with the boundary instruction, so that in the execution process of the smart contract, directly according to the In the deployment phase, the execution consumption of the first consumption is associated with the bytecode calculation of the first execution consumption, and there is no need to calculate the instructions in the program block corresponding to the boundary instruction one by one, and the resource consumption can be measured quickly and efficiently.
本申请实施例第二方面与现有技术相比存在的有益效果是:在智能合约执行过程中,当执行的字节码为边界指令时,根据所述边界指令关联的执行消耗计算字节码,计算所述边界指令对应程序块的第一执行消耗;由于执行消耗计算字节码是在智能合约部署过程中将计算所述边界指令对应程序块的第一消耗关联预设指令得到的可执行程序,直接根据执行消耗计算字节码,获得所述边界指令对应程序块的第一执行消耗,不需要对边界指令对应程序块中的指令一条一条进行计算,能快速高效的对资源消耗进行衡量。并且获取第二执行消耗,将所述第二执行消耗与所述第一执行消耗进行累加,获得第三执行消耗;其中,所述第二执行消耗为当前边界指令之前已执行的所有字节码指令的总执行消耗;在检测到所述第三执行消耗大于所述指令消耗阈值时,退出执行所述智能合约,可在第三执行消耗大于所述指令消耗阈值时,退出智能合约的执行,从而可提高智能合约的执行稳定性。Compared with the prior art, the second aspect of the embodiment of the present application has the following beneficial effects: during the execution of the smart contract, when the executed bytecode is a boundary instruction, the bytecode is calculated according to the execution consumption associated with the boundary instruction , calculate the first execution consumption of the program block corresponding to the boundary instruction; since the execution consumption calculation bytecode is an executable obtained by correlating the first consumption of the program block corresponding to the boundary instruction with the preset instruction in the smart contract deployment process The program directly calculates the bytecode according to the execution consumption, obtains the first execution consumption of the program block corresponding to the boundary instruction, does not need to calculate the instructions in the program block corresponding to the boundary instruction one by one, and can quickly and efficiently measure the resource consumption . And obtain the second execution consumption, accumulate the second execution consumption and the first execution consumption, and obtain the third execution consumption; wherein, the second execution consumption is all bytecodes that have been executed before the current boundary instruction The total execution consumption of the instruction; when it is detected that the third execution consumption is greater than the instruction consumption threshold, the execution of the smart contract is terminated, and the execution of the smart contract can be quit when the third execution consumption is greater than the instruction consumption threshold, Thus, the execution stability of smart contracts can be improved.
附图说明Description of drawings
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例或示范性技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其它的附图。In order to illustrate the technical solutions in the embodiments of the present application more clearly, the following briefly introduces the accompanying drawings that are used in the description of the embodiments or exemplary technologies. Obviously, the drawings in the following description are only for the present application. In some embodiments, for those of ordinary skill in the art, other drawings can also be obtained according to these drawings without any creative effort.
图1是本申请实施例一提供的智能合约的部署方法的流程示意图;1 is a schematic flowchart of a method for deploying a smart contract provided in Embodiment 1 of the present application;
图2是本申请实施例二提供的智能合约的执行方法的流程示意图;2 is a schematic flowchart of a method for executing a smart contract provided in Embodiment 2 of the present application;
图3是本申请实施例二提供的智能合约的执行方法的流程示意图;3 is a schematic flowchart of a method for executing a smart contract provided in Embodiment 2 of the present application;
图4是本申请实施例三提供的智能合约的部署装置的流程示意图;4 is a schematic flowchart of a smart contract deployment device provided in Embodiment 3 of the present application;
图5是本申请实施例四提供的智能合约的执行装置的流程示意图;5 is a schematic flowchart of a smart contract execution device provided in Embodiment 4 of the present application;
图6是本申请实施例五提供的终端设备的结构示意图。FIG. 6 is a schematic structural diagram of a terminal device provided in Embodiment 5 of the present application.
本发明的实施方式Embodiments of the present invention
以下描述中,为了说明而不是为了限定,提出了诸如特定系统结构、技术之类的具体细节,以便透彻理解本申请实施例。然而,本领域的技术人员应当清楚,在没有这些具体细节的其它实施例中也可以实现本申请。在其它情况中,省略对众所周知的系统、装置、电路以及方法的详细说明,以免不必要的细节妨碍本申请的描述。In the following description, for the purpose of illustration rather than limitation, specific details such as a specific system structure and technology are set forth in order to provide a thorough understanding of the embodiments of the present application. However, it will be apparent to those skilled in the art that the present application may be practiced in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail.
本申请实施例提供的智能合约的部署方法可应用于区块链网络中的区块链节点,所述区块链节点可以为服务器、平板电脑、可穿戴设备、车载设备、增强现实(augmented reality,AR)/虚拟现实(virtual reality,VR)设备、笔记本电脑、超级移动个人计算机(ultra-mobile personal computer,UMPC)、上网本、个人数字助理(personal digital assistant,PDA)、手机、或者其他能进行数据处理的各种终端设备。本申请实施例对设备的具体类型不作任何限制。The smart contract deployment method provided by the embodiments of this application can be applied to a blockchain node in a blockchain network, and the blockchain node can be a server, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality , AR)/virtual reality (VR) devices, laptops, ultra-mobile personal computers computer, UMPC), netbooks, personal digital assistants (personal digital assistants) assistant, PDA), mobile phone, or other various terminal devices capable of data processing. The embodiments of the present application do not limit any specific types of devices.
为了说明本申请所述的技术方案,下面通过以下实施例来进行说明。In order to illustrate the technical solutions described in this application, the following examples are used to illustrate.
实施例一Example 1
请参阅图1,本申请实施例提供的一种智能合约的部署方法,包括:Referring to FIG. 1, a method for deploying a smart contract provided by an embodiment of the present application includes:
步骤S101,当接收到部署所述智能合约的请求指令时,按顺序读取所述智能合约中的字节码指令。Step S101, when receiving a request instruction for deploying the smart contract, read bytecode instructions in the smart contract in sequence.
具体地,部署所述智能合约的请求指令包括用于执行所述智能合约的多个字节码指令,在接收到部署智能合约的请求指令时,按顺序读取智能合约中的字节码指令进行处理,所述字节码指令可以是wasm字节码指令。Specifically, the request instruction for deploying the smart contract includes a plurality of 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 sequentially read. For processing, the bytecode instruction may be a wasm bytecode instruction.
步骤S102,在读取的所述智能合约中的字节码指令为边界指令时,计算所述边界指令对应程序块的第一消耗;其中,所述边界指令包括指示字节码指令为分支执行指令或循环执行指令的开始指令和结束指令。Step S102, when the read bytecode instruction 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 indicating that the bytecode instruction is branch execution The start and end instructions of an instruction or a cyclic execution instruction.
具体地,在读取的所述智能合约中的字节码指令为边界指令时,边界指令可以是分支执行指令或循环执行指令,在边界指令的起始指令和结束指令中会包括多条指令,即边界指令会对应的是一段程序块,因此可在部署智能合约的过程中,将边界指令对应的程序块中所有指令的执行消耗计算出来,将计算该边界指令对应程序块的所有指令的执行消耗称之为第一消耗。Specifically, when the read bytecode instruction in the smart contract is a boundary instruction, the boundary instruction may be a branch execution instruction or a loop execution instruction, and the start instruction and the end instruction of the boundary instruction will include multiple instructions , that is, the boundary instruction will correspond to a program block, so in the process of deploying the smart contract, the execution consumption of all instructions in the program block corresponding to the boundary instruction can be calculated, and the cost of all instructions in the program block corresponding to the boundary instruction can be calculated. The execution cost is called the first cost.
在一个实施例中,所述在读取的所述智能合约中的字节码指令为边界指令时,计算所述边界指令对应程序块的第一消耗,包括:所述在读取的所述智能合约中的字节码指令为边界指令时,将所述边界指令对应程序块中每一条指令的执行消耗进行累加,得到所述第一消耗。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 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.
具体地,在读取的所述智能合约中的字节码指令为边界指令时,计算所述边界指令对应程序块的第一消耗可以是:计算单次执行所述边界指令时,将所述边界指令对应程序块中每一条指令的执行消耗进行累加,得到所述第一消耗。每一条指令的执行消耗可以是根据对应指令所占用的字节码的大小进行计算。Specifically, when the read bytecode instruction in the smart contract is a boundary instruction, calculating the first consumption of the program block corresponding to the boundary instruction may be: when calculating a single execution of the boundary instruction, the The boundary instructions are accumulated corresponding to the execution consumption of each instruction in the program block to obtain the first consumption. The execution consumption of each instruction may be calculated according to the size of the bytecode occupied by the corresponding instruction.
步骤S103,将所述第一消耗关联预设指令,得到所述边界指令对应程序块的执行消耗计算字节码。Step S103 , associate the first consumption with a preset instruction to obtain the execution consumption calculation bytecode of the program block corresponding to the boundary instruction.
具体地,所述预设指令为预先设置用于计算在智能合约执行阶段时计算边界指令对应程序段的执行消耗的程序,该程序中需要获取当前边界指令执行一次需要的第一消耗,因此将第一消耗关联预设指令,生成对应的执行消耗计算字节码。Specifically, the preset instruction is a program preset for calculating the execution consumption of the program segment corresponding to the boundary instruction during the execution stage of the smart contract. The program needs to obtain the first consumption required for executing the current boundary instruction once, so the The first consumption is associated with a preset instruction, and a corresponding execution consumption calculation bytecode is generated.
步骤S104,将所述执行消耗计算字节码关联所述边界指令进行存储,以使所述智能合约在执行所述边界指令的过程中,执行所述执行消耗计算字节码以获得所述边界指令对应程序块的第一执行消耗。Step S104, storing 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 boundary in the process of executing the boundary instruction The instruction corresponds to the first execution cost of the program block.
具体地,将所述执行消耗计算字节码关联所述边界指令进行存储,使得在智能合约每次执行边界指令时,先通过执行与该边界指令关联的执行消耗字节码计算出第一执行消耗。例如将所述执行消耗计算字节码关联所述边界指令进行存储可以是将执行消耗计算字节码插入至所述边界指令之前的预设位置,所述预设位置可以是所述边界指令与边界指令上一条指令中间的位置,可使得在智能合约每次执行边界指令时,先通过执行对应执行消耗字节码计算出第一执行消耗。执行消耗计算字节码是可以在智能合约执行过程中,在当前执行的字节码指令为边界指令时,执行所述边界指令关联的执行消耗计算字节码,获得所述边界指令对应程序块的第一执行消耗。执行所述边界指令关联的执行消耗计算字节码的具体过程可以是在执行边界指令关联的执行消耗计算字节码的过程中,每检测到开始执行一次所述边界指令时,将所述边界指令关联的第一消耗累加一次至所述第一执行消耗,以更新所述第一执行消耗,所述第一消耗表示边界指令执行一次需要的消耗,第一执行消耗为在执行智能合约时,根据边界指令当前的执行次数和第一消耗计算的边界指令对应程序块的总执行消耗。从而可在智能合约执行到边界指令时,先执行该执行消耗计算字节码,通过执行消耗计算字节码可计算该边界指令需要的第一执行消耗。Specifically, the execution consumption calculation bytecode is stored in association with the boundary instruction, so that each time the smart contract executes the boundary instruction, it first calculates the first execution by executing the execution consumption bytecode associated with the boundary instruction. consume. For example, storing the execution consumption calculation bytecode in association with the boundary instruction may be inserting the execution consumption calculation bytecode into a preset position before the boundary instruction, and the preset position may be the boundary instruction and the boundary instruction. The position in the middle of the previous instruction of the boundary instruction allows the smart contract to calculate the first execution consumption by executing the corresponding execution consumption bytecode each time the boundary instruction is executed. The execution consumption calculation bytecode can be executed in the smart contract execution process, when the currently executed bytecode instruction is a boundary instruction, execute the execution consumption calculation bytecode associated with the boundary instruction, and obtain the program block corresponding to the boundary instruction The first execution consumes. The specific process of executing the execution consumption calculation bytecode associated with the boundary instruction may be in the process of executing the execution consumption calculation bytecode associated with the boundary instruction, every time it is detected that the boundary instruction starts to be executed once, the boundary instruction is executed. The first consumption associated with the instruction is accumulated once to the first execution consumption to update the first execution consumption, the first consumption represents the consumption required for executing the boundary instruction once, and the first execution consumption is when executing the smart contract, The total execution consumption of the program block corresponding to the boundary instruction is calculated according to the current execution times of the boundary instruction and the first consumption. 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.
在一种应用场景中,如执行消耗计算字节码所实现的步骤是先获取边界指令单次的执行消耗(即上述要关联的第一消耗,不同的边界指令的第一消耗可能是不一样的,因此需要在读取的所述智能合约中的字节码指令为边界指令时,计算所述边界指令对应程序块的第一消耗),根据该边界指令单次的执行消耗与边界指令当前的执行次数,可计算出边界指令当前的执行总消耗(即第一执行消耗)。In an application scenario, for example, the step implemented by the execution consumption calculation bytecode is to first obtain the single execution consumption of the boundary instruction (that is, the above-mentioned first consumption to be associated, the first consumption of different boundary instructions may be different) Therefore, 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 boundary instruction The execution times of , the total current execution consumption of the boundary instruction (ie the first execution consumption) can be calculated.
在一个实施例中,执行消耗计算字节码可为通过wasm字节码程序实现的可执行程序,wasm字节码程序具体可通过栈式程序实现。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 specifically be implemented by a stack program.
具体地,wasm(web assembly)字节码是针对浏览器开发的目标语言,具有独立于各种硬件体系结构并具有高可移植性及高效的网络分发效率,wasm字节码已被各大主流浏览器所支持,智能合约的目标字节码可采用wasm字节码形式,并采用独立的wasm虚拟机执行智能合约的程序代码。使用wasm字节码来表示和执行智能合约程序代码,由于其二进制格式具有很高的紧凑性,能够极大的缩小目标代码文件的大小、提高应用程序的网络分发效率。此外wasm字节码其运行时效率可以接近于本地机器码的效率,同时wasm能够提供像C/C++和Rust等类型语言的编译目标,使得采用这些语言编写的应用程序能够运行于浏览器中。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 used by major mainstream Supported by browsers, the target bytecode of the smart contract 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, because its binary format has high compactness, it can greatly reduce the size of the object code file and improve the network distribution efficiency of the application. In addition, the runtime efficiency of wasm bytecode can be close to the efficiency of native machine code, and wasm can provide compilation targets for types of languages such as C/C++ and Rust, so that applications written in these languages can run in the browser.
在一个具体应用场景中,如通过栈式代码程序实现执行消耗计算字节码的步骤可以是:先通过预设第一内部指令(如通过指令“EnvGet”实现),从当前的执行环境中获得变量A(该变量可理解为在第N次执行当前边界指令时,前N减1次执行边界指令对应程序块的总执行消耗),并将变量A先推入预构建的栈中;再根据预设第一wasm标准指令(如通过指令“I64Const”实现)将常数B(该常数可理解为上述获取的第一消耗)推入栈中;接着根据预设第二wasm标准指令(如通过指令“I64Add”实现)从栈中弹出两个数相加然后将结果推入栈,此时栈中已有变量A和常数B,因此从栈中弹出的两个数为变量A和常数B,将变量A和常数B相加然后将结果推入栈;最后再通过预设第二内部指令(如通过指令“EnvPet”实现)从栈中弹出一个值并写回环境变量中,此时栈中的值为变量A和常数B相加的结果,将变量A和常数B相加的结果写回环境变量中,即可实现每检测到开始执行一次所述边界指令时,将所述边界指令关联的第一消耗累加一次至所述第一执行消耗,以更新所述第一执行消耗。In a specific application scenario, for example, the step of implementing the execution consumption calculation bytecode through a stack code program may be: first, by presetting the first internal instruction (for example, through the instruction "EnvGet"), obtaining from the current execution environment Variable A (this variable can be understood as the total execution consumption of the program block corresponding to the first N minus 1 execution of the boundary instruction when the current boundary instruction is executed for the Nth time), and the variable A is first pushed into the pre-built stack; Preset the first wasm standard instruction (such as through the instruction "I64Const") to push the constant B (this constant can be understood as the first consumption of the above acquisition) into the stack; then according to the preset second wasm standard instruction (such as through the instruction "I64Add" implementation) pops two numbers from the stack and adds the result and pushes the result into the stack. At this time, there are variable A and constant B in the stack, so the two numbers popped from the stack are variable A and constant B. The variable A and the constant B are added and the result is pushed onto the stack; finally, a value is popped from the stack and written back to the environment variable by a preset second internal instruction (such as through the instruction "EnvPet") and written back to the environment variable. The value is the result of adding the variable A and the constant B, and the result of adding the variable A and the constant B is written back to the environment variable, so as to realize that every time it is detected that the boundary instruction starts to be executed once, the boundary instruction is associated with the The first consumption is accumulated once to the first execution consumption to update the first execution consumption.
在一个实施例中,所述将所述执行消耗计算字节码关联所述边界指令进行存储,以使所述智能合约在执行所述边界指令的过程中,执行所述执行消耗计算字节码以获得所述边界指令对应程序块的第一执行消耗,包括:将所述执行消耗计算字节码关联所述边界指令进行存储,以使所述智能合约在执行过程中,每检测到开始执行一次所述边界指令时,将所述边界指令关联的第一消耗累加一次至所述第一执行消耗,以更新所述第一执行消耗;In one embodiment, the execution consumption calculation bytecode is stored in association with the boundary instruction, so that the smart contract executes the execution consumption calculation bytecode in the process of executing the boundary instruction Obtaining the first execution consumption of the program block corresponding to the boundary instruction includes: storing the execution consumption calculation bytecode in association with the boundary instruction, so that during the execution process of the smart contract, every time it detects that the execution starts When the boundary instruction is executed once, the first consumption associated with the boundary instruction is accumulated to the first execution consumption, so as to update the first execution consumption;
其中,所述第一消耗为在所述智能合约部署时计算出并存储的所述边界指令执行一次需要的消耗,所述第一执行消耗为所述在执行智能合约时,根据所述边界指令的执行次数和第一消耗计算的所述边界指令对应程序块的总执行消耗。Wherein, the first consumption is the consumption required for one execution of the boundary instruction calculated and stored when the smart contract is deployed, and the first execution consumption is the consumption according to the boundary instruction when the smart contract is executed The number of executions of and the total execution consumption of the program block corresponding to the boundary instruction of the first consumption calculation.
在一个实施例中,在读取智能合约中的字节码指令为顺序执行指令时,计算顺序执行指令的执行消耗,称之为第四执行消耗,将第四执行消耗与该顺序执行指令进行关联存储,以使在智能合约执行过程中,在执行到的字节码指令为顺序执行指令时,直接获取该顺序执行指令的第四执行消耗,获取第五执行消耗,将所述第五执行消耗与所述第四执行消耗进行累加,获得第六执行消耗;其中,所述第五执行消耗为当前顺序执行指令之前已执行的所有字节码指令的总执行消耗;在检测到所述第六执行消耗大于指令消耗阈值时,退出执行所述智能合约,所述指令消耗阈值是表示执行对应的智能合约限制执行消耗。In one embodiment, when the bytecode instruction in the smart contract is read as a sequential execution instruction, the execution consumption of the sequential execution instruction is calculated, which is called the fourth execution consumption, and the fourth execution consumption is combined with the sequential execution instruction. Associative storage, 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 obtained. The 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 that have been executed before the current sequential execution instruction; 6. When the execution consumption is greater than the instruction consumption threshold, the execution of the smart contract is terminated, and the instruction consumption threshold indicates that the execution of the corresponding smart contract limits the execution consumption.
步骤S105,在所述智能合约中所有字节码指令读取完成时,判定所述智能合约的字节码指令已处理完成。Step S105, when all bytecode instructions in the smart contract are read, it is determined that the bytecode instructions of the smart contract have been processed.
具体地,在所述智能合约中所有字节码指令读取完成并通过上述步骤S101至步骤S104进行对应处理时,判定所述智能合约的字节码指令已处理完成,以便本申请提供的智能合约的执行方法执行采用上述部署方法进行部署的智能合约。Specifically, when all the bytecode instructions in the smart contract are read and the corresponding processing is performed 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 provided by this application can be processed. The execution method of the contract executes the smart contract deployed using the above deployment method.
本申请实施例在智能合约的部署过程中,若读取的字节码指令为边界指令,计算该边界指令的第一消耗,将第一消耗关联预设指令得到边界指令对应程序块的执行消耗计算字节码,并将所述执行消耗计算字节码关联所述边界指令进行存储,可以使得在智能合约的执行过程中,直接根据部署阶段关联了第一消耗的执行消耗计算字节码计算第一执行消耗,不需要对边界指令对应程序块中的指令一条一条进行计算,能快速高效的对资源消耗进行衡量。During the deployment process of the smart contract in the embodiment of the present application, if the read bytecode instruction is a boundary instruction, the first consumption of the boundary instruction is calculated, and the first consumption is associated with the preset instruction to obtain the execution consumption of the program block corresponding to the boundary instruction. Calculate the bytecode, and associate the execution consumption calculation bytecode with the boundary instruction for storage, so that in the execution process of the smart contract, the execution consumption calculation bytecode calculation is directly associated with the first consumption in the deployment stage. The first execution consumption does not need to calculate the instructions in the program block corresponding to the boundary instruction one by one, which can quickly and efficiently measure the resource consumption.
实施例二Embodiment 2
本申请实施例提供的智能合约的执行方法可应用于通过实施例一智能合约的部署方法部署了智能合约的终端设备。The smart contract execution method provided in the embodiment of the present application can be applied to a terminal device in which a smart contract is deployed through the smart contract deployment method in Embodiment 1.
请参阅图2,本申请实施例提供的一种智能合约的执行方法,包括:Referring to FIG. 2, a method for executing a smart contract provided by an embodiment of the present application includes:
步骤S201,在接收到执行已部署的智能合约的请求指令时,获取指令消耗阈值。Step S201, when a request instruction for executing the deployed smart contract is received, obtain an instruction consumption threshold.
具体地,上述已部署的智能合约为通过实施例一中的部署方法部署的智能合约,执行已部署的智能合约的请求指令包括指令消耗阈值,所述指令消耗阈值是表示执行对应的智能合约限制执行消耗。Specifically, the above-mentioned deployed smart contract is a smart contract deployed by the deployment method in Embodiment 1, and the request instruction to execute the deployed smart contract includes an instruction consumption threshold, and the instruction consumption threshold is a limit indicating the execution of the corresponding smart contract Execute consumption.
步骤S202,在当前执行的字节码指令为边界指令时,执行所述边界指令关联的执行消耗计算字节码,获得所述边界指令对应程序块的第一执行消耗。Step S202, when the currently executed bytecode instruction is a boundary instruction, execute the execution consumption calculation bytecode associated with the boundary instruction, and obtain the first execution consumption of the program block corresponding to the boundary instruction.
其中,所述边界指令包括指示字节码指令为分支执行指令或循环执行指令的开始指令和结束指令,所述执行消耗计算字节码为在智能合约部署过程中将计算所述边界指令对应程序块的第一消耗关联预设指令得到的可执行程序。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 a program corresponding to the boundary instruction that will be calculated during the smart contract deployment process The first consumption of the block is associated with the executable program obtained by the preset instruction.
在一个实施例中,所述执行所述边界指令关联的执行消耗计算字节码,获得所述边界指令对应程序块的第一执行消耗,包括:在执行所述边界指令关联的执行消耗计算字节码的过程中,每检测到开始执行一次所述边界指令时,将所述边界指令关联的第一消耗累加一次至所述第一执行消耗,以更新所述第一执行消耗;In one embodiment, executing the execution consumption calculation bytecode associated with the boundary instruction, and obtaining the first execution consumption of the program block corresponding to the boundary instruction, includes: executing the execution consumption calculation word associated with the boundary instruction In the process of saving the code, each time it is detected that the boundary instruction starts to be executed once, the first consumption associated with the boundary instruction is accumulated once to the first execution consumption, so as to update the first execution consumption;
其中,所述第一消耗为在所述智能合约部署时计算出并存储的所述边界指令执行一次需要的消耗,在当前执行的字节码指令为边界指令时,所述第一执行消耗为所述在执行智能合约时,根据所述边界指令的执行次数和第一消耗计算的所述边界指令对应程序块的总执行消耗。Wherein, the first consumption is the consumption required to execute the boundary instruction calculated and stored when the smart contract is deployed, and when the currently executed bytecode instruction is the boundary instruction, the first execution consumption is When executing the smart contract, the total execution consumption of the program block corresponding to the boundary instruction is calculated according to the execution times of the boundary instruction and the first consumption.
具体的,上述步骤S202与上述步骤S102至步骤S104中相同、相应或相似的地方,具体可参见步骤S102至步骤S104的相关描述,此处不再赘述。Specifically, the above-mentioned step S202 is the same, corresponding or similar to the above-mentioned steps S102 to S104. For details, please refer to the relevant descriptions of the steps S102 to S104, which will not be repeated here.
步骤S203,获取第二执行消耗,将所述第二执行消耗与所述第一执行消耗进行累加,获得第三执行消耗;其中,所述第二执行消耗为当前边界指令之前已执行的所有字节码指令的总执行消耗。Step S203, obtaining the second execution consumption, accumulating the second execution consumption and the first execution consumption to obtain the third execution consumption; wherein, the second execution consumption is all words executed before the current boundary instruction Total execution cost of section code instructions.
具体地,在智能合约执行过程中,不断累加已执行的字节码指令的总执行消耗,在当前执行的字节码指令为边界指令时,先计算该边界指令的第一执行消耗,并在当前边界指令之前已执行的所有字节码指令的总执行消耗(称为第三执行消耗)与第一执行进行相加,以衡量出继续执行该边界指令的执行消耗会不会大于指令消耗阈值。Specifically, during the execution of the smart contract, the total execution consumption of the executed bytecode instructions is continuously accumulated, and when the currently executed bytecode instruction is a boundary instruction, the first execution consumption of the boundary instruction is calculated first, and the The total execution consumption of all bytecode instructions executed before the current boundary instruction (called the third execution consumption) is added to the first execution to measure whether the execution consumption of continuing to execute the boundary instruction will be greater than the instruction consumption threshold .
步骤S204,在检测到所述第三执行消耗大于所述指令消耗阈值时,退出执行所述智能合约。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.
具体地,在检测到所述第三执行消耗大于所述指令消耗阈值时,就表示衡量出继续执行该边界指令的执行消耗会大于指令消耗阈值,因此直接退出执行所述智能合约。Specifically, when it is detected that the third execution consumption is greater than the instruction consumption threshold, it means 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.
在一个实施例中,请参阅图3,所述执行方法还包括:In one embodiment, referring to FIG. 3, the execution method further includes:
步骤S301,在当前执行的字节码指令为顺序执行指令时,获取所述顺序执行指令的第四执行消耗。Step S301, when the currently executed bytecode instruction is a sequential execution instruction, obtain the fourth execution consumption of the sequential execution instruction.
具体地,在执行到智能合约的字节码指令为顺序执行指令时,先获取该顺序指令的执行消耗,称之为第四执行消耗。第四执行消耗可以是在智能合约部署的过程中,在读取智能合约中的字节码指令为顺序执行指令时,计算顺序执行指令的第四执行消耗,并将第四执行消耗与该顺序执行指令进行关联存储,因此在执行智能合约的过程中直接获取第四执行消耗即可;或者第四执行消耗也可以是在执行智能合约的过程中,当前执行的字节码指令为顺序执行指令时,根据该顺序执行指令所占用的字节码的大小进行计算得到第四执行消耗。Specifically, when the bytecode instruction executed to the smart contract is a sequential execution instruction, the execution consumption of the sequential instruction is obtained first, which is called the fourth execution consumption. The fourth execution cost may be, in the process of smart contract deployment, when the bytecode instruction in the smart contract is read as a sequential execution instruction, the fourth execution cost of the sequential execution instruction is calculated, and the fourth execution cost is compared with the sequence. The execution instructions are stored associatively, so the fourth execution consumption can be directly obtained during the execution of the smart contract; or the fourth execution consumption can also be in the process of executing the smart contract, and the currently executed bytecode instruction is a sequential execution instruction , the fourth execution consumption is obtained by calculating according to the size of the bytecode occupied by the sequentially executed instructions.
步骤S302,获取第五执行消耗,将所述第五执行消耗与所述第四执行消耗进行累加,获得第六执行消耗;其中,所述第五执行消耗为当前顺序执行指令之前已执行的所有字节码指令的总执行消耗。Step S302, obtaining the fifth execution consumption, and accumulating the fifth execution consumption and the fourth execution consumption to obtain the sixth execution consumption; wherein, the fifth execution consumption is all the executed instructions before the current sequential execution instruction. Total execution cost of bytecode instructions.
具体地,在智能合约执行过程中,不断累加已执行的字节码指令的总执行消耗,在当前执行的字节码指令为顺序执行指令时,先获取顺序执行指令的第四执行消耗,并在当前顺序执行指令之前已执行的所有字节码指令的总执行消耗(称为第五执行消耗)与第四执行消耗进行相加,以衡量出继续执行该顺序执行指令的执行消耗会不会大于指令消耗阈值。Specifically, during the execution of the smart contract, the total execution consumption of the executed bytecode instructions is continuously accumulated, and when the currently executed bytecode instruction is a sequential execution instruction, the fourth execution consumption of the sequential execution instruction is obtained first, and The total execution cost of all bytecode instructions executed before the current sequential execution instruction (called the fifth execution cost) is added to the fourth execution cost to measure whether the execution cost of continuing the sequential execution of the instruction will be Greater than the instruction consumption threshold.
步骤S303,在检测到所述第六执行消耗大于所述指令消耗阈值时,退出执行所述智能合约。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.
具体地,在检测到所述第六执行消耗大于所述指令消耗阈值时,就表示衡量出继续执行该顺序执行指令的执行消耗会大于指令消耗阈值,因此直接退出执行所述智能合约。Specifically, when it is detected that the sixth execution consumption is greater than the instruction consumption threshold, it means 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.
在一个具体应用中,在检测到所述第三执行消耗大于所述指令消耗阈值时,退出执行所述智能合约,以及在检测到所述第六执行消耗大于所述指令消耗阈值时,退出执行所述智能合约,具体可以通过栈式代码程序实现:如先通过预设第三内部指令(如通过指令“EnvGet”实现),从当前执行环境中得到变量C(变量C为执行当前指令以及当前指令之前所有指令所需要的总执行消耗,如执行的是边界指令,变量C为上述第三执行消耗;执行的是顺序执行指令,变量C为上述第六执行消耗);再根据预设第三wasm标准指令(如通过指令“I64Const”实现)表示将常数(limit值,即指令消耗阈值)推入栈中;接着根据预设第四wasm标准指令(如通过指令I64Ge_U实现),将栈上存储的两个值比较,此时栈上第一个值是指令消耗阈值,栈上第二个值是第三执行消耗或第六执行消耗,如果第一个值大于第二个值返回1,如果第一个值小于或等于第二个值返回0,并将返回值至压入栈;再根据预设第五wasm标准指令(如通过if实现),判断栈顶是否为0,为0表示指令消耗阈值小于或等于第三执行消耗或第六执行消耗;判断栈顶为0时通过预设第四内部指令(如通过指令Break实现)退出执行并抛出错误。通过栈式代码程序可实现判断当前代码执行消耗是否超出执行限制,如果超出限制则停止执行。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 is exited The smart contract can be specifically implemented through a stack code program: for example, by presetting the third internal instruction (such as through the instruction "EnvGet"), the variable C is obtained from the current execution environment (the variable C is the execution of the current instruction and the current The total execution consumption required by all the instructions before the instruction, if the boundary instruction is executed, the variable C is the above-mentioned third execution consumption; if the sequential execution instruction is executed, the variable C is the above-mentioned sixth execution consumption); and then according to the preset third The wasm standard instruction (such as implemented by the instruction "I64Const") means to push the constant (limit value, that is, the instruction consumption threshold) into the stack; then according to the preset fourth wasm standard instruction (such as implemented by the instruction I64Ge_U), the stack is stored on the stack. The first value on the stack is the instruction consumption threshold, 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 returns 1, if The first value is less than or equal to the second value and returns 0, and pushes the return value into the stack; then according to the preset fifth wasm standard instruction (such as through if), it is judged whether the top of the stack is 0, and 0 means the instruction The consumption threshold is less than or equal to the third execution consumption or the sixth execution consumption; when it is judged that the top of the stack is 0, the fourth internal instruction is preset (for example, implemented by the instruction Break) to exit the execution and throw an error. Through the stack code program, it is possible to judge whether the current code execution consumption exceeds the execution limit, and stop the execution if it exceeds the limit.
本申请实施例在智能合约执行过程中,当执行的字节码为边界指令时,根据所述边界指令关联的执行消耗计算字节码,计算所述边界指令对应程序块的第一执行消耗;由于执行消耗计算字节码是在智能合约部署过程中将计算所述边界指令对应程序块的第一消耗关联预设指令得到的可执行程序,直接根据执行消耗计算字节码,获得所述边界指令对应程序块的第一执行消耗,不需要对边界指令对应程序块中的指令一条一条进行计算,能快速高效的对资源消耗进行衡量。并且获取第二执行消耗,将所述第二执行消耗与所述第一执行消耗进行累加,获得第三执行消耗;其中,所述第二执行消耗为当前边界指令之前已执行的所有字节码指令的总执行消耗;在检测到所述第三执行消耗大于所述指令消耗阈值时,退出执行所述智能合约,可在第三执行消耗大于所述指令消耗阈值时,退出智能合约的执行,从而可提高智能合约的执行稳定性。During the execution of the smart contract in the embodiment of the present application, when the executed bytecode is a boundary instruction, the bytecode is calculated according to the execution consumption associated with the boundary instruction, and the first execution consumption of the program block corresponding to the boundary instruction is calculated; Since the execution consumption calculation bytecode is an executable program obtained by correlating the first consumption of the program block corresponding to the boundary instruction with the preset instruction in the smart contract deployment process, the bytecode is directly calculated according to the execution consumption to obtain the boundary The first execution consumption of the program block corresponding to the instruction does not need to be calculated one by one in the program block corresponding to the boundary instruction, and the resource consumption can be measured quickly and efficiently. And obtain the second execution consumption, accumulate the second execution consumption and the first execution consumption, and obtain the third execution consumption; wherein, the second execution consumption is all bytecodes that have been executed before the current boundary instruction The total execution consumption of the 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 the execution of the smart contract can be exited when the third execution consumption is greater than the instruction consumption threshold, Thus, the execution stability of smart contracts can be improved.
实施例三Embodiment 3
本申请实施例还提供一种智能合约的部署装置,用于执行上述智能合约的部署方法实施例中的步骤。如图4所示,本申请实施例提供的智能合约的部署装置400包括:The embodiments of the present application further provide a smart contract deployment device, which is used to execute the steps in the above smart contract deployment method embodiments. As shown in FIG. 4 , the smart contract deployment device 400 provided in the embodiment of the present application includes:
接收模块401,用于当接收到部署所述智能合约的请求指令时,按顺序读取所述智能合约中的字节码指令;A receiving module 401, configured to read bytecode instructions in the smart contract in sequence when receiving a request instruction for deploying the smart contract;
计算模块402,用于在读取的所述智能合约中的字节码指令为边界指令时,计算所述边界指令对应程序块的第一消耗;其中,所述边界指令包括指示字节码指令为分支执行指令或循环执行指令的开始指令和结束指令;The calculation module 402 is configured to calculate the first consumption of the program block corresponding to the boundary instruction when the read bytecode instruction in the smart contract is a boundary instruction; wherein, the boundary instruction includes an instruction bytecode instruction Start and end instructions for branch execution instructions or loop execution instructions;
得到模块403,用于将所述第一消耗关联预设指令,得到所述边界指令对应程序块的执行消耗计算字节码;Obtaining module 403, for associating the first consumption with a preset instruction to obtain the execution consumption calculation bytecode of the program block corresponding to the boundary instruction;
关联模块404,用于将所述执行消耗计算字节码关联所述边界指令进行存储,以使所述智能合约在执行所述边界指令的过程中,执行所述执行消耗计算字节码以获得所述边界指令对应程序块的第一执行消耗;The association module 404 is configured to associate the execution consumption calculation bytecode with the boundary instruction for storage, so that in the process of executing the boundary instruction, the smart contract executes the execution consumption calculation bytecode to obtain The boundary instruction corresponds to the first execution consumption of the program block;
处理完成模块405,用于在所述智能合约中所有字节码指令读取完成时,判定所述智能合约的字节码指令已处理完成。The processing completion module 405 is configured to determine that the bytecode instructions of the smart contract have been processed when all bytecode instructions in the smart contract are read.
在一个实施例中,所述计算模块402具体用于所述在读取的所述智能合约中的字节码指令为边界指令时,将所述边界指令对应程序块中每一条指令的执行消耗进行累加,得到所述第一消耗。In one embodiment, the computing module 402 is specifically configured to, when the read bytecode instruction in the smart contract is a boundary instruction, consume the execution consumption of each instruction in the program block corresponding to the boundary instruction Accumulation is performed to obtain the first consumption.
在一个实施例中,所述关联模块具体用于:将所述执行消耗计算字节码关联所述边界指令进行存储,以使所述智能合约在执行过程中,每检测到开始执行一次所述边界指令时,将所述边界指令关联的第一消耗累加一次至所述第一执行消耗,以更新所述第一执行消耗;In one embodiment, the associating module is specifically configured 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 it detects that it starts to execute the When the boundary instruction is used, the first consumption associated with the boundary instruction is accumulated to the first execution consumption once to update the first execution consumption;
其中,所述第一消耗为在所述智能合约部署时计算出并存储的所述边界指令执行一次需要的消耗,所述第一执行消耗为所述在执行智能合约时,根据所述边界指令的执行次数和第一消耗计算的所述边界指令对应程序块的总执行消耗。Wherein, the first consumption is the consumption required for one execution of the boundary instruction calculated and stored when the smart contract is deployed, and the first execution consumption is the consumption according to the boundary instruction when the smart contract is executed The number of executions of and the total execution consumption of the program block corresponding to the boundary instruction of the first consumption calculation.
本申请实施例在智能合约的部署过程中,若读取的字节码指令为边界指令,计算该边界指令的第一消耗,将第一消耗关联预设指令得到边界指令对应程序块的执行消耗计算字节码,并将所述执行消耗计算字节码关联所述边界指令进行存储,可以使得在智能合约的执行过程中,直接根据部署阶段关联了第一消耗的执行消耗计算字节码计算第一执行消耗,不需要对边界指令对应程序块中的指令一条一条进行计算,能快速高效的对资源消耗进行衡量。During the deployment process of the smart contract in the embodiment of the present application, if the read bytecode instruction is a boundary instruction, the first consumption of the boundary instruction is calculated, and the first consumption is associated with the preset instruction to obtain the execution consumption of the program block corresponding to the boundary instruction. Calculate the bytecode, and associate the execution consumption calculation bytecode with the boundary instruction for storage, so that in the execution process of the smart contract, the execution consumption calculation bytecode calculation is directly associated with the first consumption in the deployment stage. The first execution consumption does not need to calculate the instructions in the program block corresponding to the boundary instruction one by one, which can quickly and efficiently measure the resource consumption.
实施例四Embodiment 4
本申请实施例还提供一种智能合约的执行装置,用于执行上述智能合约的执行方法实施例中的步骤。如图5所示,本申请实施例提供的智能合约的执行装置500包括:Embodiments of the present application further provide an apparatus for executing a smart contract, which is used to execute the steps in the above-mentioned embodiments of the method for executing a smart contract. As shown in FIG. 5 , the execution device 500 of the smart contract provided by the embodiment of the present application includes:
第一获取模块501,用于在接收到执行已部署的智能合约的请求指令时,获取指令消耗阈值;The first obtaining module 501 is configured to obtain the instruction consumption threshold when receiving the request instruction for executing the deployed smart contract;
计算模块502,用于在当前执行的字节码指令为边界指令时,执行所述边界指令关联的执行消耗计算字节码,获得所述边界指令对应程序块的第一执行消耗;其中,所述边界指令包括指示字节码指令为分支执行指令或循环执行指令的开始指令和结束指令,所述执行消耗计算字节码为在智能合约部署过程中将计算所述边界指令对应程序块的第一消耗关联预设指令得到的可执行程序;The calculation module 502 is 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; 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 executable program obtained by consuming the associated preset instruction;
第二获取模块503,用于获取第二执行消耗,将所述第二执行消耗与所述第一执行消耗进行累加,获得第三执行消耗;其中,所述第二执行消耗为当前边界指令之前已执行的所有字节码指令的总执行消耗;The second obtaining module 503 is configured to obtain the second execution consumption, and accumulate the second execution consumption and the first execution consumption to obtain the third execution consumption; wherein, the second execution consumption is before the current boundary instruction The total execution cost of all bytecode instructions executed;
第一退出模块504,用于在检测到所述第三执行消耗大于所述指令消耗阈值时,退出执行所述智能合约。The first exit module 504 is 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.
在一个实施例中,所述计算模块502具体用于:在执行所述边界指令关联的执行消耗计算字节码的过程中,每检测到开始执行一次所述边界指令时,将所述边界指令关联的第一消耗累加一次至所述第一执行消耗,以更新所述第一执行消耗;In one embodiment, the calculation module 502 is specifically configured to: in the process of executing the execution consumption calculation bytecode associated with the boundary instruction, every time it is detected that the boundary instruction starts to be executed once, calculate the boundary instruction The associated first consumption is accumulated once to the first execution consumption to update the first execution consumption;
其中,所述第一消耗为在所述智能合约部署时计算出并存储的所述边界指令执行一次需要的消耗,所述第一执行消耗为所述在执行智能合约时,根据所述边界指令的执行次数和第一消耗计算的所述边界指令对应程序块的总执行消耗。Wherein, the first consumption is the consumption required for one execution of the boundary instruction calculated and stored when the smart contract is deployed, and the first execution consumption is the consumption according to the boundary instruction when the smart contract is executed The number of executions of and the total execution consumption of the program block corresponding to the boundary instruction of the first consumption calculation.
在一个实施例中,执行装置500还包括:In one embodiment, the execution device 500 further includes:
第三获取模块,用于在当前执行的字节码指令为顺序执行指令时,获取所述顺序执行指令的第四执行消耗;a third obtaining module, configured to obtain the fourth execution consumption of the sequential execution instruction when the currently executed bytecode instruction is a sequential execution instruction;
第四获取模块,用于获取第五执行消耗,将所述第五执行消耗与所述第四执行消耗进行累加,获得第六执行消耗;其中,所述第五执行消耗为当前顺序执行指令之前已执行的所有字节码指令的总执行消耗;a fourth acquisition module, configured to acquire the fifth execution consumption, and accumulate the fifth execution consumption and the fourth execution consumption to obtain the sixth execution consumption; wherein, the fifth execution consumption is before the current sequential execution instruction The total execution cost of all bytecode instructions executed;
第二退出模块,用于在检测到所述第六执行消耗大于所述指令消耗阈值时,退出执行所述智能合约。The second exit module is configured to exit the execution of the smart contract when it is detected that the sixth execution consumption is greater than the instruction consumption threshold.
本申请实施例在智能合约执行过程中,当执行的字节码为边界指令时,根据所述边界指令关联的执行消耗计算字节码,计算所述边界指令对应程序块的第一执行消耗;由于执行消耗计算字节码是在智能合约部署过程中将计算所述边界指令对应程序块的第一消耗关联预设指令得到的可执行程序,直接根据执行消耗计算字节码,获得所述边界指令对应程序块的第一执行消耗,不需要对边界指令对应程序块中的指令一条一条进行计算,能快速高效的对资源消耗进行衡量。并且获取第二执行消耗,将所述第二执行消耗与所述第一执行消耗进行累加,获得第三执行消耗;其中,所述第二执行消耗为当前边界指令之前已执行的所有字节码指令的总执行消耗;在检测到所述第三执行消耗大于所述指令消耗阈值时,退出执行所述智能合约,可在第三执行消耗大于所述指令消耗阈值时,退出智能合约的执行,从而可提高智能合约的执行稳定性。During the execution of the smart contract in the embodiment of the present application, when the executed bytecode is a boundary instruction, the bytecode is calculated according to the execution consumption associated with the boundary instruction, and the first execution consumption of the program block corresponding to the boundary instruction is calculated; Since the execution consumption calculation bytecode is an executable program obtained by correlating the first consumption of the program block corresponding to the boundary instruction with the preset instruction in the smart contract deployment process, the bytecode is directly calculated according to the execution consumption to obtain the boundary The first execution consumption of the program block corresponding to the instruction does not need to be calculated one by one in the program block corresponding to the boundary instruction, and the resource consumption can be measured quickly and efficiently. And obtain the second execution consumption, accumulate the second execution consumption and the first execution consumption, and obtain the third execution consumption; wherein, the second execution consumption is all bytecodes that have been executed before the current boundary instruction The total execution consumption of the 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 the execution of the smart contract can be exited when the third execution consumption is greater than the instruction consumption threshold, Thus, the execution stability of smart contracts can be improved.
实施例五Embodiment 5
如图6所示,本申请的一个实施例还提供一种终端设备600包括:处理器601,存储器602以及存储在所述存储器602中并可在所述处理器601上运行的计算机程序603,例如智能合约的部署程序和/或执行程序。所述处理器601执行所述计算机程序603时实现上述各个智能合约的部署方法和/或各个智能合约的执行方法实施例中的步骤。所述处理器601执行所述计算机程序603时实现上述各装置实施例中各模块的功能,例如实施例三和/或实施例四的功能。As shown in FIG. 6 , an embodiment of the present application further provides a terminal device 600 including: a processor 601, a memory 602, and a computer program 603 stored in the memory 602 and running on the processor 601, For example, the deployer and/or the executor of the smart contract. When the processor 601 executes the computer program 603, the steps in the above-mentioned embodiments of the 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 the modules in the foregoing apparatus embodiments are implemented, for example, the functions of the third embodiment and/or the fourth embodiment.
示例性的,所述计算机程序603可以被分割成一个或多个模块,所述一个或者多个模块被存储在所述存储器602中,并由所述处理器601执行,以完成本申请。所述一个或多个模块可以是能够完成特定功能的一系列计算机程序指令段,该指令段用于描述所述计算机程序603在所述终端设备600中的执行过程。Exemplarily, the computer program 603 may be divided into one or more modules, and the one or more modules 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 accomplishing specific functions, and the instruction segments are used to describe the execution process of the computer program 603 in the terminal device 600 .
所述终端设备600可以是服务器、平板电脑、可穿戴设备、车载设备、增强现实(augmented reality,AR)/虚拟现实(virtual reality,VR)设备、笔记本电脑、超级移动个人计算机(ultra-mobile personal computer,UMPC)、上网本、个人数字助理(personal digital assistant,PDA)、手机、或者其他计算设备。所述终端设备可包括,但不仅限于,处理器601,存储器602。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, and an ultra-mobile personal computer (ultra-mobile personal computer). computer, UMPC), netbooks, personal digital assistants (personal digital assistants) assistant, PDA), cell phone, or other computing device. The terminal device may include, but is not limited to, the processor 601 and the memory 602 .
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述或记载的部分,可以参见其它实施例的相关描述。In the foregoing embodiments, the description of each embodiment has its own emphasis. For parts that are not described or described in detail in a certain embodiment, reference may be made to the relevant descriptions of other embodiments.
以上所述实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围,均应包含在本申请的保护范围之内。The above-mentioned embodiments are only used to illustrate the technical solutions of the present application, but not to limit them; although the present application has been described in detail with reference to the above-mentioned embodiments, those of ordinary skill in the art should understand that: it is still possible to implement the above-mentioned implementations. The technical solutions described in the examples are modified, or some technical features thereof are equivalently replaced; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions in the embodiments of the application, and should be included in the within the scope of protection of this application.

Claims (14)

  1. 一种智能合约的部署方法,其特征在于,包括: A method for deploying a smart contract, comprising:
    当接收到部署所述智能合约的请求指令时,按顺序读取所述智能合约中的字节码指令;When receiving the request instruction for deploying the smart contract, read the bytecode instructions in the smart contract in sequence;
    在读取的所述智能合约中的字节码指令为边界指令时,计算所述边界指令对应程序块的第一消耗;其中,所述边界指令包括指示字节码指令为分支执行指令或循环执行指令的开始指令和结束指令;When the read bytecode instruction 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 indicating that the bytecode instruction is a branch execution instruction or a loop Execute the start command and end command of the command;
    将所述第一消耗关联预设指令,得到所述边界指令对应程序块的执行消耗计算字节码;Associating the first consumption with a preset instruction to obtain the execution consumption calculation bytecode of the program block corresponding to the boundary instruction;
    将所述执行消耗计算字节码关联所述边界指令进行存储,以使所述智能合约在执行所述边界指令的过程中,执行所述执行消耗计算字节码以获得所述边界指令对应程序块的第一执行消耗;storing the execution consumption calculation bytecode in association with the boundary instruction, so that in the process of executing the boundary instruction, the smart contract executes the execution consumption calculation bytecode to obtain a program corresponding to the boundary instruction the first execution consumption of the block;
    在所述智能合约中所有字节码指令读取完成时,判定所述智能合约的字节码指令已处理完成。When all bytecode instructions in the smart contract are read, it is determined that the bytecode instructions of the smart contract have been processed.
  2. 根据权利要求1所述的部署方法,其特征在于,所述在读取的所述智能合约中的字节码指令为边界指令时,计算所述边界指令对应程序块的第一消耗,包括: The deployment method according to claim 1, wherein, when the read bytecode instruction in the smart contract is a boundary instruction, calculating the first consumption of the program block corresponding to the boundary instruction comprises:
    所述在读取的所述智能合约中的字节码指令为边界指令时,将所述边界指令对应程序块中每一条指令的执行消耗进行累加,得到所述第一消耗。When the read bytecode instruction in the smart contract 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. 根据权利要求1所述的部署方法,其特征在于,所述将所述执行消耗计算字节码关联所述边界指令进行存储,以使所述智能合约在执行所述边界指令的过程中,执行所述执行消耗计算字节码以获得所述边界指令对应程序块的第一执行消耗,包括: The deployment method according to claim 1, wherein the execution consumption calculation bytecode is associated with the boundary instruction for storage, so that the smart contract executes the boundary instruction in the process of executing the boundary instruction. The execution consumption calculates the bytecode to obtain the first execution consumption of the program block corresponding to the boundary instruction, including:
    将所述执行消耗计算字节码关联所述边界指令进行存储,以使所述智能合约在执行过程中,每检测到开始执行一次所述边界指令时,将所述边界指令关联的第一消耗累加一次至所述第一执行消耗,以更新所述第一执行消耗;The execution consumption calculation bytecode is stored in association with the boundary instruction, so that during the execution process of the smart contract, each time it detects that the boundary instruction starts to be executed once, the first consumption associated with the boundary instruction is associated with the boundary instruction. Accumulate once to the first execution consumption to update the first execution consumption;
    其中,所述第一消耗为在所述智能合约部署时计算出并存储的所述边界指令执行一次需要的消耗,所述第一执行消耗为所述在执行智能合约时,根据所述边界指令的执行次数和第一消耗计算的所述边界指令对应程序块的总执行消耗。Wherein, the first consumption is the consumption required for one execution of the boundary instruction calculated and stored when the smart contract is deployed, and the first execution consumption is the consumption according to the boundary instruction when the smart contract is executed The number of executions of and the total execution consumption of the program block corresponding to the boundary instruction of the first consumption calculation.
  4. 根据权利要求1所述的部署方法,其特征在于,所述将所述执行消耗计算字节码关联所述边界指令进行存储,包括: The deployment method according to claim 1, wherein the storing the execution consumption calculation bytecode in association with the boundary instruction comprises:
    将所述执行消耗计算字节码插入至所述边界指令之前的预设位置。Inserting the execution cost calculation bytecode at a preset position before the boundary instruction.
  5. 根据权利要求1所述的部署方法,其特征在于,所述执行消耗计算字节码为通过wasm字节码程序实现的可执行程序。 The deployment method according to claim 1, wherein the execution consumption calculation bytecode is an executable program implemented by a wasm bytecode program.
  6. 一种智能合约的执行方法,其特征在于,包括: A method for executing a smart contract, comprising:
    在接收到执行已部署的智能合约的请求指令时,获取指令消耗阈值;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 associated with the boundary instruction is executed to calculate the bytecode, and the first execution consumption of the program block corresponding to the boundary instruction is obtained; wherein, the boundary instruction includes a pointer The section code instruction is the start instruction and the end instruction of the branch execution instruction or the loop execution instruction, and the execution consumption calculation bytecode is a preset instruction that associates the first consumption of the program block corresponding to the boundary instruction with the calculation during the smart contract deployment process the resulting executable program;
    获取第二执行消耗,将所述第二执行消耗与所述第一执行消耗进行累加,获得第三执行消耗;其中,所述第二执行消耗为当前边界指令之前已执行的所有字节码指令的总执行消耗;Obtain the second execution consumption, accumulate the second execution consumption and the first execution consumption, and obtain the third execution consumption; wherein, the second execution consumption is all bytecode instructions that have been executed before the current boundary instruction The total execution cost of ;
    在检测到所述第三执行消耗大于所述指令消耗阈值时,退出执行所述智能合约。When it is detected that the third execution consumption is greater than the instruction consumption threshold, the execution of the smart contract is exited.
  7. 根据权利要求6所述的执行方法,其特征在于,所述执行所述边界指令关联的执行消耗计算字节码,获得所述边界指令对应程序块的第一执行消耗,包括: The execution method according to claim 6, wherein the executing the execution consumption calculation bytecode associated with the boundary instruction, and obtaining the first execution consumption of the program block corresponding to the boundary instruction, comprises:
    在执行所述边界指令关联的执行消耗计算字节码的过程中,每检测到开始执行一次所述边界指令时,将所述边界指令关联的第一消耗累加一次至所述第一执行消耗,以更新所述第一执行消耗;In the process of calculating the bytecode of execution consumption associated with the boundary instruction, each time it is detected that the boundary instruction starts to be executed once, the first consumption associated with the boundary instruction is accumulated once to the first execution consumption, to update the first execution consumption;
    其中,所述第一消耗为在所述智能合约部署时计算出并存储的所述边界指令执行一次需要的消耗,所述第一执行消耗为所述在执行智能合约时,根据所述边界指令的执行次数和第一消耗计算的所述边界指令对应程序块的总执行消耗。Wherein, the first consumption is the consumption required for one execution of the boundary instruction calculated and stored when the smart contract is deployed, and the first execution consumption is the consumption according to the boundary instruction when the smart contract is executed The number of executions of and the total execution consumption of the program block corresponding to the boundary instruction of the first consumption calculation.
  8. 根据权利要求6所述的执行方法,其特征在于,所述执行方法还包括: The execution method according to claim 6, wherein the execution method further comprises:
    在当前执行的字节码指令为顺序执行指令时,获取所述顺序执行指令的第四执行消耗;When the currently executed bytecode instruction is a sequential execution instruction, obtain the fourth execution consumption of the sequential execution instruction;
    获取第五执行消耗,将所述第五执行消耗与所述第四执行消耗进行累加,获得第六执行消耗;其中,所述第五执行消耗为当前顺序执行指令之前已执行的所有字节码指令的总执行消耗;Obtain the fifth execution consumption, and accumulate the fifth execution consumption and the fourth execution consumption to obtain the sixth execution consumption; wherein, the fifth execution consumption is all bytecodes that have been executed before the current sequential execution instruction The total execution cost of the 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.
  9. 一种终端设备,其特征在于,包括存储器和处理器,所述存储器上保存有可在所述处理器上运行的智能合约的部署程序,以及所述存储器上保存有可在所述处理器上运行的智能合约的执行程序; A terminal device, characterized in that it includes a memory and a processor, the memory stores a deployment program of a smart contract that can run on the processor, and the memory stores a program that can run on the processor The executor of the running smart contract;
    所述智能合约的部署程序被所述处理器执行时实现的方法步骤包括:The method steps implemented when the deployment program of the smart contract is executed by the processor include:
    当接收到部署所述智能合约的请求指令时,按顺序读取所述智能合约中的字节码指令;When receiving the request instruction for deploying the smart contract, read the bytecode instructions in the smart contract in sequence;
    在读取的所述智能合约中的字节码指令为边界指令时,计算所述边界指令对应程序块的第一消耗;其中,所述边界指令包括指示字节码指令为分支执行指令或循环执行指令的开始指令和结束指令;When the read bytecode instruction 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 indicating that the bytecode instruction is a branch execution instruction or a loop Execute the start command and end command of the command;
    将所述第一消耗关联预设指令,得到所述边界指令对应程序块的执行消耗计算字节码;Associating the first consumption with a preset instruction to obtain the execution consumption calculation bytecode of the program block corresponding to the boundary instruction;
    将所述执行消耗计算字节码关联所述边界指令进行存储,以使所述智能合约在执行所述边界指令的过程中,执行所述执行消耗计算字节码以获得所述边界指令对应程序块的第一执行消耗;storing the execution consumption calculation bytecode in association with the boundary instruction, so that in the process of executing the boundary instruction, the smart contract executes the execution consumption calculation bytecode to obtain a program corresponding to the boundary instruction the first execution consumption of the block;
    在所述智能合约中所有字节码指令读取完成时,判定所述智能合约的字节码指令已处理完成;When all bytecode instructions in the smart contract are read, it is determined that the bytecode instructions of the smart contract have been processed;
    所述智能合约的执行程序被所述处理器执行时实现的方法步骤包括:The method steps implemented when the execution program of the smart contract is executed by the processor 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 associated with the boundary instruction is executed to calculate the bytecode, and the first execution consumption of the program block corresponding to the boundary instruction is obtained; wherein, the boundary instruction includes a pointer The section code instruction is the start instruction and the end instruction of the branch execution instruction or the loop execution instruction, and the execution consumption calculation bytecode is a preset instruction that associates the first consumption of the program block corresponding to the boundary instruction with the calculation during the smart contract deployment process the resulting executable program;
    获取第二执行消耗,将所述第二执行消耗与所述第一执行消耗进行累加,获得第三执行消耗;其中,所述第二执行消耗为当前边界指令之前已执行的所有字节码指令的总执行消耗;Obtain the second execution consumption, accumulate the second execution consumption and the first execution consumption, and obtain the third execution consumption; wherein, the second execution consumption is all bytecode instructions that have been executed before the current boundary instruction The total execution cost of ;
    在检测到所述第三执行消耗大于所述指令消耗阈值时,退出执行所述智能合约。When it is detected that the third execution consumption is greater than the instruction consumption threshold, the execution of the smart contract is exited.
  10. 根据权利要求9所述的终端设备,其特征在于,所述在读取的所述智能合约中的字节码指令为边界指令时,计算所述边界指令对应程序块的第一消耗,包括: The terminal device according to claim 9, wherein, when the read bytecode instruction in the smart contract is a boundary instruction, calculating the first consumption of the program block corresponding to the boundary instruction comprises:
    所述在读取的所述智能合约中的字节码指令为边界指令时,将所述边界指令对应程序块中每一条指令的执行消耗进行累加,得到所述第一消耗。When the read bytecode instruction in the smart contract 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.
  11. 根据权利要求9所述的终端设备,其特征在于,所述将所述执行消耗计算字节码关联所述边界指令进行存储,以使所述智能合约在执行所述边界指令的过程中,执行所述执行消耗计算字节码以获得所述边界指令对应程序块的第一执行消耗,包括: The terminal device according to claim 9, wherein the execution consumption calculation bytecode is stored in association with the boundary instruction, so that the smart contract executes the boundary instruction in the process of executing the boundary instruction. The execution consumption calculates the bytecode to obtain the first execution consumption of the program block corresponding to the boundary instruction, including:
    将所述执行消耗计算字节码关联所述边界指令进行存储,以使所述智能合约在执行过程中,每检测到开始执行一次所述边界指令时,将所述边界指令关联的第一消耗累加一次至所述第一执行消耗,以更新所述第一执行消耗;The execution consumption calculation bytecode is stored in association with the boundary instruction, so that during the execution process of the smart contract, each time it detects that the boundary instruction starts to be executed once, the first consumption associated with the boundary instruction is associated with the boundary instruction. Accumulate once to the first execution consumption to update the first execution consumption;
    其中,所述第一消耗为在所述智能合约部署时计算出并存储的所述边界指令执行一次需要的消耗,所述第一执行消耗为所述在执行智能合约时,根据所述边界指令的执行次数和第一消耗计算的所述边界指令对应程序块的总执行消耗。Wherein, the first consumption is the consumption required for one execution of the boundary instruction calculated and stored when the smart contract is deployed, and the first execution consumption is the consumption according to the boundary instruction when the smart contract is executed The number of executions of and the total execution consumption of the program block corresponding to the boundary instruction of the first consumption calculation.
  12. 根据权利要求9所述的终端设备,其特征在于,所述将所述执行消耗计算字节码关联所述边界指令进行存储,包括: The terminal device according to claim 9, wherein the storing the execution consumption calculation bytecode in association with the boundary instruction comprises:
    将所述执行消耗计算字节码插入至所述边界指令之前的预设位置。Inserting the execution cost calculation bytecode at a preset position before the boundary instruction.
  13. 根据权利要求9所述的终端设备,其特征在于,所述执行消耗计算字节码为通过wasm字节码程序实现的可执行程序。 The terminal device according to claim 9, wherein the execution consumption calculation bytecode is an executable program implemented by a wasm bytecode program.
  14. 根据权利要求9所述的终端设备,其特征在于,所述智能合约的执行程序被所述处理器执行时实现的方法步骤还包括: The terminal device according to claim 9, wherein the method steps implemented when the execution program of the smart contract is executed by the processor further comprises:
    在当前执行的字节码指令为顺序执行指令时,获取所述顺序执行指令的第四执行消耗;When the currently executed bytecode instruction is a sequential execution instruction, obtain the fourth execution consumption of the sequential execution instruction;
    获取第五执行消耗,将所述第五执行消耗与所述第四执行消耗进行累加,获得第六执行消耗;其中,所述第五执行消耗为当前顺序执行指令之前已执行的所有字节码指令的总执行消耗;Obtain the fifth execution consumption, and accumulate the fifth execution consumption and the fourth execution consumption to obtain the sixth execution consumption; wherein, the fifth execution consumption is all bytecodes that have been executed before the current sequential execution instruction The total execution cost of the 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.
PCT/CN2020/140281 2020-12-28 2020-12-28 Smart contract deployment method and apparatus, smart contract execution method and apparatus, and terminal device WO2022140947A1 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
PCT/CN2020/140281 WO2022140947A1 (en) 2020-12-28 2020-12-28 Smart contract deployment method and apparatus, smart contract execution method and apparatus, and terminal device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2020/140281 WO2022140947A1 (en) 2020-12-28 2020-12-28 Smart contract deployment method and apparatus, smart contract execution method and apparatus, and terminal device

Publications (1)

Publication Number Publication Date
WO2022140947A1 true WO2022140947A1 (en) 2022-07-07

Family

ID=82259004

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/140281 WO2022140947A1 (en) 2020-12-28 2020-12-28 Smart contract deployment method and apparatus, smart contract execution method and apparatus, and terminal device

Country Status (1)

Country Link
WO (1) WO2022140947A1 (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2019034959A1 (en) * 2017-08-15 2019-02-21 nChain Holdings Limited Methods and systems for blockchain-implemented script-based byte interpretation
CN109710385A (en) * 2018-12-29 2019-05-03 杭州趣链科技有限公司 A kind of intelligent contract complexity method for limiting based on Java Virtual Machine
CN110096338A (en) * 2019-05-10 2019-08-06 百度在线网络技术(北京)有限公司 Intelligent contract executes method, apparatus, equipment and medium
CN111459786A (en) * 2019-01-18 2020-07-28 南京大学 Intelligent contract security testing method based on variant fuzz
CN111523784A (en) * 2020-04-16 2020-08-11 广州拉卡拉信息技术有限公司 Monitoring method and device for automatic execution path

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2019034959A1 (en) * 2017-08-15 2019-02-21 nChain Holdings Limited Methods and systems for blockchain-implemented script-based byte interpretation
CN109710385A (en) * 2018-12-29 2019-05-03 杭州趣链科技有限公司 A kind of intelligent contract complexity method for limiting based on Java Virtual Machine
CN111459786A (en) * 2019-01-18 2020-07-28 南京大学 Intelligent contract security testing method based on variant fuzz
CN110096338A (en) * 2019-05-10 2019-08-06 百度在线网络技术(北京)有限公司 Intelligent contract executes method, apparatus, equipment and medium
CN111523784A (en) * 2020-04-16 2020-08-11 广州拉卡拉信息技术有限公司 Monitoring method and device for automatic execution path

Similar Documents

Publication Publication Date Title
US8196110B2 (en) Method and apparatus for verifying a suspect return pointer in a stack
US8572614B2 (en) Processing workloads using a processor hierarchy system
US10459727B2 (en) Loop code processor optimizations
KR101615907B1 (en) Method and system using exceptions for code specialization in a computer architecture that supports transactions
US9256520B2 (en) Using linked data to determine package quality
US11138055B1 (en) System and method for tracking memory corrected errors by frequency of occurrence while reducing dynamic memory allocation
US20210166156A1 (en) Data processing system and data processing method
US10592252B2 (en) Efficient instruction processing for sparse data
CN102364442A (en) Method for transplanting Wine from x86 to advanced risc machine (ARM) platform
US8296402B2 (en) Determining and downloading portions of a software application in a computer system
CN109947500A (en) A kind of program loading method, device, system, chip and storage medium
CN112612489B (en) Method and device for constructing upgrade package of software and electronic equipment
WO2022140947A1 (en) Smart contract deployment method and apparatus, smart contract execution method and apparatus, and terminal device
CN111506904B (en) Method and device for online bug repair
US8555030B2 (en) Creating multiple versions for interior pointers and alignment of an array
US20170192896A1 (en) Zero cache memory system extension
CN116382782A (en) Vector operation method, vector operator, electronic device, and storage medium
CN103235745B (en) A kind of address conflict detecting method and device
US20210318879A1 (en) Instruction execution method, device, and electronic equipment
US11023238B1 (en) Optimized branching using safe static keys
CN112631729A (en) Deployment method, execution method and device of intelligent contract and terminal equipment
US20130262910A1 (en) Time keeping in unknown and unstable clock architecture
CN106020996A (en) Data updating method and data updating apparatus
CN113220334B (en) Program fault positioning method, terminal equipment and computer readable storage medium
CN112069065B (en) Algorithm debugging method, electronic equipment and computer readable storage medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20967299

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20967299

Country of ref document: EP

Kind code of ref document: A1