Smart contract execution method, device, terminal equipment and computer medium

By encrypting the input parameters of participating nodes on the blockchain, making public calculations of smart contracts, offline calculations of management nodes and verification of verification nodes, the problem of privacy information leakage during the execution of smart contracts is solved and the accuracy of calculation results is achieved. and privacy protection.

CN115567214BActive Publication Date: 2024-08-30SHENZHEN WOXIANG TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211023784.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-24
Publication Date
2024-08-30
Estimated Expiration
2042-08-24

AI Technical Summary

Technical Problem

The disclosure of contract parameters and codes of smart contracts deployed on existing blockchains leads to the leakage of private information of participants, and the risk of malicious short selling of assets on the chain increases. How to protect user privacy without increasing the amount of calculation has become an urgent issue for the industry. question.

Method used

By obtaining the target input parameters of each participating node in the blockchain for encryption, calling smart contracts for public calculations, management nodes perform offline calculations and generate zero-knowledge proofs, and verification nodes verify the calculation results and deploy them to the blockchain to ensure that the calculation results are accurate. Sexuality and privacy protection.

Benefits of technology

It ensures the accuracy of smart contract calculation results without increasing the amount of additional calculations, thereby protecting the privacy information of participants and preventing leakage of private information and malicious short selling.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115567214B
    Figure CN115567214B
Patent Text Reader

Abstract

The present invention discloses a smart contract execution method, device, terminal equipment and computer medium, which relate to the field of blockchain technology, and include: obtaining target input parameters corresponding to each participating node in the blockchain, and encrypting each target input parameter to obtain each encrypted target parameter; publishing each encrypted target parameter through a target smart contract in the blockchain to obtain each public target parameter, and calling the target smart contract to calculate each public target parameter to obtain a first calculation result; calling each management node in the blockchain to perform offline calculation on each target input parameter to obtain a second calculation result, and each management node generates a zero-knowledge proof corresponding to the second calculation result; calling each verification node in the blockchain to verify the first calculation result to obtain a verification result, and each verification node deploys the verification result and the zero-knowledge proof into the blockchain.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of blockchain technology, and in particular to a method, device, terminal equipment and computer-readable storage medium for executing a smart contract. Background Art

[0002] With the development of blockchain technology, blockchain developers have gradually realized that deploying smart contracts within the blockchain is a technical means to add more variable attributes to the blockchain and enable the blockchain to complete more complex tasks.

[0003] However, the contract parameters of smart contracts deployed on various blockchains and the codes of the smart contracts themselves are currently public, so one of the participants in the smart contract can obtain the privacy information of other participants under the smart contract by viewing the contract parameters or the underlying code of the smart contract, thereby maliciously shorting the on-chain assets of other participants. Therefore, how to better protect user privacy during the execution of smart contracts has become an urgent problem that needs to be solved in the industry. Summary of the invention

[0004] The embodiments of the present invention provide a method, apparatus, terminal device and computer-readable storage medium for executing a smart contract, aiming to achieve the technical effect of not requiring the target smart contract to increase additional computing power, thereby ensuring the accuracy of the calculation results and further protecting the privacy information of each participant.

[0005] The present invention provides a method for executing a smart contract, the method comprising the following steps:

[0006] Obtaining target input parameters corresponding to each participating node in the blockchain, and encrypting each target input parameter to obtain each encrypted target parameter;

[0007] Publicizing each of the encrypted target parameters through a target smart contract in the blockchain to obtain each public target parameter, and calling the target smart contract to calculate each of the public target parameters to obtain a first calculation result;

[0008] Calling each management node in the blockchain to perform offline calculation on each of the target input parameters to obtain a second calculation result, and each of the management nodes generates a zero-knowledge proof corresponding to the second calculation result;

[0009] Each verification node in the blockchain is called to verify the first calculation result to obtain a verification result, and each verification node deploys the verification result and the zero-knowledge proof into the blockchain.

[0010] Furthermore, the method further comprises:

[0011] Determine each candidate node among each of the participating nodes in the blockchain;

[0012] A preset management quantity threshold is obtained, a target candidate node is randomly selected from each of the candidate nodes according to the management quantity threshold, and the target candidate node is determined as the management node.

[0013] Further, after the step of determining the target candidate node as the management node, the method further includes:

[0014] Get the preset contract reward parameters and contract penalty parameters;

[0015] Testing the zero-knowledge proof and determining whether the zero-knowledge proof is correct;

[0016] If yes, executing the contract reward operation corresponding to the contract reward parameter on each of the management nodes according to the contract reward parameter;

[0017] If not, a contract penalty operation corresponding to the contract penalty parameter is performed on each management node according to the contract reward parameter.

[0018] Furthermore, the method further comprises:

[0019] Obtaining a preset contract trigger threshold, determining the number of participating nodes corresponding to each participating node according to each of the encrypted target parameters, and comparing the contract trigger threshold with the number of participating nodes to obtain a comparison result;

[0020] When the comparison result is that the number of participating nodes is less than the contract triggering threshold, a refund operation is performed on each of the encrypted target parameters;

[0021] When the comparison result is that the number of participating nodes is greater than or equal to the contract trigger threshold, the step of making each of the encrypted target parameters public through the target smart contract in the blockchain to obtain each public target parameter is executed.

[0022] Furthermore, the step of calling each management node in the blockchain to perform offline calculation on each target input parameter to obtain a second calculation result includes:

[0023] Control each management node to enter offline mode;

[0024] Through the offline mode, each management node is controlled to calculate each target input parameter according to the contract rules corresponding to the target smart contract to obtain a second calculation result.

[0025] Furthermore, the verification result includes whether the first calculation result is valid and whether the first calculation result is invalid, and the step of calling each verification node in the blockchain to verify the first calculation result to obtain the verification result includes:

[0026] Calling each verification node to calculate each of the public target parameters to obtain a fourth calculation result, and comparing the fourth calculation result with the first calculation result to obtain a comparison result;

[0027] When the comparison result is that the fourth calculation result is consistent with the first calculation result, determining that the verification result is that the first calculation result is valid;

