CN110544113A - Method and device for determining input of fuel charge in transaction based on intelligent contract - Google Patents

Method and device for determining input of fuel charge in transaction based on intelligent contract Download PDF

Info

Publication number
CN110544113A
CN110544113A CN201910749662.1A CN201910749662A CN110544113A CN 110544113 A CN110544113 A CN 110544113A CN 201910749662 A CN201910749662 A CN 201910749662A CN 110544113 A CN110544113 A CN 110544113A
Authority
CN
China
Prior art keywords
node
function
input
operator
fuel
Prior art date
Legal status (The legal status 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 status listed.)
Granted
Application number
CN201910749662.1A
Other languages
Chinese (zh)
Other versions
CN110544113B (en
Inventor
马福辰
姜宇
傅滢
任萌
杨鑫
顾明
孙家广
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tsinghua University
Original Assignee
Tsinghua University
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 Tsinghua University filed Critical Tsinghua University
Priority to CN201910749662.1A priority Critical patent/CN110544113B/en
Publication of CN110544113A publication Critical patent/CN110544113A/en
Application granted granted Critical
Publication of CN110544113B publication Critical patent/CN110544113B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/40Authorisation, e.g. identification of payer or payee, verification of customer or shop credentials; Review and approval of payers, e.g. check credit lines or negative lists
    • G06Q20/405Establishing or using transaction specific rules
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q30/00Commerce
    • G06Q30/02Marketing; Price estimation or determination; Fundraising
    • G06Q30/0283Price estimation or determination

Landscapes

  • Business, Economics & Management (AREA)
  • Accounting & Taxation (AREA)
  • Development Economics (AREA)
  • Engineering & Computer Science (AREA)
  • Finance (AREA)
  • Strategic Management (AREA)
  • Physics & Mathematics (AREA)
  • Economics (AREA)
  • General Business, Economics & Management (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Entrepreneurship & Innovation (AREA)
  • Game Theory and Decision Science (AREA)
  • Marketing (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The invention provides an input determination method and device of fuel charge in transaction based on an intelligent contract, wherein the method comprises the following steps: generating a control flow graph according to the execution process of a function in the intelligent contract; taking each predetermined parameter value of the function as a seed input function for determining fuel charge input, selecting a target seed from the seeds according to the actual fuel charge consumed by each node in the execution process of the function, and updating the weight of each node according to the actual fuel charge consumed by each node; performing variation on the target seeds, and taking the varied target seeds as seeds for determining the next fuel charge input until a preset termination condition is reached; and taking the sum of the weights of all the nodes updated at the last time as the input of the fuel charge in the transaction based on the intelligent contract. The invention can quickly find the input which generates higher fuel charge, and prompts the function of the intelligent contract to consume higher fuel charge.

Description

Method and device for determining input of fuel charge in transaction based on intelligent contract
Technical Field
the invention belongs to the technical field of block chains, and particularly relates to a method and a device for determining input of fuel charge in transaction based on an intelligent contract.
background
Etherhouses are a platform based on blockchain technology. In the Etherns, developers can develop decentralized applications according to their needs. To prevent resource waste and malicious attacks, the ether house officially stipulates that each transaction based on an intelligent contract requires a fuel fee for consumed computing resources and storage resources.
to save on the propagation and data exchange time, each block is set to a maximum fuel cost. Meanwhile, each user also sets a maximum fuel charge willing to be paid for the transaction before the transaction is completed. If the actual fuel charge is greater than the set maximum value during the transaction, a problem of insufficient fuel charge occurs, resulting in a failure of the transaction. In some cases, the consumption of fuel costs may be affected by both the input of a transaction and the current environmental state of the blockchain system. Some malicious attackers may design special inputs resulting in very high fuel costs to implement an attack that will deny service to the blockchain system.
in practice, it is difficult to predict how much fuel charge it will consume before a transaction is actually executed. Because the consumption of the fuel fee is not only from operators specifically executed in the transaction process, but also from the storage process of the data. In addition, some complex functions including many branches also introduce uncertainty in the estimation of fuel cost.
There are currently some means of estimating fuel consumption, which use static methods. A compilation tool solc, for example for compiling smart contracts written in the Solidity language, provides a tool by which the consumption of fuel can be estimated. However, these tools often have problems, such as the tool provided by solc always presents an infinite estimated fuel cost. There are also tools that use symbolic execution techniques to estimate fuel cost consumption, but sometimes the path given by a symbolic execution tool is complex and a specific solution cannot be found.
Disclosure of Invention
In order to overcome the problem that the existing fuel fee estimation method has an erroneous estimation result or cannot estimate the result, or at least partially solve the problem, the embodiment of the invention provides a method and a device for determining the input of the fuel fee in the transaction based on the intelligent contract.
According to a first aspect of the embodiments of the present invention, there is provided a method for determining input of a fuel fee in a transaction based on a smart contract, including:
Generating a control flow graph according to the execution process of a function in the intelligent contract; the nodes in the control flow graph are operator sequences formed by partial operators of the execution process, and the weight of each node is the maximum fuel cost consumed by each node;
Inputting each predetermined parameter value of the function into the function as a seed for determining fuel charge input, selecting a target seed from the seeds according to the actual fuel charge consumed by each node in the execution process of the function, and updating the weight of each node according to the actual fuel charge consumed by each node;
performing variation on the target seeds, and taking the varied target seeds as seeds for determining the next fuel charge input until a preset termination condition is reached;
and taking the sum of the weights of all the nodes updated at the last time as the input of the fuel charge in the transaction based on the intelligent contract.
according to a second aspect of the embodiments of the present invention, there is provided an input determination device for a fuel fee in a transaction based on a smart contract, including:
The generating module is used for generating a control flow graph according to the execution process of the function in the intelligent contract; the nodes in the control flow graph are operator sequences formed by partial operators of the execution process, and the weight of each node is the maximum fuel cost consumed by each node;
The selection module is used for inputting each predetermined parameter value of the function into the function as a seed for determining fuel charge input, selecting a target seed from the seeds according to the actual fuel charge consumed by each node in the execution process of the function, and updating the weight of each node according to the actual fuel charge consumed by each node;
The variation module is used for performing variation on the target seeds, and taking the varied target seeds as seeds for determining the next fuel charge input until a preset termination condition is reached;
and the determining module is used for taking the sum of the weights of all the nodes updated at the last time as the input of the fuel charge in the transaction based on the intelligent contract.
According to a third aspect of the embodiments of the present invention, there is also provided an electronic device, including a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor calls the program instructions to execute the method for determining the input of the fuel charge in the smart contract-based transaction provided in any one of the various possible implementations of the first aspect.
According to a fourth aspect of the embodiments of the present invention, there is also provided a non-transitory computer-readable storage medium storing computer instructions for causing a computer to execute the method for determining an input of a fuel charge in a smart contract-based transaction provided in any one of the various possible implementations of the first aspect.
The embodiment of the invention provides a method and a device for determining the input of fuel charge in transaction based on an intelligent contract, the method generates a control flow graph according to the execution process of an intelligent contract function, estimates the fuel charge consumed by the execution of the intelligent contract function according to the feedback information of the execution result of the intelligent contract function, guides the selection and variation of seeds, thereby quickly finding the input generating higher fuel charge, promoting the function of the intelligent contract to consume higher fuel charge, effectively estimating the upper limit of the fuel charge consumed by the transaction of the current intelligent contract for a user, and facilitating the setting of the maximum value of the fuel charge by the user; for openers of intelligent contracts, the problem of insufficient fuel cost still occurs through determined fuel cost input, which indicates that a malicious attacker exists, and developers are required to check whether unreasonable codes exist in the contracts or not.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and those skilled in the art can also obtain other drawings according to the drawings without creative efforts.
FIG. 1 is a schematic overall flow chart of a method for determining the input of a fuel charge in a transaction based on an intelligent contract according to an embodiment of the present invention;
fig. 2 is a schematic diagram of a control flow diagram in a method for determining input of a fuel fee in a transaction based on an intelligent contract according to an embodiment of the present invention;
fig. 3 is a schematic diagram illustrating an overall structure of a fuel fee input determination device in a transaction based on a smart contract according to an embodiment of the present invention;
fig. 4 is a schematic view of an overall structure of an electronic device according to an embodiment of the present invention.
Detailed Description
in order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and those skilled in the art can also obtain other drawings according to the drawings without creative efforts.
in an embodiment of the present invention, a method for determining input of a fuel fee in a transaction based on a smart contract is provided, and fig. 1 is a schematic overall flow chart of the method for determining input of a fuel fee in a transaction based on a smart contract provided in the embodiment of the present invention, where the method includes: s101, generating a control flow graph according to the execution process of a function in an intelligent contract; the nodes in the control flow graph are operator sequences formed by operators in the execution process, and the weight of each node is the maximum fuel cost consumed by each node;
The Control Flow Graph (CFG) is an abstract data structure of a program, represents all paths traversed during program execution, and represents Flow directions of all basic block executions during program execution in a Graph form. And compiling the functions in the intelligent contract to generate a binary file, and generating a control flow graph according to the operational characters in the binary file. Wherein, the nodes in the control chart are operator sequences formed by operators in the process of executing the function. Each node includes one or more operators, where a node refers to a continuous string of blocks of operators without branches. The generated control flow graph is an authorized control flow graph, and the weight of each node of the control flow graph is the maximum fuel cost consumed by the node. The fuel fee is the fee paid for the consumed computing and storage resources in the smart contract-based transaction.
S102, inputting each predetermined parameter value of the function into the function as a seed for determining fuel charge input, selecting a target seed from the seeds according to the actual fuel charge consumed by each node in the execution process of the function, and updating the weight of each node according to the actual fuel charge consumed by each node;
in this embodiment, the seeds input in each round are selected and varied by using a feedback-oriented seed selection and variation method. Feedback-directed seed selection and variation is for the seed of each input function. And determining whether the current seed should be reserved or not according to the feedback information of the function execution result of each intelligent contract, and if so, performing mutation on the seed. The feedback information of the function execution result is related to the actual fuel cost consumed by the function in the execution process. If the actual fuel cost consumed is increased, reserving the seeds of the input function, and taking the reserved seeds as target seeds.
Before seed selection, some initial seeds are generated, and the type definition of parameters required by each function is randomly determined according to the abstract binary interface file of the intelligent contract. The first input of the function is the initial seed, and the inputs after the first time are the mutated seed nodes.
This embodiment uses the gene chain structure to store the information of the seed, and also defines the gene matching map to correspond each part of the gene chain to the function input represented by it. The gene chain is a chain consisting of a plurality of bytes, and the mutation strategy of the seeds is carried out aiming at the gene chain.
this embodiment maintains the weight of each node. Before the function is executed, the maximum fuel charge of each node is used as the weight of each node. When a seed is input into the function to execute the function each time, comparing the actual fuel charge of each node with the weight in the executing process, and if the actual fuel charge consumed by any node is greater than the weight of the node, taking the actual fuel charge consumed by the node as the weight of the node; otherwise, the weight of the node is unchanged, so that the update of the weight of the node is realized.
in order to better execute the intelligent contract function, some environment variables are prepared for the execution process of the intelligent contract function, and some drivers are set. In order to simulate the execution environment of the Ethernet, firstly some simulated environment variables are initialized, and simultaneously the current intelligent contract is deployed, and the process is completed by executing the constructor of the current intelligent contract.
s103, performing variation on the target seeds, and taking the varied target seeds as seeds for determining the next fuel charge input until a preset termination condition is reached;
and (5) carrying out mutation on the selected target seeds. The present embodiment is not limited to the variant method. And inputting the varied target seeds into a function in the intelligent contract, and selecting and varying the varied seeds according to feedback information of an execution result of the function. Steps S102 and S103 are iteratively executed until a preset termination condition is reached. The preset termination condition may be that the determined fuel cost input determined in the current iteration is greater than a preset threshold value, which indicates that there may be hacking. Termination may also occur when a user-specified number of iterations or computation time is reached.
and S104, taking the sum of the weights of all the nodes updated for the last time as the input of the fuel charge in the transaction based on the intelligent contract.
In summary, the embodiment receives the binary file and the abstract binary interface file compiled by the intelligent contract function, and outputs the input of each function and the consumption of the fuel cost caused by the input. Thus, a large number of inputs are quickly found so that the fuel charge of each function in the intelligent contract reaches a higher value. And finally, the input of the fuel fee in the transaction based on the intelligent contract is automatically determined, the user is guided to set the maximum value of the fuel fee in the transaction, and the problem of insufficient fuel fee caused by the maximum value of the fuel fee set by the user is avoided.
The test results on the intelligent contracts show that on many intelligent contracts, the embodiment can generate the fuel charge input exceeding the maximum value of the fuel charge set by the user, which indicates that the problem of insufficient fuel charge can occur according to the maximum value of the fuel charge set by the current user.
According to the method, the control flow graph is generated according to the execution process of the intelligent contract function, the fuel charge consumed by the execution of the intelligent contract function is estimated according to the feedback information of the execution result of the intelligent contract function, and the selection and variation of the seeds are guided, so that the input generating higher fuel charge is quickly found, the function of the intelligent contract is prompted to consume higher fuel charge, for a user, the upper limit of the fuel charge consumed in the transaction of the current intelligent contract can be effectively estimated, and the maximum value of the fuel charge is convenient to set by the user; for openers of intelligent contracts, the problem of insufficient fuel cost still occurs through determined fuel cost input, which indicates that a malicious attacker exists, and developers are required to check whether unreasonable codes exist in the contracts or not.
On the basis of the foregoing embodiment, in this embodiment, the step of generating the control flow graph according to the execution process of the function in the intelligent contract specifically includes: compiling an execution process of a function in an intelligent contract to obtain all operational characters in the execution process; for any one of the operators generating the control flow graph, if the operator is not a JUMP operator or a JUMPI operator, adding the operator to a current node of the control flow graph; if the operator is a JUMP operator or a JUMPI operator, adding the operator to a current node of the control flow graph, and adding the operator pointed by the operator to a node next to the current node; and taking the operator pointed by the operator as the operator of the next generated control flow graph, and taking the next node as the next current node until the operator is a STOP operator.
specifically, the execution process of the function in the intelligent contract is mutated, and all the operators in the execution process are obtained. Each node of the control flow graph is a series of contiguous, unbranched operator sequences. When a control flow graph is generated, if a current operator is a JUMP operator or a JUMPI operator, a new branch of the control flow graph appears, namely the next node pointed to by the current node is pointed to, and an operator behind the current operator is stored in the node pointed to by the current node. Otherwise, an operator subsequent to the current operator is stored in the current node.
As shown in fig. 2, there are 6 nodes in fig. 2, and operators numbered 0 and 1 are first placed in the first node according to the sequence of appearance of the operators. When the jump pi operator of number 3 appears, the operator is put in the first node, then the operator of number 4 pointed to by the operator is put in the second node, and the operator of number d pointed to by the operator is put in the third node. The operator order after the operator with number 4 is put in the second node until the JUMP operator with number a appears. The operator order after the operator with number d is put in the third node until the JUMP operator with number 14 appears. The JUMP operators of numbers a and 14 refer to operators both pointing to number 17. The operator order after the operator number 17 is put in the fourth node until the JUMP operator number 19 appears. The number b operator pointed to by the number 19 JUMP operator is placed in the fifth node and the number 15 operator pointed to is placed in the sixth node. And terminates until STOP nodes are placed in the fifth node and the sixth node.
On the basis of the foregoing embodiment, in this embodiment, according to the execution process of the function in the intelligent contract, the step of generating the control flow graph further includes: regarding any node in the control flow graph, taking an operator with preset fuel charge in the node as a target operator, taking the sum of the preset fuel charges of all the target operators in the node as the initial fuel charge of the node, and taking the initial fuel charge of the node as the initial weight of the node.
as shown in fig. 2, the dotted box in each node is a preset fuel charge of the corresponding operator, such as 3units, i.e. 3 units. The preset fuel charge is preset by the Ether house platform. The preset fuel charge of some operators is also related to the operand of the operator, such as the STORE operator, and the fuel charge consumed by the operators is uncertain and does not exist in the preset fuel charge. And taking the operator of the determined fuel charge in each node as a target operator, and taking the sum of the preset fuel charges of the operators as the initial fuel charge of the corresponding node. The weight of the node is defined as the initial fuel charge, and the weight is updated along with the execution of the function of the intelligent contract. And if the actual fuel cost consumed by a certain node is higher than the current weight of the node after the certain execution, updating the weight of the node into the actual fuel cost of the node.
on the basis of the above embodiment, in this embodiment, the step of selecting the target seed from the seeds according to the actual fuel cost consumed by each node in the execution process of the function specifically includes: adding the actual fuel cost consumed by each node to obtain the actual total fuel cost consumed by executing the function, and obtaining the execution times of the nodes on each edge in the control flow graph; if the actual fuel cost consumed by any node is larger than the weight of any node, taking the seed currently input into the function as a target seed; if the actual total fuel cost consumed by the function is larger than the maximum fuel cost consumed by the function, taking the seeds currently input into the function as target seeds; wherein the maximum fuel cost consumed by the function is the sum of the weights of all the nodes; and if the execution times of the nodes on any edge are greater than the maximum execution times of the nodes on any edge, taking the seeds currently input into the function as target seeds.
Specifically, after the function of the intelligent contract is executed according to the seeds input in each round, feedback information of the execution result is collected, and the seeds are screened and mutated again according to the feedback information. The feedback information comprises the actual fuel charge consumed by the whole function in the process of executing the intelligent contract function at this time, the actual fuel charge consumed by each node in the authorized control flow diagram and the execution times of each edge. The number of executions of each edge refers to the total number of executions of all operators in the two nodes on each edge.
According to the feedback information, if the fact that the fuel charge of a certain node is increased, or the number of times of executing a certain edge is increased, or the fuel charge consumption value of the whole function is increased is known, the currently input seeds are reserved. The number of execution times on a certain edge becomes large, for example, the number of execution times of the whole of two nodes on a certain edge becomes large due to circulation, which may increase the fuel cost consumed by the whole function.
On the basis of the foregoing embodiment, the step of mutating the target seed in this embodiment specifically includes: if the variable type of the target seed is not the array type, performing mutation on the target seed based on a traditional mutation method; if the variable type of the target seed is an array, randomly selecting a numerical value in a preset range as the length of the array; and randomly filling the array according to the types of the elements in the array.
Specifically, the mutation process of the target seed is divided into two parts, namely the traditional mutation process and the fuel consumption related mutation. For some common inputs of the function, the function is mutated by using a traditional mutation method. Common inputs refer to other types of variables besides array variables. The conventional mutation method refers to a mutation method used in a fuzz testing tool for conventional software, and includes bit flipping, byte flipping, increment and decrement of an arithmetic value, and the like. The fuel consumption related variation process is a variation strategy for increasing the fuel consumption. For the input of the array type, a number within a preset range, such as 1000, is randomly selected as the length of the array during variation, and then random filling is performed according to the type of the elements in the array.
in another embodiment of the invention, an input determination device for fuel charge in intelligent contract-based transaction is provided, which is used for realizing the method in each embodiment. Therefore, the description and definition in each embodiment of the method for determining the input of the fuel fee in the intelligent contract-based transaction may be used for understanding each execution module in the embodiment of the present invention. Fig. 3 is a schematic diagram of an overall structure of an apparatus for determining an input of a fuel fee in a transaction based on an intelligent contract according to an embodiment of the present invention, where the apparatus includes a generating module 301, a selecting module 302, a mutation module 303, and a determining module 304, where:
The generating module 301 is configured to generate a control flow graph according to an execution process of a function in an intelligent contract; the nodes in the control flow graph are operator sequences formed by partial operators of the execution process, and the weight of each node is the maximum fuel cost consumed by each node;
The control flow graph is an abstract data structure of the program, represents all paths traversed in the program execution process, and represents the flow direction of all basic block execution in the program execution process in a graph form. The generating module 301 compiles a function in the intelligent contract to generate a binary file, and generates a control flow graph according to an operator in the binary file. Wherein, the nodes in the control chart are operator sequences formed by operators in the process of executing the function. Each node includes one or more operators, where a node refers to a continuous string of blocks of operators without branches. The generated control flow graph is an authorized control flow graph, and the weight of each node of the control flow graph is the maximum fuel cost consumed by the node. The fuel fee is the fee paid for the consumed computing and storage resources in the smart contract-based transaction.
The selection module 302 is configured to input each predetermined parameter value of the function into the function as a seed for determining fuel charge input, select a target seed from the seeds according to an actual fuel charge consumed by each node in an execution process of the function, and update the weight of each node according to the actual fuel charge consumed by each node;
In this embodiment, the seeds input in each round are selected and varied by using a feedback-oriented seed selection and variation method. Feedback-directed seed selection and variation is for the seed of each input function. The selection module 302 determines whether the current seed should be preserved or not according to the feedback information of the function execution result of each intelligent contract, and if so, how to perform mutation on the seed. The feedback information of the function execution result is related to the actual fuel cost consumed by the function in the execution process. If the actual fuel cost consumed is increased, reserving the seeds of the input function, and taking the reserved seeds as target seeds. This embodiment maintains the weight of each node. Before the function is executed, the maximum fuel charge of each node is used as the weight of each node.
The variation module 303 is configured to perform variation on the target seed, and use the varied target seed as a seed for determining the next fuel cost input until a preset termination condition is reached;
the mutation module 303 performs mutation on the selected target seed. The present embodiment is not limited to the variant method. And inputting the varied target seeds into a function in the intelligent contract, and selecting and varying the varied seeds according to feedback information of an execution result of the function. And iteratively executing the selection and variation steps until a preset termination condition is reached. The preset termination condition may be that the determined fuel cost input determined in the current iteration is greater than a preset threshold value, which indicates that there may be hacking. Termination may also occur when a user-specified number of iterations or computation time is reached.
The determination module 304 is used for taking the sum of the weights of all nodes updated last time as the input of the fuel charge in the transaction based on the intelligent contract.
In the embodiment, the control flow graph is generated according to the execution process of the intelligent contract function, the fuel charge consumed by the execution of the intelligent contract function is estimated according to the feedback information of the execution result of the intelligent contract function, and the selection and variation of the seeds are guided, so that the input generating higher fuel charge is quickly found, and the function of the intelligent contract is promoted to consume higher fuel charge
On the basis of the foregoing embodiment, the generating module in this embodiment is specifically configured to: compiling an execution process of a function in an intelligent contract to obtain all operational characters in the execution process; for any one of the operators generating the control flow graph, if the operator is not a JUMP operator or a JUMPI operator, adding the operator to a current node of the control flow graph; if the operator is a JUMP operator or a JUMPI operator, adding the operator to a current node of the control flow graph, and adding the operator pointed by the operator to a node next to the current node; and taking the operator pointed by the operator as the operator of the next generated control flow graph, and taking the next node as the next current node until the operator is a STOP operator.
On the basis of the foregoing embodiment, the generating module in this embodiment is further configured to: regarding any node in the control flow graph, taking an operator with preset fuel charge in the node as a target operator, taking the sum of the preset fuel charges of all the target operators in the node as the initial fuel charge of the node, and taking the initial fuel charge of the node as the initial weight of the node.
On the basis of the above embodiment, the module is specifically selected in this embodiment to: adding the actual fuel cost consumed by each node to obtain the actual total fuel cost consumed by executing the function, and obtaining the execution times of the nodes on each edge in the control flow graph; if the actual fuel cost consumed by any node is larger than the weight of any node, taking the seed currently input into the function as a target seed; if the actual total fuel cost consumed by the function is larger than the maximum fuel cost consumed by the function, taking the seeds currently input into the function as target seeds; wherein the maximum fuel cost consumed by the function is the sum of the weights of all the nodes; and if the execution times of the nodes on any edge are greater than the maximum execution times of the nodes on any edge, taking the seeds currently input into the function as target seeds.
on the basis of the above embodiment, the module is specifically selected in this embodiment to: and if the actual fuel cost consumed by any node is greater than the weight of any node, taking the actual fuel cost consumed by any node as the weight of any node.
on the basis of the foregoing embodiment, the variation module in this embodiment is specifically configured to: if the variable type of the target seed is not the array type, performing mutation on the target seed based on a traditional mutation method; if the variable type of the target seed is an array, randomly selecting a numerical value in a preset range as the length of the array; and randomly filling the array according to the types of the elements in the array.
On the basis of the above embodiment, the module is specifically selected in this embodiment to: and determining an initial seed of the function according to the definition of the parameter type of the function input in the abstract binary interface file of the intelligent contract.
the embodiment provides an electronic device, and fig. 4 is a schematic view of an overall structure of the electronic device according to the embodiment of the present invention, where the electronic device includes: at least one processor 401, at least one memory 402, and a bus 403; wherein the content of the first and second substances,
the processor 401 and the memory 402 communicate with each other via a bus 403;
The memory 402 stores program instructions executable by the processor 401, and the processor calls the program instructions to perform the methods provided by the above method embodiments, for example, the methods include: generating a control flow graph according to the execution process of a function in the intelligent contract; taking each predetermined parameter value of the function as a seed input function for determining fuel charge input, selecting a target seed from the seeds according to the actual fuel charge consumed by each node in the execution process of the function, and updating the weight of each node according to the actual fuel charge consumed by each node; performing variation on the target seeds, and taking the varied target seeds as seeds for determining the next fuel charge input until a preset termination condition is reached; and taking the sum of the weights of all the nodes updated at the last time as the input of the fuel charge in the transaction based on the intelligent contract.
The present embodiments provide a non-transitory computer-readable storage medium storing computer instructions that cause a computer to perform the methods provided by the above method embodiments, for example, including: generating a control flow graph according to the execution process of a function in the intelligent contract; taking each predetermined parameter value of the function as a seed input function for determining fuel charge input, selecting a target seed from the seeds according to the actual fuel charge consumed by each node in the execution process of the function, and updating the weight of each node according to the actual fuel charge consumed by each node; performing variation on the target seeds, and taking the varied target seeds as seeds for determining the next fuel charge input until a preset termination condition is reached; and taking the sum of the weights of all the nodes updated at the last time as the input of the fuel charge in the transaction based on the intelligent contract.
those of ordinary skill in the art will understand that: all or part of the steps for implementing the method embodiments may be implemented by hardware related to program instructions, and the program may be stored in a computer readable storage medium, and when executed, the program performs the steps including the method embodiments; and the aforementioned storage medium includes: various media that can store program codes, such as ROM, RAM, magnetic or optical disks.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above-described technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable storage medium such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (10)

1. a method for determining input of fuel charge in transaction based on intelligent contracts is characterized by comprising the following steps:
Generating a control flow graph according to the execution process of a function in the intelligent contract; the nodes in the control flow graph are operator sequences formed by partial operators of the execution process, and the weight of each node is the maximum fuel cost consumed by each node;
inputting each predetermined parameter value of the function into the function as a seed for determining fuel charge input, selecting a target seed from the seeds according to the actual fuel charge consumed by each node in the execution process of the function, and updating the weight of each node according to the actual fuel charge consumed by each node;
Performing variation on the target seeds, and taking the varied target seeds as seeds for determining the next fuel charge input until a preset termination condition is reached;
And taking the sum of the weights of all the nodes updated at the last time as the input of the fuel charge in the transaction based on the intelligent contract.
2. The method for determining the input of the fuel fee in the transaction based on the intelligent contract as claimed in claim 1, wherein the step of generating the control flow graph according to the execution process of the function in the intelligent contract specifically comprises the following steps:
Compiling an execution process of a function in an intelligent contract to obtain all operational characters in the execution process;
For any one of the operators generating the control flow graph, if the operator is not a JUMP operator or a JUMPI operator, adding the operator to a current node of the control flow graph;
If the operator is a JUMP operator or a JUMPI operator, adding the operator to a current node of the control flow graph, and adding the operator pointed by the operator to a node next to the current node;
And taking the operator pointed by the operator as the operator of the next generated control flow graph, and taking the next node as the next current node until the operator is a STOP operator.
3. The method for determining the input of the fuel fee in the transaction based on the intelligent contract as claimed in claim 2, wherein the step of generating the control flow graph according to the execution process of the function in the intelligent contract further comprises the steps of:
regarding any node in the control flow graph, taking an operator with preset fuel charge in the node as a target operator, taking the sum of the preset fuel charges of all the target operators in the node as the initial fuel charge of the node, and taking the initial fuel charge of the node as the initial weight of the node.
4. The method for determining the input of the fuel fee in the transaction based on the intelligent contract as claimed in claim 1, wherein the step of selecting the target seed from the seeds according to the actual fuel fee consumed by each node in the execution process of the function specifically comprises the following steps:
adding the actual fuel cost consumed by each node to obtain the actual total fuel cost consumed by executing the function, and obtaining the execution times of the nodes on each edge in the control flow graph;
If the actual fuel cost consumed by any node is larger than the weight of any node, taking the seed currently input into the function as a target seed;
if the actual total fuel cost consumed by the function is larger than the maximum fuel cost consumed by the function, taking the seeds currently input into the function as target seeds; wherein the maximum fuel cost consumed by the function is the sum of the weights of all the nodes;
And if the execution times of the nodes on any edge are greater than the maximum execution times of the nodes on any edge, taking the seeds currently input into the function as target seeds.
5. The method for determining the input of the fuel fee in the transaction based on the intelligent contract as claimed in claim 1, wherein the step of updating the weight of each node according to the actual fuel fee consumed by each node specifically comprises the steps of:
And if the actual fuel cost consumed by any node is greater than the weight of any node, taking the actual fuel cost consumed by any node as the weight of any node.
6. the method for determining the input of the fuel fee in the transaction based on the intelligent contract as claimed in claim 1, wherein the step of mutating the target seed specifically comprises the steps of:
If the variable type of the target seed is not the array type, performing mutation on the target seed based on a traditional mutation method;
if the variable type of the target seed is an array, randomly selecting a numerical value in a preset range as the length of the array;
And randomly filling the array according to the types of the elements in the array.
7. The method for determining the input of the fuel fee in the transaction based on the intelligent contract as claimed in claim 1, wherein the step of inputting each predetermined parameter value of the function into the function as a seed for determining the input of the fuel fee specifically comprises:
and determining an initial seed of the function according to the definition of the parameter type of the function input in the abstract binary interface file of the intelligent contract.
8. An input determination device for fuel charge in a transaction based on a smart contract, comprising:
The generating module is used for generating a control flow graph according to the execution process of the function in the intelligent contract; the nodes in the control flow graph are operator sequences formed by partial operators of the execution process, and the weight of each node is the maximum fuel cost consumed by each node;
The selection module is used for inputting each predetermined parameter value of the function into the function as a seed for determining fuel charge input, selecting a target seed from the seeds according to the actual fuel charge consumed by each node in the execution process of the function, and updating the weight of each node according to the actual fuel charge consumed by each node;
The variation module is used for performing variation on the target seeds, and taking the varied target seeds as seeds for determining the next fuel charge input until a preset termination condition is reached;
and the determining module is used for taking the sum of the weights of all the nodes updated at the last time as the input of the fuel charge in the transaction based on the intelligent contract.
9. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor when executing the program performs the steps of the method for determining an input of a fuel charge in a smart contract-based transaction according to any one of claims 1 to 7.
10. a non-transitory computer readable storage medium having stored thereon a computer program, wherein the computer program when executed by a processor implements the steps of the method for determining an input of a fuel charge in a smart contract-based transaction according to any one of claims 1 to 7.
CN201910749662.1A 2019-08-14 2019-08-14 Method and device for determining input of fuel charge in transaction based on intelligent contract Active CN110544113B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910749662.1A CN110544113B (en) 2019-08-14 2019-08-14 Method and device for determining input of fuel charge in transaction based on intelligent contract

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910749662.1A CN110544113B (en) 2019-08-14 2019-08-14 Method and device for determining input of fuel charge in transaction based on intelligent contract

Publications (2)

Publication Number Publication Date
CN110544113A true CN110544113A (en) 2019-12-06
CN110544113B CN110544113B (en) 2022-04-12

Family

ID=68710815

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910749662.1A Active CN110544113B (en) 2019-08-14 2019-08-14 Method and device for determining input of fuel charge in transaction based on intelligent contract

Country Status (1)

Country Link
CN (1) CN110544113B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112035350A (en) * 2020-08-27 2020-12-04 腾讯科技(深圳)有限公司 Test method and device for block chain system and computer equipment

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140279065A1 (en) * 2013-03-15 2014-09-18 Adchemy, Inc. Generating Ad Copy
CN107967539A (en) * 2017-11-29 2018-04-27 暨南大学 The method for the fuel limitation merchandised on prediction ether mill based on machine learning and block chain technology
US20180300694A1 (en) * 2018-05-14 2018-10-18 Beijing Good Fortune Innovative Intelligence Technology Co.Ltd Method for intelligently selecting accounting node of blockchain
CN108876620A (en) * 2018-06-28 2018-11-23 北京金山安全软件有限公司 Transaction fee estimation method and device
CN109493042A (en) * 2018-10-24 2019-03-19 南京邮电大学 A kind of intelligent contract possessing access control function is credible to deposit card method and system

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140279065A1 (en) * 2013-03-15 2014-09-18 Adchemy, Inc. Generating Ad Copy
CN107967539A (en) * 2017-11-29 2018-04-27 暨南大学 The method for the fuel limitation merchandised on prediction ether mill based on machine learning and block chain technology
US20180300694A1 (en) * 2018-05-14 2018-10-18 Beijing Good Fortune Innovative Intelligence Technology Co.Ltd Method for intelligently selecting accounting node of blockchain
CN108876620A (en) * 2018-06-28 2018-11-23 北京金山安全软件有限公司 Transaction fee estimation method and device
CN109493042A (en) * 2018-10-24 2019-03-19 南京邮电大学 A kind of intelligent contract possessing access control function is credible to deposit card method and system

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112035350A (en) * 2020-08-27 2020-12-04 腾讯科技(深圳)有限公司 Test method and device for block chain system and computer equipment
CN112035350B (en) * 2020-08-27 2021-09-28 腾讯科技(深圳)有限公司 Test method and device for block chain system and computer equipment

Also Published As

Publication number Publication date
CN110544113B (en) 2022-04-12

Similar Documents

Publication Publication Date Title
Gribaudo et al. Hybrid Petri nets with general one-shot transitions
EP3490223A1 (en) System and method for simulating and foiling attacks on a vehicle on-board network
Cavalcante et al. Statistical model checking of dynamic software architectures
CN102110013B (en) For the method and apparatus of effective generating process device architectural model
GB2530516A (en) Intelligent Software Test Augmenting
Horváth et al. Dynamic constraint satisfaction problems over models
Ni et al. A formal model and risk assessment method for security-critical real-time embedded systems
Simaitis Automatic verification of competitive stochastic systems
CN110544113B (en) Method and device for determining input of fuel charge in transaction based on intelligent contract
CN110321458B (en) Data flow analysis method and device based on control flow graph
Smetanin et al. Modeling of distributed ledgers: Challenges and future perspectives
CN113468044B (en) Test case generation method based on improved grey predictive evolution algorithm
US9678853B2 (en) Lifting of bounded liveness counterexamples to concrete liveness counterexamples
US10819752B2 (en) Systems and methods for quantitative assessment of a computer defense technique
Zhou et al. A study on optimizing execution time and code size in iterative compilation
CN102567169B (en) Test method and device of microprocessor
Ummer et al. Factors influencing design iteration with a focus on project duration
CN111930476A (en) Task scheduling method and device and electronic equipment
Makkar et al. Optimization of software quality attributes using evolutionary algorithm
CN107135221B (en) Method for progressively solving K maximum probability attack path
Marques-Silva Computing with SAT oracles: past, present and future
CN111882416A (en) Training method and related device of risk prediction model
CN110796234B (en) Method and device for predicting computer state
CN117273115B (en) Static generation method, device, equipment and medium of reverse calculation graph
Nabli Finding minimal siphons and traps as a Constraint satisfaction Problem

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant