Smart contract verification method, device and electronic equipment
By dividing the blockchain into a contract management system and a data storage system, and using read-write sets for smart contract verification, the problems of low smart contract verification efficiency and insufficient security in the existing technology are solved, and security improvement and Efficiency improvements.
Patent Information
- Application Number
- CN202110410155.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-03-15
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2039-03-15
AI Technical Summary
In the existing smart contract verification process, multiple node devices repeatedly pre-execute smart contracts. Frequent access to data status consumes resources and is inefficient, and it is difficult to avoid a single node from doing evil.
The blockchain is divided into a contract management system and a data storage system. The smart contract node pre-executes the read and write sets generated by the target smart contract, so that other nodes do not need to access the data storage node again. Logical verification improves security and reduces the number of data accesses. , decoupling about verification and data verification as independent parts.
It improves the security of smart contract execution, reduces the verification running cycle, simplifies the verification execution logic, avoids evildoing by a single node, and reduces the frequency of access to data storage nodes.
Smart Images

Figure CN112966311B
Abstract
Description
Technical Field
[0001] The embodiments of this specification relate to the field of blockchain technology, and more particularly to a smart contract verification method and device and an electronic device. Background Art
[0002] Blockchain technology, also known as distributed ledger technology, is an emerging technology in which several computing devices jointly participate in "bookkeeping" and jointly maintain a complete distributed database. Blockchain technology is widely used in many fields because of its decentralized, open and transparent characteristics, each computing device can participate in database records, and data can be quickly synchronized between computing devices. Summary of the invention
[0003] A smart contract verification method, device and electronic device provided in the embodiments of this specification:
[0004] According to a first aspect of an embodiment of this specification, a smart contract verification method is provided, the method comprising:
[0005] The data storage node broadcasts the target transaction initiated by the client to any smart contract node;
[0006] The smart contract node responds to the target transaction, pre-executes the target smart contract corresponding to the target transaction, and returns the pre-execution result to the data storage node;
[0007] The data storage node sends the pre-execution result to other smart contract nodes;
[0008] The other smart contract nodes simulate and execute the target smart contract according to the pre-execution result, and return the simulated pre-execution result obtained after simulating the execution of the target smart contract to the data storage node;
[0009] The data storage node determines that the pre-execution result verification passes when it is determined that the simulation pre-execution result is consistent with the pre-execution result.
[0010] According to a second aspect of the embodiments of this specification, a smart contract verification method is provided, the method comprising:
[0011] The smart contract node receives the pre-execution result sent by the data storage node; wherein the pre-execution result is the result obtained by other smart contract nodes responding to the target transaction initiated by the client and pre-executing the target smart contract corresponding to the target transaction;
[0012] According to a third aspect of an embodiment of this specification, a smart contract verification method includes:
[0013] The data storage node receives the target transaction initiated by the client;
[0014] Broadcast the target transaction to any smart contract node;
[0015] Receiving a pre-execution result returned by the smart contract node after pre-executing the target smart contract corresponding to the target transaction;
[0016] Send the pre-execution result to other smart contract nodes so that other smart contract nodes simulate and execute the target smart contract;
[0017] When the simulation execution result returned by the other node is consistent with the pre-execution result, it is determined that the pre-execution result verification has passed.
[0018] According to a fourth aspect of an embodiment of this specification, a smart contract verification device includes:
[0019] A receiving unit, wherein the smart contract node receives the pre-execution result sent by the data storage node; wherein the pre-execution result is a result obtained after other smart contract nodes respond to the target transaction initiated by the client and pre-execute the target smart contract corresponding to the target transaction;
[0020] The execution unit simulates and executes the target smart contract according to the pre-execution result, and returns the simulated pre-execution result obtained after the simulated execution of the target smart contract to the data storage node; for verification by the data storage node.
[0021] According to a fifth aspect of an embodiment of this specification, a smart contract verification device includes:
[0022] A first receiving unit, a data storage node receives a target transaction initiated by a client;
[0023] A broadcast unit, which broadcasts the target transaction to any smart contract node;
[0024] A second receiving unit receives a pre-execution result returned by the smart contract node after pre-executing the target smart contract corresponding to the target transaction;
[0025] A sending unit, sending the pre-execution result to other smart contract nodes, so that other smart contract nodes simulate and execute the target smart contract;
[0026] The verification unit determines that the pre-execution result verification passes when the simulation execution result returned by the other node is consistent with the pre-execution result.
[0027] According to a sixth aspect of the embodiments of this specification, there is provided an electronic device, including:
[0028] processor;
[0029] a memory for storing processor-executable instructions;
[0030] Wherein, the processor is configured as any of the above-mentioned smart contract verification methods.
[0031] The embodiments of this specification provide a smart contract verification scheme, which uses a read-write set generated by a smart contract node to pre-execute the target smart contract, so that other smart contract nodes do not need to access the data storage node again, and can use the read-write set to simulate the execution of the target smart contract; if the simulated execution results returned by the other smart contract nodes are consistent with the previous pre-execution results, it can be determined that the verification has passed. In this way, on the one hand, the security of smart contract execution can be improved through logical verification to prevent a single smart contract node from doing evil. On the other hand, the smart contract node that performs logical verification does not need to obtain the data status again, reducing the number of times the data storage node is accessed. On the other hand, the contract verification and data verification in the transaction process are decoupled and divided into two independent parts; the node device in the contract management system is only responsible for contract logic verification, and the node device in the data storage system is only responsible for data verification; the verification execution logic is simplified and the verification operation cycle is shortened. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1a This is a schematic diagram of smart contract verification of a traditional blockchain system provided in an embodiment of this specification;
[0033] Figure 1b It is a schematic diagram of a contract management system and a data storage system provided in an embodiment of this specification;
[0034] Figure 2 This is an embodiment of the present specification based on Figure 1b Flow chart of the smart contract verification method of the blockchain shown;
[0035] Figure 3 It is a schematic diagram of the process of a smart contract node obtaining data status from a data storage node provided in an embodiment of this specification;
[0036] Figure 4 It is a flow chart of a smart contract verification method based on a traditional blockchain provided in an embodiment of this specification;
[0037] Figure 5a yes Figure 4 Specific flow chart of step 2;
[0038] Figure 5b yes Figure 4 Specific flow chart of step 3;
[0039] Figure 6 yes Figure 2A flow chart of a method in which a data storage node is used as an execution subject;
[0040] Figure 7 yes Figure 2 A flowchart of the method in which the smart contract node is the execution subject;
[0041] Figure 8 It is a hardware structure diagram of a smart contract verification device provided in an embodiment of this specification;
[0042] Fig. 9 It is a module of the smart contract verification device provided in an embodiment of this specification;
[0043] Fig.10 It is a module of the smart contract verification device provided in an embodiment of this specification. DETAILED DESCRIPTION
[0044] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with this specification. Instead, they are merely examples of devices and methods consistent with some aspects of this specification as detailed in the appended claims.
[0045] The terms used in this specification are for the purpose of describing specific embodiments only and are not intended to limit this specification. The singular forms "a", "the" and "the" used in this specification and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0046] It should be understood that although the terms first, second, third, etc. may be used in this specification to describe various information, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0047] The smart contract verification solution provided in this specification can be applied not only in blockchain but also in non-blockchain.
[0048] Taking the application in blockchain as an example, smart contract is a computer protocol designed to be deployed on blockchain to disseminate, verify or execute contracts in an information-based manner. The corresponding operations can be executed by declaring business logic in the smart contract. Smart contracts allow trusted transactions without a third party. These transactions are traceable and irreversible. Smart contracts can provide security that is superior to traditional contract methods and reduce other transaction costs associated with contracts.
[0049] First, let’s introduce how smart contracts are deployed in traditional blockchains. Traditional smart contracts are deployed directly on node devices in the blockchain, and when the node device executes a transaction request, it directly runs the corresponding smart contract deployed locally; and the node device also stores the full amount of transaction data. In order to prevent a single node device from doing evil, such as tampering with data; Figure 1a As shown in the figure, the smart contract verification process of the traditional blockchain is:
[0050] 1. The blockchain system sends transactions to multiple node devices.
[0051] 2. Each node device performs pre-execution of the transaction and returns a pre-execution result set (usually with the signature of the corresponding node device).
[0052] 3. Verify each result set. If the pre-execution results are consistent, the verification is determined to be passed.
[0053] 4. After the verification is passed, the pre-execution results will be broadcast to the entire network for consensus (verification of data status).
[0054] It can be seen that in the existing smart contract verification, multiple node devices are required to repeatedly pre-execute the smart contract, and each pre-execution may need to access the world state of the blockchain to obtain the corresponding data state. Frequent access to the data state will consume a lot of resources and have low efficiency.
[0055] This specification proposes a smart contract verification solution based on blockchain, which divides the blockchain into a contract management system and a data storage system. The contract management system only stores the smart contracts of the blockchain, and the data storage system only stores the data status of the blockchain.
[0056] By using a smart contract node to pre-execute the target smart contract and generate a read-write set, other smart contract nodes do not need to access the data storage node again, and can use the read-write set to simulate the execution of the target smart contract; if the simulated execution results returned by the other smart contract nodes are consistent with the previous pre-execution results, it can be determined that the verification has passed. In this way, on the one hand, the security of smart contract execution can be improved through logical verification to prevent a single smart contract node from doing evil. On the other hand, the smart contract node that performs logical verification does not need to obtain the data status again, reducing the number of times the data storage node is accessed. On the other hand, the contract verification and data verification in the transaction process are decoupled and divided into two independent parts; the node device in the contract management system is only responsible for contract logic verification, and the node device in the data storage system is only responsible for data verification; the verification execution logic is simplified and the verification operation cycle is shortened.
[0057] The blockchain described in this specification may include private chains, public chains, and alliance chains, etc., which are not specifically limited in this specification. Node devices in the blockchain can be added without restriction, and each node device can synchronize a system time to ensure the timeliness of smart contract execution.
[0058] It should be noted that the transaction described in this specification refers to a piece of data created by a blockchain client and that needs to be ultimately published to the blockchain's data storage system.
[0059] Transactions in the blockchain are usually divided into narrow transactions and broad transactions. A transaction in the narrow sense refers to a value transfer published by a user to the blockchain; for example, in the traditional Bitcoin blockchain network, a transaction can be a transfer initiated by a user in the blockchain. A transaction in the broad sense refers to a business data with business intent published by a user to the blockchain; for example, an operator can build a consortium chain based on actual business needs, and rely on the consortium chain to deploy some other types of online services that are not related to value transfer (for example, broadly divided into query services, call services, etc.), and in this type of consortium chain, a transaction can be a business message or business request with business intent published by a user in the consortium chain.
[0060] The above-mentioned client may include any type of upper-layer application that uses the underlying business data stored in the blockchain as data support to implement specific business functions.
[0061] Pre-execution in this specification can refer to the process of running a smart contract without recording the results of the operation, which can be understood as a kind of logical execution. A complete execution process includes the execution of a smart contract and the recording of the execution results; but pre-execution is only the execution of a smart contract.
[0062] Please refer to Figure 1b , Figure 1b The schematic diagram of the blockchain system architecture provided for this specification is as follows:
[0063] The blockchain is divided into a contract management system 11 and a data storage system 12. The contract management system 11 stores smart contracts, and the data storage system 12 stores business data.
[0064] The contract management system 11 includes several smart contract node devices, and the data storage system 12 includes several data storage node devices.
[0065] The contract management system 11 and the data storage system 12 are connected via the SDK 13 to complete data interaction.
[0066] Specifically, the contract management system 11 can be an independent blockchain system, which is mainly responsible for the deployment (creation), upgrade (update) and operation of smart contracts. In addition, the contract management system 11 also needs to perform logic verification on the execution of smart contracts.
[0067] The data storage system 12 may be another independent blockchain system different from the contract management system 11, which is mainly responsible for storing the data status and changes corresponding to the smart contract. In addition, the data storage system 12 also needs to perform data verification on the data status changes.
[0068] Please refer to Figure 2 , Figure 2 This is a flowchart of a blockchain-based smart contract verification method provided in an embodiment of this specification. Figure 1b As shown, the blockchain can be divided into a contract management system and a data storage system.
[0069] 1. The user initiates a transaction to any data storage node in the data storage system; set as data storage node 1.
[0070] 2. Data storage node 1 broadcasts the transaction to any smart contract node in the contract management system; set as smart contract node 1.
[0071] Specifically, the data storage node 1 can broadcast the transaction to any smart contract node in the contract management system by connecting to the SDK.
[0072] 3. After smart contract node 1 pre-executes the smart contract, it returns the signed result set.
[0073] After receiving the transaction broadcast by data storage node 1, smart contract node 1 responds to the transaction by pre-running the target smart contract corresponding to the transaction, and packages the read-write set and other information generated during the pre-execution of the target smart contract into a result set, and then signs the result set to endorse the result set. Similarly, smart contract node 1 also returns the signed result set to data storage node 1 through the connection SDK.
[0074] 4. Data storage node 1 sends the result set returned by smart contract node 1 to other smart contract nodes.
[0075] After receiving the result set returned by smart contract node 1, data storage node 1 can also send the result set to other smart contract nodes except smart contract node 1 through the connection SDK.
[0076] 5. Other smart contract nodes perform logical verification on the result set; if the verification passes, they add their own signature to the result set and return it to data storage node 1.
[0077] The logic verification includes: simulating the execution of the smart contract to obtain a simulated read-write set; judging whether the simulated read-write set is consistent with the read-write set in the result set. If they are consistent, the verification passes; if they are inconsistent, the verification fails.
[0078] 6. Data storage node 1 performs validity verification on the result set returned by the other smart contract nodes.
[0079] The validity check here may refer to the verification of the signature of the result set. If the signatures of all other smart contract nodes are included, the validity check can be considered to have passed.
[0080] 7. After the validity check is passed, data storage node 1 sends the transaction to other data storage nodes for consensus.
[0081] After verifying that the result set is valid, the data state change results can be extracted from the read-write set and sent to other data storage nodes for consensus.
[0082] 8. The data storage section performs data verification on data status changes; if the verification passes, the corresponding data status is modified and the transaction is set as a valid transaction.
[0083] The consensus mechanism here mainly verifies the data status change; if the data status change is consistent with the locally stored data status, it means that the verification is passed. Therefore, the corresponding data status is modified and the transaction is set as a valid transaction.
[0084] 9. After the consensus is passed, data storage node 1 returns a prompt message.
[0085] After the consensus is passed, data storage node 1 can return prompt information to the user, such as the execution result or the occurrence of a block event. In this way, a complete transaction process ends.
[0086] The following combination Figure 3 The example shown introduces a flowchart of smart contract node 1 obtaining data status from data storage node 1.
[0087] 1. Data storage node 1 sends a transaction to smart contract node 1 by connecting to SDK.
[0088] The transaction carries execution parameters, which may specifically include contract parameters and business parameters.
[0089] The contract parameters can be used to locate the target smart contract. The contract parameters may include contract identifier, calling function name, contract version number, input parameters, transaction ID, timestamp and other information.
[0090] 2. Smart contract node 1 responds to the transaction and executes the smart contract corresponding to the transaction; during the execution of the smart contract, it obtains the data status from data storage node 1.
[0091] Smart contract node 1 can determine the calling function interface method based on the contract identifier, calling function name and other information in the contract parameters.
[0092] The business parameters can be used to locate the data state required to execute the contract logic.
[0093] The following example illustrates the difference between business parameters and data status:
[0094] Assume that the transaction sent by the client is, let a+1. Then the field a plus 1 is the business parameter, and the current value of a is the data state. When actually calculating a+1, you first need to obtain the original value of a (business data), and then add 1 to the original value to get the execution result.
[0095] like Figure 3 As shown, the smart contract node 1 can generate a read / write set (r / w set) during the execution of the contract logic. The read / write set can include a contract identifier, a state read, and a state write.
[0096] The contract identifier here is used to indicate which smart contract the read-write set corresponds to. The state reading here refers to the data state read by smart contract node 1 by accessing data storage node 1 through the SDK connection. The state writing here refers to the changed data state calculated based on the read data state.
[0097] Usually, for complex smart contracts, there are multiple sets of state reads and state writes; that is, the read-write set can be a data set consisting of all state reads and state writes during the execution of the smart contract. The read-write set can truly reflect the entire execution and calculation process of the smart contract.
[0098] 3. After smart contract node 1 executes the smart contract, the execution result can be returned to data storage node 1.
[0099] The execution result here can be a result set that packages the contract parameters and read-write sets, and the result set is signed and endorsed.
[0100] In addition to being applied to the above Figure 1b In addition to the blockchain system shown in the figure, it can also be applied in traditional blockchain systems, such as Figure 4 As shown:
[0101] 1. The blockchain system sends transactions initiated by users to any node device.
[0102] 2. The node device pre-executes the smart contract corresponding to the transaction and returns the result set (including read-write set, return value, signature and other information). Figure 5a As shown:
[0103] 2.1. Transactions carry execution parameters.
[0104] 2.2.SDK passes the parameters to the node device.
[0105] 2.3. The node device executes the contract logic, obtains or modifies data from the data storage, and generates a read-write set.
[0106] 2.4. The contract is executed successfully, the signature record is generated, and the result set is returned.
[0107] 3. Send the result set to other node devices so that other node devices can perform logic verification.
[0108] The smart contract is simulated and executed according to the data in the read-write set to obtain the simulated read-write set generated during the simulated execution; if the simulated read-write set is consistent with the read-write set in the result set, the verification passes; otherwise, if they are inconsistent, the verification fails. The specific process is as follows: Figure 5b As shown:
[0109] 3.1.SDK transfers the result set to other node devices.
[0110] 3.2. Other node devices execute the contract logic, obtain data from the read-write set or modify data and perform logical verification.
[0111] 3.3.Logical verification passed, signature recorded.
[0112] 4. If the verification passes, the correct signature information is returned.
[0113] 5. Collect result set and signature information.
[0114] In this embodiment, when other node devices perform simulation execution through the result set, these node devices do not need to access the corresponding world state again, but directly obtain the required data state from the result set. Because the execution results of each node device for the same transaction are consistent, the data state accessed during the process is also consistent, so as long as the logic is correct, the correct result can be obtained through the read-write set.
[0115] The following combination Figure 6 This specification introduces a method embodiment in which a data storage node in a data storage system is used as an execution subject. This embodiment can be applied to Figure 1b The system shown here corresponds to Figure 2 The method embodiment shown includes:
[0116] Step 210: The data storage node receives the target transaction initiated by the client;
[0117] Step 220: Broadcast the target transaction to any smart contract node.
[0118] Step 230: Receive the pre-execution result returned by the smart contract node after pre-executing the target smart contract corresponding to the target transaction.
[0119] Step 240: Send the pre-execution result to other smart contract nodes so that other smart contract nodes simulate the execution of the target smart contract.
[0120] Step 250: When the simulation execution result returned by the other node is consistent with the pre-execution result, it is determined that the pre-execution result verification has passed.
[0121] In one embodiment, the smart contract node is located in a contract management system, and the contract management system is a blockchain system that stores smart contracts;
[0122] The data storage node is located in a data storage system, and the data storage system is a blockchain system that stores data status.
[0123] In one embodiment, the pre-execution result is a result set formed by packaging the read-write sets generated by the smart contract node in the process of pre-executing the target smart contract; the simulated execution result is a result set formed by packaging the read-write sets generated by the other smart contract nodes in the process of simulating the execution of the target smart contract; the result set carries the signature of each node device;
[0124] The method further comprises:
[0125] When the simulation execution result is consistent with the pre-execution result, the pre-execution result is sent to other node devices in the data storage system for consensus.
[0126] In one embodiment, the consensus is mainly to verify the data status change of the read-write set; if the data status change is consistent with the data status stored locally, it means that the verification is passed. Thus, the corresponding data status is modified and the transaction is set as a valid transaction.
[0127] In one embodiment, after consensus is passed, the data storage node may also return prompt information to the client, such as execution results or block events.
[0128] The following combination Figure 7 This specification introduces a method embodiment in which the smart contract node in the contract management system is used as the execution subject. This embodiment can be applied to Figure 1b The system shown here corresponds to Figure 2 The method embodiment shown includes:
[0129] Step 310: The smart contract node receives the pre-execution result sent by the data storage node; wherein the pre-execution result is the result obtained by other smart contract nodes responding to the target transaction initiated by the client and pre-executing the target smart contract corresponding to the target transaction;
[0130] Step 320: Simulate the execution of the target smart contract according to the pre-execution result, and return the simulated pre-execution result obtained after the simulated execution of the target smart contract to the data storage node; for verification by the data storage node.
[0131] In one embodiment, the other smart contract nodes respond to the target transaction and pre-execute the target smart contract corresponding to the target transaction, specifically including:
[0132] According to the contract parameters carried in the target transaction, obtain the target smart contract corresponding to the contract parameters;
[0133] Pre-execute the contract logic of the target smart contract.
[0134] In this embodiment, the target transaction may carry contract parameters for locating the smart contract required to execute the target transaction.
[0135] The contract parameters may include contract identifier, calling function name, contract version number, input parameters, transaction ID, timestamp and other information.
[0136] Based on the contract identifier in the contract parameters, obtaining the smart contract address corresponding to the contract identifier from the contract management system;
[0137] According to the calling function name, determine the calling function interface method under the smart contract address.
[0138] However, generally, a smart contract may provide multiple function interface methods to the outside world. Each function interface method corresponds to a specific business logic. Therefore, after determining the smart contract address according to the contract identifier, it is also necessary to determine the calling function interface method under the smart contract address according to the calling function name.
[0139] In one embodiment, the other smart contract nodes respond to the target transaction initiated by the client and pre-execute the target smart contract corresponding to the target transaction, and the result obtained specifically includes:
[0140] Other smart contract nodes respond to the target transaction initiated by the client. If the target smart contract corresponding to the target transaction needs data status, the data status is obtained from the data storage device according to the transaction parameters carried in the target transaction.
[0141] Combined with the above Figure 3 In actual applications, some transactions do not require the input of data status, and for such transactions, it is not necessary to obtain data status from the data storage system. However, for some complex transactions, data status is required; therefore, the target transaction needs to provide the business parameters corresponding to these data statuses.
[0142] The following example illustrates the difference between business parameters and data status:
[0143] Assume that the transaction sent by the client is, let a+1. Then the field a plus 1 is the business parameter, and the current value of a is the data state. When actually calculating a+1, you first need to obtain the original value of a (business data), and then add 1 to the original value to get the execution result.
[0144] It should be noted that read-write sets are also generated during the execution of the business logic of smart contracts. The read-write set may include the input data (including data status) required for the pre-execution of the smart contract and the output data corresponding to the input data. For complex smart contracts, the input data and output data may contain multiple groups, that is, the read-write set is a data set consisting of all the input data and corresponding output data required during the execution of the smart contract, which can truly reflect the entire execution and calculation process of the smart contract.
[0145] It is worth mentioning that when the smart contract node sends the execution result obtained after pre-executing the target smart contract to the data storage system, it is necessary to add the signature of the node device to the execution result to endorse the execution result.
[0146] In one embodiment, the pre-execution result is a result set packaged from the read-write sets generated by the smart contract node in the process of pre-executing the target smart contract; the simulated execution result is a result set packaged from the read-write sets generated by the other smart contract nodes in the process of simulating the execution of the target smart contract; the result set carries the signature of each node device.
[0147] It is worth mentioning that the node device performing logic verification does not need to obtain the data status required to execute the target transaction from the data storage system again, so that the target smart contract can be simulated and run based on the read-write centralized data.
[0148] It is worth mentioning that as long as the smart contract logic runs successfully, the node device in the contract management system will make a record on its own node device. Based on the principle that the node device only performs logical verification, the record is a unique value consisting of the transaction id + result set hash. Each transaction record is collected and packaged into a block within a certain time range. The block has a packaged timestamp. There is no order for each record, but it is clear that certain transactions have been executed and completed within this time period.
[0149] In one embodiment, the data storage node performs verification, specifically including:
[0150] The data storage node compares the pre-execution result with the simulated pre-execution result;
[0151] If the pre-execution result is consistent with the simulated pre-execution result, it is determined that the verification is passed.
[0152] In one embodiment, the smart contract node is located in a contract management system, and the contract management system is a blockchain system that stores smart contracts;
[0153] The data storage node is located in a data storage system, and the data storage system is a blockchain system that stores data status.
[0154] In one embodiment, simulating and executing the target smart contract according to the pre-execution result, and returning the simulated pre-execution result obtained after simulating and executing the target smart contract to the data storage node specifically includes:
[0155] Simulate and execute the target smart contract based on the read-write centralized data of the pre-execution result;
[0156] The simulation result set of the simulated execution target smart contract is returned to the data storage node.
[0157] By using a smart contract node to pre-execute the target smart contract and generate a read-write set, other smart contract nodes do not need to access the data storage node again, and can use the read-write set to simulate the execution of the target smart contract; if the simulated execution results returned by the other smart contract nodes are consistent with the previous pre-execution results, it can be determined that the verification has passed. In this way, on the one hand, the security of smart contract execution can be improved through logical verification. On the other hand, the smart contract node that performs logical verification does not need to obtain the data status again, reducing the number of times the data storage node is accessed. On the other hand, the contract verification and data verification in the transaction process are decoupled and divided into two independent parts; the node device in the contract management system is only responsible for the contract logic verification, and the node device in the data storage system is only responsible for the data verification; the verification execution logic is simplified and the verification operation cycle is shortened.
[0158] Corresponding to the above-mentioned smart contract verification method embodiment, this specification also provides an embodiment of a smart contract verification device. The device embodiment can be implemented by software, or by hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by the processor of the device in which it is located reading the corresponding computer business program instructions in the non-volatile memory into the memory for execution. From the hardware level, if Figure 8 The following is a hardware structure diagram of the device where the smart contract verification device of this manual is located, except Figure 8 In addition to the processor, network interface, memory, and non-volatile memory shown, the device in the embodiment where the apparatus is located generally verifies the actual function according to the smart contract and may also include other hardware, which will not be described in detail.
[0159] See also Fig. 9 , is a module diagram of a smart contract verification device provided in an embodiment of this specification, and the device corresponds to Figure 6 In the embodiment shown, the device comprises:
[0160] A first receiving unit 410, a data storage node receives a target transaction initiated by a client;
[0161] A broadcast unit 420 broadcasts the target transaction to any smart contract node;
[0162] The second receiving unit 430 receives a pre-execution result returned by the smart contract node after pre-executing the target smart contract corresponding to the target transaction;
[0163] The sending unit 440 sends the pre-execution result to other smart contract nodes so that the other smart contract nodes simulate and execute the target smart contract;
[0164] The verification unit 450 determines that the pre-execution result verification passes when the simulation execution result returned by the other node is consistent with the pre-execution result.
[0165] Optionally, also include:
[0166] The consensus unit sends the pre-execution result to other node devices in the data storage system for consensus.
[0167] Optionally, the pre-execution result is a result set packaged from the read-write sets generated during the pre-execution of the target smart contract by the smart contract node; the simulated execution result is a result set packaged from the read-write sets generated during the simulated execution of the target smart contract by other smart contract nodes; the result set carries the signatures of each node device.
[0168] Optionally, the smart contract node is located in a contract management system, and the contract management system is a blockchain system that stores smart contracts;
[0169] The data storage node is located in a data storage system, and the data storage system is a blockchain system that stores data status.
[0170] See also Fig.10 , is a module diagram of a smart contract verification device provided in an embodiment of this specification, and the device corresponds to Figure 7 In the embodiment shown, the device comprises:
[0171] Receiving unit 510, the smart contract node receives the pre-execution result sent by the data storage node; wherein the pre-execution result is the result obtained after other smart contract nodes respond to the target transaction initiated by the client and pre-execute the target smart contract corresponding to the target transaction;
[0172] The execution unit 520 simulates the execution of the target smart contract according to the pre-execution result, and returns the simulated pre-execution result obtained after the simulated execution of the target smart contract to the data storage node; for verification by the data storage node.
[0173] Optionally, the data storage node performs verification, specifically including:
[0174] The data storage node compares the pre-execution result with the simulated pre-execution result;
[0175] If the pre-execution result is consistent with the simulated pre-execution result, it is determined that the verification is passed.
[0176] Optionally, the pre-execution result is a result set packaged from the read-write sets generated during the pre-execution of the target smart contract by the smart contract node; the simulated execution result is a result set packaged from the read-write sets generated during the simulated execution of the target smart contract by other smart contract nodes; the result set carries the signatures of each node device.
[0177] Optionally, simulating and executing the target smart contract according to the pre-execution result, and returning the simulated pre-execution result obtained after simulating and executing the target smart contract to the data storage node, specifically includes:
[0178] Simulate and execute the target smart contract based on the read-write centralized data of the pre-execution result;
[0179] The simulation result set of the simulated execution target smart contract is returned to the data storage node.
[0180] Optionally, the other smart contract nodes respond to the target transaction initiated by the client and pre-execute the target smart contract corresponding to the target transaction, and the result obtained specifically includes:
[0181] Other smart contract nodes respond to the target transaction initiated by the client. If the target smart contract corresponding to the target transaction needs data status, the data status is obtained from the data storage device according to the transaction parameters carried in the target transaction.
[0182] Optionally, the smart contract node is located in a contract management system, and the contract management system is a blockchain system that stores smart contracts;
[0183] The data storage node is located in a data storage system, and the data storage system is a blockchain system that stores data status.
[0184] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.
[0185] The implementation process of the functions and effects of each unit in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.
[0186] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can refer to the partial description of the method embodiments. The device embodiments described above are only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this specification. Ordinary technicians in this field can understand and implement it without paying creative work.
[0187] above Fig. 9 The internal functional modules and structural schematic diagram of the execution device of the smart contract in the blockchain are described. Its actual execution subject can be an electronic device, including:
[0188] processor;
[0189] a memory for storing processor-executable instructions;
[0190] Wherein, the processor is configured to:
[0191] The data storage node receives the target transaction initiated by the client;
[0192] Broadcast the target transaction to any smart contract node;
[0193] Receiving a pre-execution result returned by the smart contract node after pre-executing the target smart contract corresponding to the target transaction;
[0194] Send the pre-execution result to other smart contract nodes so that other smart contract nodes simulate and execute the target smart contract;
[0195] When the simulation execution result returned by the other node is consistent with the pre-execution result, it is determined that the pre-execution result verification has passed.
[0196] above Fig.10 The internal functional modules and structural schematic diagram of the verification device of the smart contract in the blockchain are described. Its actual execution subject can be an electronic device, including:
[0197] processor;
[0198] a memory for storing processor-executable instructions;
[0199] Wherein, the processor is configured to:
[0200] The smart contract node receives the pre-execution result sent by the data storage node; wherein the pre-execution result is the result obtained by other smart contract nodes responding to the target transaction initiated by the client and pre-executing the target smart contract corresponding to the target transaction;
[0201] The target smart contract is simulated and executed according to the pre-execution result, and the simulated pre-execution result obtained after the simulated execution of the target smart contract is returned to the data storage node; for verification by the data storage node.
[0202] In the above-mentioned embodiment of the electronic device, it should be understood that the processor can be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. The general-purpose processor can be a microprocessor or the processor can be any conventional processor, etc., and the aforementioned memory can be a read-only memory (ROM), a random access memory (RAM), a flash memory, a hard disk, or a solid-state drive. The steps of the method disclosed in the embodiment of the present invention can be directly embodied as being executed by a hardware processor, or executed by a combination of hardware and software modules in the processor.
[0203] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the electronic device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0204] Those skilled in the art will readily appreciate other embodiments of the specification after considering the specification and practicing the invention disclosed herein. The specification is intended to cover any variations, uses, or adaptations of the specification that follow the general principles of the specification and include common knowledge or customary techniques in the art that are not disclosed in the specification. The specification and examples are to be considered exemplary only, and the true scope and spirit of the specification are indicated by the following claims.
[0205] It should be understood that the present description is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present description is limited only by the appended claims.
Claims
1. A smart contract verification method, the method comprising: The first data storage node in the blockchain broadcasts the target transaction to the first smart contract node in the blockchain; The first smart contract node responds to the target transaction, pre-executes the target smart contract corresponding to the target transaction, and returns the pre-execution result to the first data storage node; wherein the pre-execution is the process of executing the target smart contract without recording the execution result, and the pre-execution result includes the read-write set generated by the pre-execution of the target smart contract; The first data storage node sends the pre-execution result to the second smart contract node in the blockchain; The second smart contract node simulates and executes the target smart contract according to the read-write set of the pre-execution result, and returns the simulated pre-execution result obtained after the simulated execution of the target smart contract to the first data storage node; When the first data storage node determines that the simulation pre-execution result is consistent with the pre-execution result, it determines that the pre-execution result verification passes.
2. The method according to claim 1, further comprising: The first data storage node sends the pre-execution result to a second data storage node in the blockchain for consensus.
3. According to the method described in claim 1, the pre-execution result is a result set formed by packaging the read-write sets generated by the first smart contract node during the pre-execution of the target smart contract; the simulated pre-execution result is a result set formed by packaging the read-write sets generated by the second smart contract node during the simulated execution of the target smart contract.
4. The method according to claim 3, wherein the second smart contract node simulates and executes the target smart contract according to the read-write set of the pre-execution result, and returns the simulated pre-execution result obtained after the simulated execution of the target smart contract to the first data storage node, comprising: The second smart contract node simulates and executes the target smart contract according to the read-write centralized data of the pre-execution result; The simulation result set of the simulated execution target smart contract is returned to the first data storage node.
5. According to the method described in claim 1, the first data storage node and the first smart contract node, and the first data storage node and the second smart contract node interact with each other through a connection SDK.
6. According to the method of claim 5, during the pre-execution of the target smart contract, the required status data is read from the first data storage node by connecting to the SDK.
7. A smart contract verification method, the method comprising: The first data storage node in the blockchain broadcasts the target transaction to the first smart contract node in the blockchain; Receive a pre-execution result returned by the first smart contract node after pre-executing the target smart contract corresponding to the target transaction; wherein the pre-execution is a process of executing the target smart contract without recording the execution result, and the pre-execution result includes a read-write set generated by pre-executing the target smart contract; Sending the pre-execution result to a second smart contract node in the blockchain, so that the second smart contract node simulates and executes the target smart contract according to the read-write set of the pre-execution result to obtain a simulated pre-execution result; When the simulated pre-execution result returned by the second smart contract node is consistent with the pre-execution result, it is determined that the pre-execution result verification has passed.
8. The method according to claim 7, further comprising: The pre-execution result is sent to a second data storage node in the blockchain for consensus.
9. According to the method described in claim 7, the pre-execution result is a result set formed by packaging the read-write sets generated by the first smart contract node in the process of pre-executing the target smart contract; the simulated pre-execution result is a result set formed by packaging the read-write sets generated by the second smart contract node in the process of simulating the execution of the target smart contract.
10. According to the method of claim 7, the first data storage node and the first smart contract node, and the first data storage node and the second smart contract node interact with each other through a connection SDK.
11. According to the method of claim 7, during the pre-execution of the target smart contract, the required status data is read from the first data storage node by connecting to the SDK.
12. A smart contract verification method, the method comprising: A first smart contract node in the blockchain receives a target transaction broadcasted by a first data storage node in the blockchain; After pre-executing the target smart contract corresponding to the target transaction, a pre-execution result is returned; wherein the pre-execution is the process of executing the target smart contract without recording the execution result, and the pre-execution result includes a read-write set generated by pre-executing the target smart contract, and the pre-execution result is used for the second smart contract node in the blockchain to simulate the execution of the target smart contract according to the read-write set of the pre-execution result to obtain a simulated pre-execution result, and when the simulated pre-execution result is consistent with the pre-execution result, it is determined that the pre-execution result verification has passed.
13. According to the method described in claim 12, the pre-execution result is a result set formed by packaging the read-write sets generated by the first smart contract node during the pre-execution of the target smart contract; the simulated pre-execution result is a result set formed by packaging the read-write sets generated by the second smart contract node during the simulated execution of the target smart contract.
14. According to the method of claim 12, the first smart contract node and the first data storage node interact with each other through connecting SDK.
15. According to the method of claim 14, during the pre-execution of the target smart contract, the required status data is read from the first data storage node by connecting to the SDK.
16. A smart contract verification method, the method comprising: The second smart contract node in the blockchain receives the pre-execution result sent by the first data storage node in the blockchain; wherein the pre-execution result is a read-write set generated by the first smart contract node in the blockchain pre-executing the target transaction corresponding to the target smart contract, and the pre-execution is the process of executing the target smart contract without recording the execution result; The target smart contract is simulated and executed according to the read-write set of the pre-execution result, and the simulated pre-execution result obtained after the simulated execution of the target smart contract is returned to the first data storage node.
17. According to the method described in claim 16, the pre-execution result is a result set formed by packaging the read-write sets generated by the first smart contract node during the pre-execution of the target smart contract; the simulated pre-execution result is a result set formed by packaging the read-write sets generated by the second smart contract node during the simulated execution of the target smart contract.
18. The method according to claim 16, wherein the simulating execution of the target smart contract according to the pre-execution result and returning the simulated pre-execution result obtained after the simulated execution of the target smart contract to the data storage node specifically comprises: Simulate and execute the target smart contract based on the read-write centralized data of the pre-execution result; The simulation result set of the simulated execution target smart contract is returned to the data storage node.
19. According to the method of claim 16, the second smart contract node and the first data storage node exchange data by connecting SDK.
20. A smart contract verification method, the method comprising: The blockchain SDK sends the transaction to the first node device in the blockchain; The first node device pre-executes the smart contract corresponding to the transaction and returns a pre-execution result; wherein the pre-execution is a process of executing the smart contract without recording the execution result, and the pre-execution result includes a read-write set generated by pre-executing the smart contract; The SDK sends the pre-execution result to a second node device in the blockchain; The second node device simulates and executes the smart contract according to the read-write set of the pre-execution result, and returns the simulated pre-execution result obtained after the simulated execution of the smart contract to the SDK; When the SDK determines that the simulation pre-execution result is consistent with the pre-execution result, it determines that the pre-execution result verification passes.
21. The method according to claim 20, further comprising: The SDK sends the pre-execution result to all nodes in the blockchain for consensus.
22. According to the method described in claim 20, the pre-execution result is a result set formed by packaging the read-write sets generated during the pre-execution of the smart contract by the first node device; the simulated pre-execution result is a result set formed by packaging the read-write sets generated during the simulated execution of the smart contract by the second node device.
23. The method according to claim 22, wherein the second node device simulates and executes the smart contract according to the pre-execution result, and returns the simulated pre-execution result obtained after the simulated execution of the smart contract to the SDK, comprising: The second node device simulates and executes the smart contract according to the read-write centralized data of the pre-execution result; The simulation result set of the simulated execution of the smart contract is returned to the SDK.
24. A smart contract verification method, the method comprising: The blockchain SDK sends the transaction to the first node device in the blockchain; Receiving a pre-execution result returned by the first node device after pre-executing the smart contract corresponding to the transaction; wherein the pre-execution is a process of executing the smart contract without recording the execution result, and the pre-execution result includes a read-write set generated by pre-executing the smart contract; Sending the pre-execution result to a second node device in the blockchain, so that the second node device simulates and executes the smart contract according to the read-write set of the pre-execution result to obtain a simulated pre-execution result; When the simulation pre-execution result returned by the second node device is consistent with the pre-execution result, it is determined that the pre-execution result verification passes.
25. The method according to claim 24, further comprising: The pre-execution result is sent to all nodes in the blockchain for consensus.
26. According to the method described in claim 24, the pre-execution result is a result set formed by packaging the read-write sets generated during the pre-execution of the smart contract by the first node device; the simulated pre-execution result is a result set formed by packaging the read-write sets generated during the simulated execution of the smart contract by the second node device.
27. A smart contract verification method, the method comprising: The first node device in the blockchain receives the transaction sent by the SDK of the blockchain; After pre-executing the smart contract corresponding to the transaction, a pre-execution result is returned; wherein the pre-execution is the process of executing the smart contract without recording the execution result, and the pre-execution result includes a read-write set generated by the pre-execution of the smart contract, and the pre-execution result is used for the second node device in the blockchain to simulate the execution of the smart contract according to the read-write set of the pre-execution result to obtain a simulated pre-execution result, and when the simulated pre-execution result is consistent with the pre-execution result, it is determined that the pre-execution result verification has passed.
28. According to the method described in claim 27, the pre-execution result is a result set formed by packaging the read-write sets generated during the pre-execution of the smart contract by the first node device; the simulated pre-execution result is a result set formed by packaging the read-write sets generated during the simulated execution of the smart contract by the second node device.
29. A smart contract verification method, the method comprising: The second node device in the blockchain receives the pre-execution result sent by the SDK of the blockchain; wherein the pre-execution result is a read-write set generated by the smart contract corresponding to the pre-execution transaction of the first node device in the blockchain, and the pre-execution is the process of executing the smart contract without recording the execution result; The smart contract is simulated and executed according to the read-write set of the pre-execution result, and the simulated pre-execution result obtained after the simulated execution of the smart contract is returned to the SDK.
30. According to the method described in claim 29, the pre-execution result is a result set formed by packaging the read-write sets generated during the pre-execution of the smart contract by the first node device; the simulated pre-execution result is a result set formed by packaging the read-write sets generated during the simulated execution of the smart contract by the second node device.
31. The method according to claim 30, wherein simulating the execution of the smart contract according to the pre-execution result and returning the simulated pre-execution result obtained after simulating the execution of the smart contract to the SDK specifically comprises: Simulate and execute the smart contract according to the read-write centralized data of the pre-execution result; The simulation result set of the simulated execution of the smart contract is returned to the SDK.
32. A smart contract verification device, the device comprising: A broadcasting unit, wherein the first data storage node in the blockchain broadcasts the target transaction to the first smart contract node in the blockchain; A receiving unit, receiving a pre-execution result returned by the first smart contract node after pre-executing the target smart contract corresponding to the target transaction; wherein the pre-execution is a process of executing the target smart contract without recording the execution result, and the pre-execution result includes a read-write set generated by pre-executing the target smart contract; A sending unit, sending the pre-execution result to a second smart contract node in the blockchain, so that the second smart contract node simulates and executes the target smart contract according to the read-write set of the pre-execution result to obtain a simulated pre-execution result; The verification unit determines that the pre-execution result verification passes when the simulated pre-execution result returned by the second smart contract node is consistent with the pre-execution result.
33. A smart contract verification device, the device comprising: A receiving unit, a first smart contract node in the blockchain receives a target transaction broadcasted by a first data storage node in the blockchain; A pre-execution unit, after pre-executing the target smart contract corresponding to the target transaction, returns a pre-execution result; wherein the pre-execution is a process of executing the target smart contract without recording the execution result, and the pre-execution result includes a read-write set generated by the pre-execution of the target smart contract; the pre-execution result is used for the second smart contract node in the blockchain to simulate the execution of the target smart contract according to the read-write set of the pre-execution result to obtain a simulated pre-execution result, and when the simulated pre-execution result is consistent with the pre-execution result, it is determined that the pre-execution result verification has passed.
34. A smart contract verification device, the device comprising: A receiving unit, wherein the second smart contract node in the blockchain receives a pre-execution result sent by the first data storage node in the blockchain; wherein the pre-execution result is a read-write set generated by the first smart contract node in the blockchain pre-executing the target transaction corresponding to the target smart contract, and the pre-execution is a process of executing the target smart contract without recording the execution result; The simulation execution unit simulates and executes the target smart contract according to the read-write set of the pre-execution result, and returns the simulation pre-execution result obtained after the simulation execution of the target smart contract to the first data storage node.
35. A smart contract verification device, the device comprising: A first sending unit, the blockchain SDK sends the transaction to a first node device in the blockchain; A receiving unit, receiving a pre-execution result returned by the first node device after pre-executing the smart contract corresponding to the transaction; wherein the pre-execution is a process of executing the smart contract without recording the execution result, and the pre-execution result includes a read-write set generated by pre-executing the smart contract; A second sending unit sends the pre-execution result to a second node device in the blockchain, so that the second node device simulates and executes the smart contract according to the read-write set of the pre-execution result to obtain a simulated pre-execution result; A verification unit is configured to determine that the pre-execution result verification passes when the simulation pre-execution result returned by the second node device is consistent with the pre-execution result.
36. A smart contract verification device, the device comprising: A receiving unit, a first node device in a blockchain receives a transaction sent by an SDK of the blockchain; A pre-execution unit, after pre-executing the smart contract corresponding to the transaction, returns a pre-execution result; wherein the pre-execution is the process of executing the smart contract without recording the execution result, the pre-execution result includes a read-write set generated by the pre-execution of the smart contract, and the pre-execution result is used for the second node device in the blockchain to simulate the execution of the smart contract according to the read-write set of the pre-execution result to obtain a simulated pre-execution result, and when the simulated pre-execution result is consistent with the pre-execution result, it is determined that the pre-execution result verification has passed.
37. A smart contract verification device, the device comprising: A receiving unit, wherein the second node device in the blockchain receives the pre-execution result sent by the SDK of the blockchain; wherein the pre-execution result is a read-write set generated by the smart contract corresponding to the pre-execution transaction of the first node device in the blockchain, and the pre-execution is a process of executing the smart contract without recording the execution result; The simulation execution unit simulates the execution of the smart contract according to the read-write set of the pre-execution result, and returns the simulation pre-execution result obtained after the simulation execution of the smart contract to the SDK.
38. An electronic device comprising: processor; a memory for storing processor-executable instructions; The processor is configured to execute the method described in any one of claims 1 to 31.