[0028] When the comparison result is that the fourth calculation result is inconsistent with the first calculation result, it is determined that the verification result is that the first calculation result is invalid.

[0029] Furthermore, before the step of deploying the verification result and the zero-knowledge proof into the blockchain by each verification node, the method further includes:

[0030] Obtaining, by each of the participating nodes, a third calculation result based on each of the target input parameters;

[0031] Compare the third calculation result with the second calculation result and determine whether the third calculation result is consistent with the second calculation result;

[0032] If it is determined that the third calculation result is consistent with the second calculation result, determining that the second calculation result is a valid calculation result;

[0033] If it is determined that the third calculation result is inconsistent with the second calculation result, the second calculation result is determined to be an invalid calculation result.

[0034] In addition, to achieve the above-mentioned purpose, the present invention also provides an execution device of a smart contract, the device comprising:

[0035] A parameter encryption module is used to obtain the target input parameters corresponding to each participating node in the blockchain, and encrypt each of the target input parameters to obtain each encrypted target parameter;

[0036] A first calculation module, used to make each of the encrypted target parameters public through the target smart contract in the blockchain to obtain each public target parameter, and call the target smart contract to calculate each of the public target parameters to obtain a first calculation result;

[0037] A second calculation module is used to call each management node in the blockchain to perform offline calculation on each of the target input parameters to obtain a second calculation result, and each of the management nodes generates a zero-knowledge proof corresponding to the second calculation result;

[0038] The result verification module is used to call each verification node in the blockchain to verify the first calculation result to obtain a verification result, and each verification node deploys the verification result and the zero-knowledge proof into the blockchain.

[0039] In addition, to achieve the above-mentioned purpose, the present invention also provides a terminal device, which includes: a memory, a processor, and an execution program of a smart contract stored in the memory and runnable on the processor, and when the execution program of the smart contract is executed by the processor, the steps of the execution method of the smart contract as described above are implemented.

[0040] In addition, to achieve the above-mentioned purpose, the present invention also provides a computer-readable storage medium, on which an execution program of a smart contract is stored. When the execution program of the smart contract is executed by a processor, the steps of the call management method of the smart contract as described above are implemented.

[0041] The smart contract execution method, apparatus, terminal device and computer-readable storage medium provided by the embodiments of the present invention obtain the target input parameters corresponding to each participating node in the blockchain, and encrypt each of the target input parameters to obtain each encrypted target parameter; each of the encrypted target parameters is made public through the target smart contract in the blockchain to obtain each public target parameter, and the target smart contract is called to calculate each of the public target parameters to obtain a first calculation result; each management node in the blockchain is called to perform offline calculation on each of the target input parameters to obtain a second calculation result, and each of the management nodes generates a zero-knowledge proof corresponding to the second calculation result; each verification node in the blockchain is called to verify the first calculation result to obtain a verification result, and each of the verification nodes deploys the verification result and the zero-knowledge proof to the blockchain.

[0042] In this embodiment, during operation, the terminal device first links to a preset blockchain. At the same time, the terminal device detects the blockchain. When it detects that each participating node in the blockchain issues a contract execution instruction, the terminal device obtains the target input parameters of each participating node, and calls the built-in data encryption device of the terminal device to perform a hash operation on each target input parameter to obtain each encrypted target parameter. After that, the terminal device makes each encrypted target parameter public through the target smart contract in the blockchain to obtain each public target parameter. The terminal device calls the target smart contract to execute the contract according to the preset contract rules. The target parameters are made public for calculation and a first settlement result is obtained. After that, the terminal device calls each management node corresponding to the smart contract to calculate each target input parameter according to the contract rules to obtain a second calculation result. Each management node generates a zero-knowledge proof corresponding to the second calculation result. Finally, the terminal device inputs the obtained first calculation result into each verification node in the blockchain. Each verification node verifies the first calculation result to obtain a verification result. Each verification node packages the verification result and the zero-knowledge proof and deploys them on the blockchain so that each participating node can view the verification result on the blockchain.

[0043] In this way, the present invention adopts a method in which the target smart contract calculates each public target parameter to obtain a first calculation result, and each management node in the blockchain calculates each target input parameter to obtain a second calculation result and a zero-knowledge proof corresponding to the second calculation result, and each verification node in the blockchain packages the zero-knowledge proof and the verification result corresponding to the first calculation result onto the chain, thereby achieving the technical effect that the target smart contract does not need to increase the amount of additional calculations, thereby ensuring the accuracy of the calculation results, and further protecting the privacy information of each participant. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] Figure 1 It is a schematic diagram of the structure of a terminal device in a hardware operating environment involved in an embodiment of the present invention;

[0045] Figure 2 This is a flow chart of a first embodiment of a method for executing a smart contract of the present invention;

[0046] Figure 3 This is a flow chart of a second embodiment of a method for executing a smart contract of the present invention;

[0047] Figure 4 A detailed flowchart of an embodiment of a method for executing a smart contract of the present invention;

[0048] Figure 5 This is a schematic diagram of the functional modules involved in an embodiment of the smart contract execution method of the present invention.

[0049] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0050] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.

[0051] Please refer to Figure 1 , Figure 1 A schematic diagram of the terminal device structure of the hardware operating environment involved in the embodiment of the present invention.

[0052] The terminal device targeted by the embodiment of the present invention may be a PC (Personal Computer) with an internally integrated Windows system as an operating system. Of course, the terminal device may also be other fixed terminal devices such as a server or a mobile terminal device such as a mobile phone or a tablet.

[0053] like Figure 1 As shown, the terminal device may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a wireless fidelity (WIreless-FIdelity, WI-FI) interface). The memory 1005 may be a high-speed random access memory (Random Access Memory, RAM) memory, or a stable non-volatile memory (Non-Volatile Memory, NVM), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.

[0054] Those skilled in the art will understand that Figure 1 The structure shown in the figure does not constitute a limitation on the terminal device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.

[0055] like Figure 1 As shown, the memory 1005 as a storage medium may include an operating system, a data storage module, a network communication module, a user interface module and an execution program of a smart contract.

[0056] exist Figure 1 In the terminal device shown, the network interface 1004 is mainly used for data communication with other devices; the user interface 1003 is mainly used for data interaction with the user; the processor 1001 and the memory 1005 in the terminal device of the present invention can be set in the terminal device, and the terminal device calls the execution program of the smart contract stored in the memory 1005 through the processor 1001, and executes the execution method of the smart contract provided by the embodiment of the present invention.

[0057] Based on the above-mentioned terminal device, various embodiments of the execution method of the smart contract of the present invention are provided.

[0058] Please refer to Figure 2 , Figure 2 This is a flow chart of the first embodiment of the calling method of the smart contract of the present invention.

[0059] It should be understood that although a logical order is shown in the flowchart, in some cases, the execution method of the smart contract of the present invention may of course execute the steps shown or described in an order different from that shown here.

[0060] In this embodiment, the method for executing a smart contract of the present invention is applied to a terminal device configured with a blockchain, and the blockchain includes a target smart contract, and may include the following steps:

[0061] Step S10: Obtain the target input parameters corresponding to each participating node in the blockchain, and encrypt each of the target input parameters to obtain each encrypted target parameter;

[0062] In this embodiment, during operation, the terminal device first links to the blockchain of the developer's instructions and calls the instruction detection device set in the terminal device to detect the blockchain. When the instruction device detects that each participating node in the blockchain issues an execution instruction to the target smart contract, the terminal device obtains the target input parameters corresponding to each participating node, and calls the data encryption device set in the terminal device to perform a hash operation on each target input parameter to obtain each encrypted target parameter.

[0063] Exemplarily, for example, during operation, the terminal device calls the above-mentioned instruction detection device to detect various instructions received by the above-mentioned blockchain. When the instruction detection device determines that the blockchain has received a contract execution instruction issued by all or part of the participating nodes in the blockchain, the terminal device obtains the target input parameters corresponding to each participating node that issued the contract execution instruction. At the same time, the terminal device calls the above-mentioned data encryption device to perform hash operations on the user privacy data corresponding to each participating node in each target input parameter to obtain each encrypted target parameter.

[0064] It should be noted that, in this embodiment, the target input parameters corresponding to the above-mentioned target smart contract can be on-chain assets or other data, links and options corresponding to the contract rules contained in the target smart contract, and the execution method of the smart contract of the present invention does not impose any restrictions on this.

[0065] Furthermore, in a feasible embodiment, before the above step S10, the execution method of the smart contract of the present invention may further include:

[0066] Step A10: Determine candidate nodes among the participating nodes in the blockchain;

[0067] In this embodiment, the terminal device calls the node detection device to determine the target participating nodes that input the above-mentioned on-chain assets as pledge targets into the blockchain among the participating nodes in the above-mentioned blockchain, and the terminal device determines each of the target participating nodes as candidate nodes.

[0068] Step A20: obtaining a preset management quantity threshold, randomly selecting a target candidate node from each of the candidate nodes according to the management quantity threshold, and determining the target candidate node as the management node;

[0069] In this embodiment, the terminal device reads the storage device to obtain the management quantity threshold pre-stored by the developer, and the terminal device inputs the management quantity threshold to the above-mentioned node detection device, and the node detection device randomly selects a target candidate node from each of the above-mentioned candidate nodes according to the management quantity threshold, and the terminal device determines each of the target candidate nodes as a management node.

[0070] Exemplarily, for example, the terminal device calls the node detection device to determine, among the participating nodes in the above-mentioned blockchain, each target participating node that inputs an on-chain asset into the blockchain and uses the on-chain asset as a pledged object. The terminal device determines each of the target participating nodes as a candidate node. Afterwards, the terminal device reads the storage device to obtain the management quantity threshold pre-stored by the developer, and determines the number of management nodes according to the management quantity threshold. That is, when the management quantity threshold is 5, the terminal device determines that the number of management nodes is 5. Afterwards, the terminal device inputs the number of management nodes into the node detection device, and the node detection device randomly selects 5 target candidate nodes from each of the candidate nodes. The terminal device determines the 5 target candidate nodes as the management nodes of the target smart contract.

[0071] It should be noted that, in this embodiment, the number of management nodes should be less than or equal to the number of candidate nodes. The user of the terminal device can adjust the number of management nodes according to actual usage, and the execution method of the smart contract of the present invention does not limit this.

[0072] Furthermore, in a feasible embodiment, after the above step A20, the execution method of the smart contract of the present invention may further include:

[0073] Step B10: Obtain preset contract reward parameters and contract penalty parameters;

[0074] In this embodiment, the terminal device reads the above storage device to obtain the contract reward parameters and contract penalty parameters pre-stored by the developer.

[0075] Step B20: testing the zero-knowledge proof and determining whether the zero-knowledge proof is correct;

[0076] In this embodiment, the terminal device inputs the acquired zero-knowledge proof into a data processing device configured in the terminal device, and the data processing device determines to detect the zero-knowledge proof and judge whether the zero-knowledge proof is correct.

[0077] Step B30: If yes, executing the contract reward operation corresponding to the contract reward parameter on each management node according to the contract reward parameter;

[0078] In this embodiment, when the terminal device determines through the data processing device that a target calculation result consistent with the above-mentioned second calculation result can be obtained according to the above-mentioned zero-knowledge proof and each target input parameter, the terminal device determines that the zero-knowledge proof is correct, and performs a contract reward operation on each of the above-mentioned management nodes according to the above-mentioned contract reward parameters.

[0079] Step B40: If not, executing the contract penalty operation corresponding to the contract penalty parameter on each of the management nodes according to the contract reward parameter;

[0080] In this embodiment, when the terminal device determines through the data processing device that the target calculation result consistent with the above-mentioned second calculation result cannot be obtained according to the above-mentioned zero-knowledge proof and each target input parameter, the terminal device determines that the zero-knowledge proof is wrong, and performs a contract penalty operation on each of the above-mentioned management nodes according to the above-mentioned contract penalty parameters.

[0081] Exemplarily, for example, the terminal device reads the above-mentioned storage device to obtain the contract reward parameters pre-stored by the developer, and the terminal device determines the target on-chain asset quantity for rewarding each management node according to the contract reward parameters. After that, the terminal device inputs the obtained zero-knowledge proof into the above-mentioned data processing device, and the data processing device performs calculation according to the zero-knowledge proof and each of the above-mentioned target input parameters, and determines whether a target calculation result consistent with the above-mentioned second calculation result can be obtained. When the data processing device determines that the target calculation result can be obtained, the terminal device determines that the zero-knowledge proof is correct, and sends the on-chain assets corresponding to the target on-chain asset quantity to each of the management nodes according to the contract reward parameters to complete the above-mentioned contract reward operation;

[0082] and,

[0083] The terminal device reads the contract penalty parameters pre-stored by the developer in the storage device, and the terminal device determines the target on-chain asset quantity for punishing each management node according to the contract penalty parameters. After that, the terminal device inputs the obtained zero-knowledge proof into the data processing device, and the data processing device performs calculations according to the zero-knowledge proof and each of the target input parameters, and determines whether a target calculation result consistent with the second calculation result can be obtained. When the data processing device determines that the target calculation result cannot be obtained, the terminal device determines that the zero-knowledge proof is wrong, and deducts the on-chain assets corresponding to the target on-chain asset quantity from each of the management nodes according to the contract penalty parameters to complete the above-mentioned contract penalty operation.

[0084] Step S20: Publicizing each of the encrypted target parameters through the target smart contract in the blockchain to obtain each public target parameter, and calling the target smart contract to calculate each of the public target parameters to obtain a first calculation result;

[0085] In this embodiment, the terminal device makes the acquired encrypted target parameters public on the above-mentioned blockchain through the target smart contract in the above-mentioned blockchain and obtains each public target parameter. The terminal device reads the above-mentioned storage device to obtain the contract rules corresponding to the target smart contract. The terminal device calls the target smart contract to calculate each public target parameter according to the contract rules to obtain a first calculation result.

[0086] For example, see Figure 4 , Figure 4The present invention is a detailed flowchart of an embodiment of the execution method of a smart contract of the present invention. The terminal device publicly obtains each of the above-mentioned encrypted target parameters on the above-mentioned blockchain through the above-mentioned target smart contract. The terminal device then obtains each of the above-mentioned public target parameters on the blockchain. At the same time, the terminal device reads the above-mentioned storage device to obtain the above-mentioned contract rules. When the contract rules are the rock-paper-scissors game rules preset by the developer, the terminal device then calls the above-mentioned target smart contract to calculate each of the public target parameters on the above-mentioned blockchain according to the contract rules. That is, when public target parameter 1 is rock and public target parameter 2 is cloth, the target smart contract determines that the first calculation result corresponding to the public target parameter 1 and the public target parameter 2 is the victory of the public target parameter 2 through the rock-paper-scissors game rules corresponding to the contract rules.

[0087] It should be noted that, in this embodiment, in addition to corresponding to the specifically specified rock-paper-scissors rules, the above-mentioned contract rules can also correspond to other types of transaction or game rules. Developers can arbitrarily adjust the contract rules according to actual application requirements, and the execution method of the smart contract of the present invention does not limit this.

[0088] Furthermore, in a feasible embodiment, the above step S20 may specifically include:

[0089] Step S201: Control each management node to enter offline mode;

[0090] In this embodiment, the terminal device controls each of the above-mentioned management nodes to disconnect from the above-mentioned blockchain and enter the offline mode.

[0091] Step S202: controlling each of the management nodes in the offline mode to calculate each of the target input parameters according to the contract rules corresponding to the target smart contract to obtain a second calculation result;

[0092] In this embodiment, the terminal device reads the above-mentioned storage device to obtain the above-mentioned contract rules. Thereafter, the terminal device sends each of the above-mentioned target input parameters to each of the above-mentioned management nodes, and controls each of the management nodes to calculate each of the target input parameters according to the contract rules to obtain the above-mentioned second calculation result.

[0093] Exemplarily, for example, the terminal device controls each of the above-mentioned management nodes to disconnect the wireless network link with the above-mentioned blockchain, thereby making each of the management nodes enter the offline mode. After that, the terminal device reads the above-mentioned storage device to obtain the above-mentioned rock-paper-scissors game rules pre-stored by the developer. At the same time, the terminal device inputs the rock-paper-scissors game rules and the target input parameter 1 as rock and the target input parameter 2 as cloth to each of the management nodes, and each of the management nodes obtains the above-mentioned second calculation result as the target input parameter 2 victory in the offline mode according to the rock-paper-scissors game rules.

[0094] Further, in a feasible embodiment, before the step of "publicizing each of the encrypted target parameters through the target smart contract to obtain each public target parameter" in the above step S20, the execution method of the smart contract of the present invention may also include:

[0095] Step C10: obtaining a preset contract trigger threshold, determining the number of participating nodes corresponding to each participating node according to each of the encrypted target parameters, and comparing the contract trigger threshold with the number of participating nodes to obtain a comparison result;

[0096] In this embodiment, the terminal reads the storage device to obtain the contract trigger threshold pre-stored by the developer. After that, the terminal device detects each of the above-mentioned encrypted target parameters and determines the number of encrypted parameters corresponding to each of the encrypted target parameters. The terminal device further determines the number of participating nodes corresponding to each of the above-mentioned participating nodes based on the number of encrypted parameters. The terminal device inputs the contract trigger threshold and the number of participating nodes into the above-mentioned data processing device, and the data processing device compares the contract trigger threshold with the number of participating nodes to obtain a comparison result.

[0097] Step C20: When the comparison result is that the number of participating nodes is less than the contract triggering threshold, a refund operation is performed on each of the encrypted target parameters;

[0098] In this embodiment, when the terminal device determines that the comparison result is that the number of participating nodes is less than the contract trigger threshold, the terminal device determines that the contract execution instruction is an invalid execution and returns each of the encrypted target parameters to each of the participating nodes.

[0099] Step C30: When the comparison result is that the number of participating nodes is greater than or equal to the contract triggering threshold, executing the step of making each of the encrypted target parameters public through the target smart contract in the blockchain to obtain each public target parameter;

[0100] In this embodiment, when the terminal device determines that the comparison result is that the number of participating nodes is greater than or equal to the contract trigger threshold, the terminal device determines that the contract execution instruction is a valid instruction, and according to the instruction, the above-mentioned encrypted target parameters are made public on the blockchain through the above-mentioned target smart contract in the above-mentioned blockchain, thereby obtaining the above-mentioned public target parameters.

[0101] Exemplarily, for example, the terminal device first reads the above-mentioned storage device to obtain the contract trigger threshold value pre-stored in the storage device by the developer. When the contract trigger threshold value is 2, the terminal device determines that at least two target output parameters corresponding to the participating nodes need to be obtained before the above-mentioned target smart contract can be called. After that, the terminal device detects each of the above-mentioned encryption parameters and determines the number of encryption parameters corresponding to each of the encryption target parameters. When the terminal device only detects that the number of encryption parameters is 1, the terminal device determines that the number of participating nodes corresponding to each of the participating nodes is 1. After that, the terminal device inputs the number of participating nodes of 1 and the contract trigger threshold of 2 into the above-mentioned data processing device , the data processing device compares the contract trigger threshold with the number of participating nodes and obtains that when the comparison result is that the number of participating nodes 1 is less than the contract trigger threshold 2, the terminal device determines that the above-mentioned contract execution instruction is invalid and returns each of the above-mentioned encrypted target parameters to each of the above-mentioned participating nodes. When the terminal device detects that the number of encrypted parameters is 3, the terminal device determines that the number of participating nodes corresponding to each of the participating nodes is 3. Similarly, when the data processing device determines that the number of nodes 3 is greater than the contract trigger threshold 2, the terminal device discloses each of the encrypted target parameters in the above-mentioned blockchain through the above-mentioned smart contract in accordance with the instruction to obtain each of the above-mentioned public target parameters.

[0102] Step S30: calling each management node in the blockchain to perform offline calculation on each of the target input parameters to obtain a second calculation result, and each of the management nodes generates a zero-knowledge proof corresponding to the second calculation result;

[0103] In this embodiment, the terminal device calls each of the above-mentioned management nodes to receive each of the above-mentioned target input parameters, and each of the management nodes calculates each of the target input parameters according to the above-mentioned contract rules in offline mode to obtain a second calculation result. At the same time, after obtaining the second calculation result, each of the management nodes generates the above-mentioned zero-knowledge proof according to the process of obtaining the second calculation result.

[0104] For example, for example, Figure 4As shown, the terminal device first determines that the target input parameter 1 corresponding to the participating node 1 is rock, and determines that the target input parameter 2 corresponding to the parameter node 2 is cloth. After that, the terminal device sends the target input parameter 1 as rock and the target input parameter 2 as cloth to each of the above-mentioned management nodes, and each of the management nodes calculates the target input parameter 1 and the target input parameter 2 according to the above-mentioned rock-paper-scissors game rules to obtain a second calculation result that the target input parameter 2 wins. At the same time, each of the management nodes records the process of obtaining the second calculation result and generates the above-mentioned zero-knowledge proof.

[0105] Step S40: calling each verification node in the blockchain to verify the first calculation result to obtain a verification result, and each verification node deploys the verification result and the zero-knowledge proof into the blockchain;

[0106] In this embodiment, the terminal device determines each verification node preset by the developer in the above-mentioned blockchain, and controls each verification node to verify the above-mentioned first calculation result to obtain a verification result. When the terminal device determines that the verification result is valid for the first calculation result, the terminal device controls each verification node to package the verification result and the above-mentioned zero-knowledge proof and deploy them into the blockchain.

[0107] For example, for example, Figure 4 As shown, the terminal device first determines each verification node with verification authority in the above-mentioned blockchain, and the terminal device controls each verification node to calculate each public target parameter according to the above-mentioned contract rules to obtain a fourth calculation result. Each verification node obtains a verification result by comparing the fourth calculation result with the above-mentioned first calculation result. When the fourth calculation result is consistent with the first calculation result, each verification node determines that the verification result is a valid result. The terminal device then packages the verification result and the above-mentioned zero-knowledge proof to obtain a result data packet, and deploys the result data packet to the blockchain for public disclosure.

[0108] Further, in a feasible embodiment, the step of “calling each verification node in the blockchain to verify the first calculation result to obtain a verification result” in the above step S40 may specifically include:

[0109] Step S401: calling each verification node to calculate each of the public target parameters to obtain a fourth calculation result, and comparing the fourth calculation result with the first calculation result to obtain a comparison result;

[0110] In this embodiment, the terminal device first determines each verification node with verification authority in the above-mentioned blockchain. After that, the terminal device calls each verification node to calculate each public target parameter on the blockchain according to the above-mentioned contract rules to obtain the above-mentioned fourth calculation result. The terminal device inputs the fourth calculation result and the above-mentioned first calculation result into the data comparison device, and the data comparison device compares the fourth calculation result with the first calculation result to obtain a comparison result.

[0111] Step S402: when the comparison result is that the fourth calculation result is consistent with the first calculation result, determining that the verification result is that the first calculation result is valid;

[0112] In this embodiment, when the terminal device determines through the data comparison device that the comparison result is that the fourth calculation result is consistent with the first calculation result, the terminal device determines that the verification result is that the first calculation result is valid.

[0113] Step S403: when the comparison result is that the fourth calculation result is inconsistent with the first calculation result, determining that the verification result is that the first calculation result is invalid;

[0114] In this embodiment, when the terminal device determines through the data comparison device that the comparison result is that the fourth calculation result is inconsistent with the first calculation result, the terminal device determines that the verification result is that the first calculation result is invalid.

[0115] Exemplarily, for example, the terminal device first determines each verification node with verification authority in the above-mentioned blockchain, and then controls each verification node to calculate the public target parameter 1 on the blockchain as stone and the public target parameter 2 as cloth according to the above-mentioned rock-paper-scissors game rules to obtain a fourth calculation result of public target parameter 2 victory. At the same time, the terminal device obtains the above-mentioned first calculation result as public target parameter 2 victory, and the terminal device inputs the fourth settlement result as public target parameter 2 victory and the first calculation result as public target parameter 2 victory to the above-mentioned data comparison device. When the data comparison device compares the first calculation result with the fourth calculation result and determines that the first calculation result is consistent with the fourth calculation result, the terminal device determines that the above-mentioned verification result is that the first calculation result is valid;

[0116] Alternatively, when the fourth calculation result is that the public target parameter 2 wins, and the above-mentioned first calculation result is that the public target parameter 1 wins, the data comparison device compares the first calculation result with the fourth calculation result and determines that the first calculation result is inconsistent with the fourth calculation result, the terminal device determines that the above-mentioned verification result is that the first calculation result is invalid.

[0117] In this embodiment, during operation, the terminal device first calls the instruction detection device set in the terminal device to detect the blockchain. When the instruction device detects that each participating node in the blockchain issues an execution instruction to the target smart contract, the terminal device obtains the target input parameters corresponding to each participating node, and calls the data encryption device set in the terminal device to perform a hash operation on each target input parameter to obtain each encrypted target parameter. After that, the terminal device publishes the obtained encrypted target parameters on the blockchain through the target smart contract and obtains each public target parameter. The terminal device reads the storage device to obtain the contract rules corresponding to the target smart contract. The terminal device calls the target smart contract to execute the execution instruction on each participating node according to the contract rules. The terminal device calculates the target parameters to obtain the first calculation result. After that, the terminal device calls each of the above-mentioned management nodes to receive each of the above-mentioned target input parameters, and each of the management nodes calculates each of the target input parameters according to the above-mentioned contract rules in offline mode to obtain the second calculation result. At the same time, after obtaining the second calculation result, each of the management nodes generates the above-mentioned zero-knowledge proof according to the process of obtaining the second calculation result. Finally, the terminal device determines each verification node preset by the developer in the above-mentioned blockchain, and controls each of the verification nodes to verify the above-mentioned first calculation result to obtain the verification result. When the terminal device determines that the verification result is valid for the first calculation result, the terminal device controls each of the verification nodes to package the verification result and the above-mentioned zero-knowledge proof and deploy them into the blockchain.

[0118] In this way, the present invention adopts a method in which the target smart contract calculates each public target parameter to obtain a first calculation result, and each management node in the blockchain calculates each target input parameter to obtain a second calculation result and a zero-knowledge proof corresponding to the second calculation result, and each verification node in the blockchain packages the zero-knowledge proof and the verification result corresponding to the first calculation result onto the chain, thereby achieving the technical effect that the target smart contract does not need to increase the amount of additional calculations, thereby ensuring the accuracy of the calculation results, and further protecting the privacy information of each participant.

[0119] Furthermore, based on the first embodiment of the method for executing a smart contract of the present invention described above, a second embodiment of the method for executing a smart contract of the present invention is proposed herein.

[0120] Please refer to Figure 3 , Figure 3 The flowchart of the second embodiment of the execution method of the smart contract of the present invention is shown in FIG. The execution method of the smart contract of the present invention may further include:

[0121] Step D10: each of the participating nodes obtains a third calculation result based on each of the target input parameters;

[0122] In this embodiment, the terminal device can control each participating node in the blockchain to calculate each public target parameter disclosed on the blockchain according to the above-mentioned contract rules and obtain a third calculation result.

[0123] Step D20: comparing the third calculation result with the second calculation result and determining whether the third calculation result is consistent with the second calculation result;

[0124] In this embodiment, the terminal device sends the acquired second calculation result to each of the participating nodes, and each of the participating nodes compares the third calculation result with the second calculation result and determines whether the third calculation result is consistent with the second calculation result.

[0125] Step D30: if it is determined that the third calculation result is consistent with the second calculation result, determining that the second calculation result is a valid calculation result;

[0126] In this embodiment, if the participating node determines that the third calculation result is consistent with the second calculation result, the terminal device determines that the second calculation result is a valid calculation result.

[0127] Step D40: if it is determined that the third calculation result is inconsistent with the second calculation result, determining that the second calculation result is an invalid calculation result;

[0128] In this embodiment, if the participating node determines that the third calculation result is inconsistent with the second calculation result, the terminal device determines that the second calculation result is an invalid calculation result.

[0129] Exemplarily, for example, the terminal device controls the above-mentioned participating node 1 and the above-mentioned participating node 2 in the above-mentioned blockchain to calculate the public target parameter 1 on the blockchain as stone and the public target parameter 2 as cloth according to the above-mentioned rock-paper-scissors game rules to obtain a third calculation result of public target parameter 2 victory. At the same time, the terminal device inputs the obtained second calculation result as target input parameter 2 victory into the participating node 1 and the participating node 2, and the participating node 1 and the participating node 2 respectively compare the second calculation result with the third calculation result. When the participating node 1 and the participating node 2 both determine that the second calculation result is consistent with the third calculation result, the terminal device determines that the second calculation result is a valid calculation result, and sends the on-chain assets to each of the management nodes according to the above-mentioned contract reward parameters to complete the above-mentioned contract reward operation;

[0130] Alternatively, when the third calculation result is a victory for the public target parameter 2, and at the same time, the second calculation result obtained by the terminal device is a victory for the target input parameter 1, the participating node 1 and the participating node 2 both determine that the second calculation result is inconsistent with the third calculation result, and the terminal device determines that the second calculation result is an invalid calculation result, and deducts the on-chain assets from each of the management nodes according to the above-mentioned contract penalty parameters to complete the above-mentioned contract penalty operation.

[0131] In this embodiment, first, the terminal device can control each participating node in the blockchain to calculate each public target parameter disclosed on the blockchain according to the above-mentioned contract rules and obtain a third calculation result. After that, the terminal device sends the obtained second calculation result to each of the above-mentioned participating nodes, and each of the participating nodes compares the third calculation result with the second calculation result and determines whether the third calculation result is consistent with the second calculation result. Finally, if the above-mentioned participating node determines that the third calculation result is consistent with the second calculation result, the terminal device determines that the second calculation result is a valid calculation result, and if the above-mentioned participating node determines that the third calculation result is inconsistent with the second calculation result, the terminal device determines that the second calculation result is an invalid calculation result.

[0132] In this way, the present invention adopts a method in which each participating node calculates each public target parameter according to the contract rules to obtain a third calculation result, and determines whether the calculation result of each management node is correct by comparing the third calculation result with the second calculation result, thereby achieving the purpose of supervision of the management node by each participating node.

[0133] In addition, the present invention also provides an execution device for a smart contract, please refer to Figure 5 , Figure 5 Schematic diagram of functional modules involved in an embodiment of a method for executing a smart contract of the present invention. Figure 5 As shown, the execution device of the smart contract of the present invention includes:

[0134] The parameter encryption module 10 is used to obtain the target input parameters corresponding to each participating node in the blockchain, and encrypt each of the target input parameters to obtain each encrypted target parameter;

[0135] A first calculation module 20, used to make each of the encrypted target parameters public through the target smart contract in the blockchain to obtain each public target parameter, and call the target smart contract to calculate each of the public target parameters to obtain a first calculation result;

[0136] A second calculation module 30 is used to call each management node in the blockchain to perform offline calculation on each of the target input parameters to obtain a second calculation result, and each of the management nodes generates a zero-knowledge proof corresponding to the second calculation result;

[0137] The result verification module 40 is used to call each verification node in the blockchain to verify the first calculation result to obtain a verification result, and each verification node deploys the verification result and the zero-knowledge proof into the blockchain.

[0138] Furthermore, the parameter encryption module 10 includes:

[0139] A first node screening unit, configured to determine candidate nodes from among the participating nodes in the blockchain;

[0140] The second node screening unit is used to obtain a preset management quantity threshold, randomly select a target candidate node from each of the candidate nodes according to the management quantity threshold, and determine the target candidate node as the management node.

[0141] Furthermore, the result verification module 40 includes:

[0142] Mechanism parameter acquisition unit, used to obtain preset contract reward parameters and contract penalty parameters;

[0143] A knowledge proof detection unit, used to detect the zero-knowledge proof and determine whether the zero-knowledge proof is correct;

[0144] A reward operation execution unit, configured to execute a contract reward operation corresponding to the contract reward parameter on each of the management nodes according to the contract reward parameter if it is determined that the zero-knowledge proof is correct;

[0145] A penalty operation execution unit is used to execute a contract penalty operation corresponding to the contract penalty parameter on each management node according to the contract reward parameter if it is determined that the zero-knowledge proof is incorrect.

[0146] Furthermore, the parameter encryption module 10 further includes:

[0147] A threshold parameter comparison unit, used to obtain a preset contract trigger threshold, determine the number of participating nodes corresponding to each participating node according to each of the encrypted target parameters, and compare the contract trigger threshold with the number of participating nodes to obtain a comparison result;

[0148] A contract trigger failure unit, configured to perform a refund operation on each of the encrypted target parameters when the comparison result shows that the number of participating nodes is less than the contract trigger threshold;

[0149] The contract trigger success unit is used to execute the step of making each encrypted target parameter public through the target smart contract in the blockchain to obtain each public target parameter when the comparison result is that the number of participating nodes is greater than or equal to the contract trigger threshold.

[0150] Furthermore, the second calculation module 30 includes:

[0151] An offline mode control unit, used to control each management node to enter offline mode;

[0152] The management node computing unit is used to control each of the management nodes through the offline mode to calculate each of the target input parameters according to the contract rules corresponding to the target smart contract to obtain a second calculation result.

[0153] Furthermore, the result verification module 40 further includes:

[0154] a verification node calculation unit, configured to call each verification node to calculate each of the public target parameters to obtain a fourth calculation result, and compare the fourth calculation result with the first calculation result to obtain a comparison result;

[0155] A first result comparison unit, configured to, when the comparison result is that the fourth calculation result is consistent with the first calculation result, determine that the verification result is that the first calculation result is valid;

[0156] The second result comparison unit is used to determine that the verification result is that the first calculation result is invalid when the comparison result is that the fourth calculation result is inconsistent with the first calculation result.

[0157] Furthermore, the result verification module 40 further includes:

[0158] A participating node calculation unit, configured to obtain a third calculation result based on each of the target input parameters by each of the participating nodes;

[0159] A participating node verification unit, configured to compare the third calculation result with the second calculation result and determine whether the third calculation result is consistent with the second calculation result;

[0160] a third result comparison unit, configured to determine that the second calculation result is a valid calculation result if it is determined that the third calculation result is consistent with the second calculation result;

[0161] The fourth result comparison unit is used to determine that the second calculation result is an invalid calculation result if it is determined that the third calculation result is inconsistent with the second calculation result.

[0162] In addition, the present invention also provides a terminal device having an execution program of a smart contract that can be run on a processor, and when the terminal device executes the execution program of the smart contract, the steps of the execution method of the smart contract in any of the above embodiments are implemented.

[0163] The specific embodiments of the terminal device of the present invention are basically the same as the embodiments of the above-mentioned smart contract execution method, and will not be described in detail here.

[0164] In addition, the present invention also provides a computer-readable storage medium, on which an execution program of a smart contract is stored. When the execution program of the smart contract is executed by a processor, the steps of the execution method of the smart contract described in any of the above embodiments are implemented.

[0165] The specific embodiments of the computer-readable storage medium of the present invention are basically the same as the embodiments of the above-mentioned smart contract execution method, and will not be described in detail here.

[0166] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.

[0167] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0168] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course, by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product is stored in a storage medium (such as ROM / RAM, disk, CD) as described above, including a number of instructions for a terminal device (which can be a PC (Personal Computer) with an internally integrated Windows system as an operating system, and of course, the terminal device can also be other fixed terminal devices such as servers or mobile terminal devices such as mobile phones and tablets, etc.) to execute the methods described in the various embodiments of the present invention.

[0169] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A method for executing a smart contract, characterized in that: The execution method of the smart contract comprises the following steps: Determine candidate nodes among participating nodes in the blockchain, wherein the candidate nodes are participating nodes that input on-chain assets into the blockchain as pledged objects; Obtaining a preset management quantity threshold, randomly selecting a target candidate node from each of the candidate nodes according to the management quantity threshold, and determining the target candidate node as a management node; Obtain the target input parameters corresponding to each participating node in the blockchain, and encrypt each of the target input parameters to obtain each encrypted target parameter; Publicizing each of the encrypted target parameters through a target smart contract in the blockchain to obtain each public target parameter, and calling the target smart contract to calculate each of the public target parameters to obtain a first calculation result; Calling each management node in the blockchain to perform offline calculation on each of the target input parameters to obtain a second calculation result, and each of the management nodes generates a zero-knowledge proof corresponding to the second calculation result; Calling each verification node to calculate each of the public target parameters to obtain a fourth calculation result, and comparing the fourth calculation result with the first calculation result to obtain a comparison result; When the comparison result is that the fourth calculation result is consistent with the first calculation result, determining that the verification result is that the first calculation result is valid; When the comparison result is that the fourth calculation result is inconsistent with the first calculation result, determining that the verification result is that the first calculation result is invalid; Obtaining, by each of the participating nodes, a third calculation result based on each of the target input parameters; Compare the third calculation result with the second calculation result and determine whether the third calculation result is consistent with the second calculation result; If it is determined that the third calculation result is consistent with the second calculation result, determining that the second calculation result is a valid calculation result; If it is determined that the third calculation result is inconsistent with the second calculation result, determining that the second calculation result is an invalid calculation result; Each of the verification nodes deploys the verification result and the zero-knowledge proof into the blockchain.

2. The method for executing a smart contract according to claim 1, wherein: After the step of determining the target candidate node as a management node, the method further includes: Get the preset contract reward parameters and contract penalty parameters; Testing the zero-knowledge proof and determining whether the zero-knowledge proof is correct; If yes, then executing the contract reward operation corresponding to the contract reward parameter on each management node according to the contract reward parameter; If not, a contract penalty operation corresponding to the contract penalty parameter is performed on each management node according to the contract reward parameter.

3. The method for executing a smart contract according to claim 1, wherein: The method further comprises: Obtaining a preset contract trigger threshold, determining the number of participating nodes corresponding to each participating node according to each of the encrypted target parameters, and comparing the contract trigger threshold with the number of participating nodes to obtain a comparison result; When the comparison result is that the number of participating nodes is less than the contract triggering threshold, a refund operation is performed on each of the encrypted target parameters; When the comparison result is that the number of participating nodes is greater than or equal to the contract trigger threshold, the step of making each of the encrypted target parameters public through the target smart contract in the blockchain to obtain each public target parameter is executed.

4. The method for executing a smart contract according to claim 1, wherein: The step of calling each management node in the blockchain to perform offline calculation on each target input parameter to obtain a second calculation result includes: Control each management node to enter offline mode; Through the offline mode, each management node is controlled to calculate each target input parameter according to the contract rules corresponding to the target smart contract to obtain a second calculation result.

5. A smart contract execution device, characterized in that: The device comprises: A parameter encryption module, used to determine each candidate node among each participating node in the blockchain, wherein the candidate node is a participating node that inputs on-chain assets as pledge targets into the blockchain; Obtaining a preset management quantity threshold, randomly selecting a target candidate node from each of the candidate nodes according to the management quantity threshold, and determining the target candidate node as a management node; The parameter encryption module is also used to obtain the target input parameters corresponding to each participating node in the blockchain, and encrypt each of the target input parameters to obtain each encrypted target parameter; A first calculation module, used to make each of the encrypted target parameters public through the target smart contract in the blockchain to obtain each public target parameter, and call the target smart contract to calculate each of the public target parameters to obtain a first calculation result; A second calculation module is used to call each management node in the blockchain to perform offline calculation on each of the target input parameters to obtain a second calculation result, and each of the management nodes generates a zero-knowledge proof corresponding to the second calculation result; A result verification module, used for calling each verification node to calculate each of the public target parameters to obtain a fourth calculation result, and comparing the fourth calculation result with the first calculation result to obtain a comparison result; When the comparison result is that the fourth calculation result is consistent with the first calculation result, determining that the verification result is that the first calculation result is valid; When the comparison result is that the fourth calculation result is inconsistent with the first calculation result, determining that the verification result is that the first calculation result is invalid; Obtaining, by each of the participating nodes, a third calculation result based on each of the target input parameters; Compare the third calculation result with the second calculation result and determine whether the third calculation result is consistent with the second calculation result; If it is determined that the third calculation result is consistent with the second calculation result, determining that the second calculation result is a valid calculation result; If it is determined that the third calculation result is inconsistent with the second calculation result, determining that the second calculation result is an invalid calculation result; Each of the verification nodes deploys the verification result and the zero-knowledge proof into the blockchain.

6. A terminal device, characterized in that: The terminal device includes: a memory, a processor, and an execution program of a smart contract stored in the memory and executable on the processor. When the execution program of the smart contract is executed by the processor, the steps of the execution method of the smart contract as described in any one of claims 1 to 4 are implemented.

7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores an execution program of a smart contract, and when the execution program of the smart contract is executed by a processor, the steps of the execution method of a smart contract as described in any one of claims 1 to 4 are implemented.

Citation Information

Patent Citations

  • Zero knowledge proving method suitable for protecting privacy of block chain, and medium

    CN108418689A

  • Intelligent contract authentication data privacy protection method and system based on zero knowledge proof

    CN110781521A