Block chain contract detection method and device, equipment, medium and product
By detecting the write set classification results in the main node in the blockchain, it can identify inconsistent contracts in the blockchain, and solve the problem of inconsistent execution results of smart contracts, improve detection efficiency and accuracy, reduce costs, and ensure the blockchain System stability.
Patent Information
- Application Number
- CN202410994917.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-23
- Publication Date
- 2024-12-10
AI Technical Summary
In blockchain, the block execution results are inconsistent due to code problems during the execution of smart contracts, resulting in block execution failure, affecting the normal operation of the system. The existing manual inspection methods are inefficient and have low accuracy.
Through the master node, determine whether there are two contracts with different combinations of write sets in the classification results of each write set, accurately check the problem contract, improve detection accuracy and efficiency, and reduce costs.
Accurate detection of blockchain contracts is achieved, detection efficiency and accuracy are improved, detection costs are reduced, and the normal operation of the blockchain system is ensured.
Smart Images

Figure CN119105952A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of blockchain technology, and in particular to a blockchain contract detection method, device, equipment, medium and product. Background Art
[0002] With the continuous development of blockchain technology, the application scope of blockchain is becoming more and more extensive, such as finance, logistics and other fields. Smart contracts are an important part of blockchain technology. They can realize automatic execution of contracts, improve contract execution efficiency and reduce operating costs. However, in the process of smart contract execution, there may be inconsistent block execution results in each block of the blockchain due to problems with the smart contract code itself, resulting in block execution failure, block height cessation, and affecting the normal operation of the entire blockchain system. Therefore, it is necessary to check the above problematic contracts.
[0003] Currently, problem contracts are usually checked manually. However, manual inspection of problem contracts is limited by the experience of the inspectors, resulting in low accuracy in the inspection of problem contracts; even if each transaction in the blockchain is pre-executed, and then the execution results of each contract are manually checked to further detect problem contracts, due to the large number of nodes and transactions in the blockchain, manual inspection is still time-consuming and labor-intensive, which in turn reduces the efficiency of problem contract detection. Summary of the invention
[0004] The present invention aims to solve at least one of the technical problems existing in the prior art. To this end, the present invention proposes a blockchain contract detection method, in which the master node determines whether there are two write-set classification results with different write-set combinations in each write-set classification result, and the contract corresponding to the different write-set combination can be determined as a problem contract. Compared with manual inspection of the problem contract, the problem contract can be accurately inspected based on each write-set classification result, that is, the inspection accuracy of the problem contract is improved. At the same time, the master node detects the problem contract based on the above method, which can improve the detection efficiency of the problem contract and reduce the detection cost of the problem contract compared with manual inspection.
[0005] The present invention also proposes a detection device for a blockchain contract.
[0006] The invention also provides an electronic device.
[0007] The present invention also provides a non-transitory computer-readable storage medium.
[0008] The present invention also provides a computer program product.
[0009] A method for detecting a blockchain contract according to an embodiment of the first aspect of the present invention is applied to a master node in a blockchain, wherein the blockchain includes multiple nodes, and the method includes: Determine a target block of the problem contract to be determined in the blockchain; Obtaining a block execution result set corresponding to the target block; the block execution result set includes the block execution results respectively stored by the multiple nodes, any of the block execution results includes a write set of at least one transaction, and any of the write sets of the transaction is the write data involved in the execution of the transaction according to a contract; Classifying the execution results of each block according to the contract category to obtain write-set classification results corresponding to each block execution result; the write-set classification result corresponding to any of the block execution results includes a write-set combination corresponding to at least one contract, and the write-set combination corresponding to any of the contracts includes at least one write-set involved in the execution of the contract; It is determined that there are two write-set classification results in each of the write-set classification results whose write-set combinations are different, and contracts corresponding to the different write-set combinations are determined as problematic contracts.
[0010] According to the blockchain contract detection method of the embodiment of the present invention, the target block of the problem contract to be determined in the blockchain is determined, and the block execution result set corresponding to the target block is obtained, and the block execution result set includes the block execution results stored by multiple nodes respectively, and any block execution result includes at least one write set of a transaction, and the write set of any transaction is the write data involved in the execution of a transaction according to a contract, so as to classify each block execution result according to the contract category, and obtain the write set classification result corresponding to each block execution result, and the write set classification result corresponding to any block execution result includes at least one write set combination corresponding to the contract, and the write set combination corresponding to any contract includes at least one write set involved in the contract execution, so that the master node determines whether there are two write set classification results in each write set classification result. The write set combination is different, and the contract corresponding to the different write set combination can be determined as a problem contract. Compared with manual inspection of the problem contract, the problem contract can be accurately inspected based on each write set classification result, that is, the inspection accuracy of the problem contract is improved. At the same time, the master node detects the problem contract based on the above method, which can improve the detection efficiency of the problem contract and reduce the detection cost of the problem contract compared with manual inspection.
[0011] According to an embodiment of the present invention, the determining that there are two write-set classification results in each of the write-set classification results that have different write-set combinations, and determining the contracts corresponding to the different write-set combinations as problematic contracts, includes: Determining that there are two different write-set classification results among the write-set classification results, and one of the two write-set classification results includes the write-set combination corresponding to the target contract, and the other of the two write-set classification results does not include the write-set combination corresponding to the target contract, and determining the target contract as a problem contract; Alternatively, it is determined that there are two different write-set classification results among the write-set classification results, and both of the two write-set classification results include a write-set combination corresponding to the target contract, and the write-set combinations corresponding to the two target contracts included in the two write-set classification results are different, and the target contract is determined to be a problem contract.
[0012] According to one embodiment of the present invention, any of the write sets includes state data and contract identification data; The determining that there are two different write-set classification results among the write-set classification results, and both of the two write-set classification results include a write-set combination corresponding to the target contract, and the write-set combinations corresponding to the two target contracts included in the two write-set classification results are different, and determining the target contract as a problem contract includes: Determining that there are two different write-set classification results among the write-set classification results, and both of the two write-set classification results include a write-set combination corresponding to a target contract, and determining merged state data of the two write-set combinations corresponding to the target contract based on the two write-set combinations corresponding to the target contract included in the two write-set classification results; the merged state data of any of the write-set combinations is obtained by merging state data included in all write-sets in the write-set combination; Performing hash processing on the two merged state data respectively to obtain two hash state data; It is determined that the two hash state data are different, and the target contract is determined to be a problematic contract.
[0013] According to an embodiment of the present invention, obtaining a block execution result set corresponding to the target block includes: Based on the block height of the target block, obtaining the block execution result stored by the master node; Based on the block height of the target block, query the block execution result corresponding to the target block from other nodes among the multiple nodes except the master node, and receive the block execution results fed back by other nodes among the multiple nodes except the master node.
[0014] According to one embodiment of the present invention, any of the write sets includes state data and contract identification data; The block execution results are classified according to the contract category to obtain the write set classification results corresponding to the block execution results, including: The execution results of each block are classified according to the contract identification data to obtain the write set classification results corresponding to the execution results of each block.
[0015] According to one embodiment of the present invention, determining a target block of a problem contract to be determined in the blockchain includes: Obtaining block height information sets respectively stored by the multiple nodes; the block height information set stored by any of the nodes includes block height information of the multiple nodes, and the block height information of any of the nodes includes node identification data, block height, and update time of the block height information; Determining the unsynchronized blocks in the blockchain based on each of the block height information sets; Based on the unsynchronized blocks, a target block of the problem contract to be determined in the blockchain is determined.
[0016] According to an embodiment of the present invention, determining the unsynchronized blocks in the blockchain based on each of the block height information sets includes: Determine, from each of the block height information sets, a block height information set that is different from the block height information set stored by the master node; Based on a block height information set different from the block height information set stored by the master node and the block height information set stored by the master node, determining the unsynchronized blocks in the blockchain.
[0017] According to one embodiment of the present invention, determining the unsynchronized blocks in the blockchain based on a block height information set different from the block height information set stored by the master node and a block height information set stored by the master node includes: Determining first target block height information from a block height information set different from the block height information set stored by the master node, wherein the first target block height information is identical to the second target block height information in the block height information set stored by the master node in terms of node identification data and block height, and the first target block height information is different from the second target block height information in terms of update time; It is determined that the update time difference between the first target block height information and the second target block height information is greater than a preset time difference, and the block corresponding to the block height in the first target block height information is determined as an unsynchronized block in the blockchain.
[0018] According to an embodiment of the present invention, determining a target block of a problem contract to be determined in the blockchain based on the unsynchronized block includes: Determine that the number of the unsynchronized blocks is greater than or equal to a block number threshold, and determine the target block from the unsynchronized blocks; The block number threshold is the product of the total number of blocks in the blockchain and a preset ratio.
[0019] According to one embodiment of the present invention, the method further includes: Receive the target block height broadcast by the target node; Based on the node identification data of the target node, determining the block height information of the target node from the block height information set stored by the master node; Determine that the block height in the block height information of the target node is different from the target block height, update the block height in the block height information of the target node to the target block height, and update the update time in the block height information of the target node.
[0020] According to an embodiment of the present invention, after determining that there are two write-set classification results in each of the write-set classification results that have different write-set combinations, and determining the contracts corresponding to the different write-set combinations as problematic contracts, the method further includes: The transaction executed according to the problematic contract is set to a failed state, and the write set involved in the execution according to the problematic contract in the block execution result set is deleted.
[0021] According to an embodiment of the present invention, after determining that there are two write-set classification results in each of the write-set classification results that have different write-set combinations, and determining the contracts corresponding to the different write-set combinations as problematic contracts, the method further includes: Add the problematic contract to the contract blacklist stored by the master node; Synchronize the problematic contract to other nodes among the multiple nodes except the master node, so that the other nodes among the multiple nodes except the master node can add the problematic contract to the contract blacklist stored in themselves; Among them, transactions executed according to the contracts in the contract blacklist need to be set to a failed state.
[0022] According to the second aspect of the present invention, a detection device for a blockchain contract is deployed in a master node in a blockchain, wherein the blockchain includes a plurality of nodes, and the device includes: A block determination module, used to determine the target block of the problem contract to be determined in the blockchain; A result acquisition module, used to acquire a block execution result set corresponding to the target block; the block execution result set includes the block execution results respectively stored by the multiple nodes, any of the block execution results includes a write set of at least one transaction, and any write set of the transaction is the write data involved in the execution of the transaction according to a contract; A result classification module is used to classify each of the block execution results according to the contract category, and obtain the write set classification results corresponding to each of the block execution results; the write set classification results corresponding to any of the block execution results include at least one write set combination corresponding to a contract, and any write set combination corresponding to the contract includes at least one write set involved in the execution of the contract; The contract determination module is used to determine that there are two write-set classification results whose write-set combinations are different among the write-set classification results, and determine the contracts corresponding to the different write-set combinations as problematic contracts.
[0023] According to an embodiment of the third aspect of the present invention, an electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the processor executes the program, a blockchain contract detection method as described in any one of the above is implemented.
[0024] According to the non-transitory computer-readable storage medium of the fourth aspect embodiment of the present invention, a computer program is stored thereon, and when the computer program is executed by a processor, a blockchain contract detection method as described in any one of the above is implemented.
[0025] According to a computer program product of an embodiment of the fifth aspect of the present invention, it includes a computer program, which, when executed by a processor, implements a blockchain contract detection method as described in any one of the above.
[0026] The above one or more technical solutions in the embodiments of the present invention have at least one of the following technical effects: Determine a target block of a problem contract to be determined in a blockchain, obtain a block execution result set corresponding to the target block, and the block execution result set includes block execution results stored by multiple nodes respectively, any block execution result includes a write set of at least one transaction, and the write set of any transaction is the write data involved in the execution of a transaction according to a contract, so as to classify each block execution result according to the contract category, and obtain a write set classification result corresponding to each block execution result, and the write set classification result corresponding to any block execution result includes a write set combination corresponding to at least one contract, and the write set combination corresponding to any contract includes at least one write set involved in the execution of the contract, so that the master node determines whether there are two write set classification results in each write set classification result that have different write set combinations, and the contract corresponding to the different write set combinations can be determined as a problem contract. Compared with manual inspection of the problem contract, the problem contract can be accurately inspected based on each write set classification result, that is, the inspection accuracy of the problem contract is improved. At the same time, the master node detects the problem contract based on the above method, which can improve the detection efficiency of the problem contract and reduce the detection cost of the problem contract compared with manual inspection.
[0027] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0029] Figure 1 This is one of the flow charts of the blockchain contract detection method provided by an embodiment of the present invention.
[0030] Figure 2 This is the second flow chart of the blockchain contract detection method provided by the embodiment of the present invention.
[0031] Figure 3 It is a structural diagram of a blockchain contract detection device provided by an embodiment of the present invention.
[0032] Figure 4 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0033] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0034] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the embodiments of the present application. In addition, the terms "first", "second", and "third" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradicting each other.
[0035] With the continuous development of blockchain technology, the application scope of blockchain is becoming more and more extensive, such as finance, logistics and other fields. Smart contracts are an important part of blockchain technology. They can realize automatic execution of contracts, improve contract execution efficiency and reduce operating costs. However, in the process of smart contract execution, there may be inconsistent block execution results in the blockchain due to problems with the smart contract code itself, resulting in block execution failure, block height cessation and affecting the normal operation of the entire blockchain system. Therefore, it is necessary to check the above problematic contracts.
[0036] Currently, problem contracts are usually checked manually. However, manual inspection of problem contracts is limited by the experience of the inspectors, resulting in low accuracy in the inspection of problem contracts; even if each transaction in the blockchain is pre-executed, and then the execution results of each contract are manually checked to further detect problem contracts, due to the large number of nodes and transactions in the blockchain, manual inspection is still time-consuming and labor-intensive, which in turn reduces the efficiency of problem contract detection.
[0037] Based on the above problems, the present invention proposes the following embodiments. The following embodiments of the present invention are further described in detail in conjunction with the accompanying drawings and embodiments. The following embodiments are used to illustrate the present invention, but cannot be used to limit the scope of the present invention.
[0038] Figure 1 This is one of the flow charts of the detection method of the blockchain contract provided by the embodiment of the present invention, such as Figure 1 As shown, the detection method of the blockchain contract applied to the master node in the blockchain includes: steps 110 to 140.
[0039] Step 110, determining the target block of the problem contract to be determined in the blockchain.
[0040] Here, the blockchain includes multiple nodes, and the multiple nodes include a master node. The master node is used to execute the method provided by the present invention to separate the processing flow from the main block processing flow to avoid affecting the block processing performance.
[0041] Here, the target block is a block in the blockchain. It should be understood that the target block of the problem contract to be determined in the blockchain can be one or more.
[0042] In one embodiment, the target block is an unsynchronized block in the blockchain. It should be understood that the contract involved in the unsynchronized block may be problematic.
[0043] In one embodiment, the unsynchronized blocks in the blockchain are determined, and it is determined whether the number of unsynchronized blocks is greater than or equal to the block number threshold; it is determined that the number of unsynchronized blocks is greater than or equal to the block number threshold, and the target block is determined from the unsynchronized blocks; wherein the block number threshold is the product of the total number of blocks in the blockchain and a preset ratio, for example, the preset ratio is 0.5. Based on this, if the number of unsynchronized blocks is large, it indicates that the contract involved is likely to have a problem, and the problem contract is detected at this time, avoiding the possibility that there is no problem contract after the problem contract detection, thereby reducing data processing time, avoiding the occupation of computing resources, and improving data processing efficiency.
[0044] Step 120: Obtain a block execution result set corresponding to the target block.
[0045] The block execution result set includes the block execution results respectively stored by the multiple nodes, and any of the block execution results includes a write set of at least one transaction, and the write set of any of the transactions is the write data involved in the execution of the transaction according to a contract.
[0046] Here, the block execution result corresponding to the target block is stored in each node in the blockchain. The block execution result set includes the block execution result stored by the master node and the block execution result corresponding to the target block queried from other nodes except the master node among multiple nodes.
[0047] In one embodiment, any write set includes state data and contract identification data. The contract identification data is used to uniquely identify a contract, and the state data is the write state data involved in the execution of the contract identified by the contract identification data.
[0048] Step 130, classify the execution results of each block according to the contract category, and obtain the write set classification results corresponding to the execution results of each block.
[0049] Among them, the write-set classification result corresponding to any of the block execution results includes a write-set combination corresponding to at least one contract, and the write-set combination corresponding to any of the contracts includes at least one write-set involved in the execution of the contract.
[0050] It should be noted that since any block execution result includes at least one write set of a transaction, and the write set of any transaction is the write data involved in the execution of a transaction according to a contract, based on this, the write sets in the block execution results can be classified according to the contract category. All the write sets in a write set combination involve the same contracts.
[0051] Step 140: Determine that there are two write-set classification results in each of the write-set classification results whose write-set combinations are different, and determine the contracts corresponding to the different write-set combinations as problematic contracts.
[0052] Here, a problematic contract is a problematic contract, which refers to a contract that produces inconsistent results after being executed by various nodes in the blockchain; it may cause unsynchronized blocks in the blockchain, for example, a problematic contract is a contract with problems in its own code.
[0053] Specifically, it is determined that there are two different write-set classification results among the write-set classification results, different write-set combinations among the two write-set classification results are determined, and the contracts corresponding to the different write-set combinations are determined as problematic contracts.
[0054] Before the above step 140, it is detected whether there are two write-set classification results with different write-set combinations in each write-set classification result. In addition, it is determined that there are no two write-set classification results with different write-set combinations in each write-set classification result, that is, the write-set classification results are the same, indicating that there is no problem contract.
[0055] Since the write set combination corresponding to any contract includes at least one write set involved in the execution of the contract, that is, one write set combination corresponds to one contract, based on this, contracts corresponding to different write set combinations can be determined as problematic contracts. It should be understood that the different write set combinations can be one or more, and if there are multiple, there are also multiple problematic contracts.
[0056] The blockchain contract detection method provided by the embodiment of the present invention determines the target block of the problem contract to be determined in the blockchain, obtains the block execution result set corresponding to the target block, and the block execution result set includes the block execution results stored by multiple nodes respectively, any block execution result includes at least one write set of a transaction, and the write set of any transaction is the write data involved in the execution of a transaction according to a contract, so as to classify each block execution result according to the contract category, and obtain the write set classification result corresponding to each block execution result, and the write set classification result corresponding to any block execution result includes at least one write set combination corresponding to the contract, and the write set combination corresponding to any contract includes at least one write set involved in the contract execution, so that the master node determines whether there are two write set classification results in each write set classification result. The write set combination is different, and the contract corresponding to the different write set combination can be determined as a problem contract. Compared with manual inspection of the problem contract, the problem contract can be accurately inspected based on each write set classification result, that is, the inspection accuracy of the problem contract is improved. At the same time, the master node detects the problem contract based on the above method, which can improve the detection efficiency of the problem contract and reduce the detection cost of the problem contract compared with manual inspection.
[0057] Based on any of the above embodiments, in the method, the above step 140 includes: Determining that there are two different write-set classification results among the write-set classification results, and one of the two write-set classification results includes the write-set combination corresponding to the target contract, and the other of the two write-set classification results does not include the write-set combination corresponding to the target contract, and determining the target contract as a problem contract; Alternatively, it is determined that there are two different write-set classification results among the write-set classification results, and both of the two write-set classification results include a write-set combination corresponding to the target contract, and the write-set combinations corresponding to the two target contracts included in the two write-set classification results are different, and the target contract is determined to be a problem contract.
[0058] For ease of understanding, it is assumed that the blockchain includes 3 nodes, that is, a total of 3 write-set classification results, for example, write-set classification result A, write-set classification result B, and write-set classification result C. Based on this, there can be at most 3 situations in which two write-set classification results are different in each write-set classification result, that is, write-set classification result A and write-set classification result B are different, write-set classification result A and write-set classification result C are different, and write-set classification result B and write-set classification result C are different. Therefore, the embodiment of the present invention mainly describes the method of determining the problem contract for one situation in which two write-set classification results are different.
[0059] It should be understood that one of the two write-set classification results includes the write-set combination corresponding to the target contract, and the other of the two write-set classification results does not include the write-set combination corresponding to the target contract, indicating that there are different write-set combinations in the two write-set classification results, that is, one has the write-set combination corresponding to the target contract and the other does not, and the different write-set combination is the write-set combination corresponding to the target contract, and the target contract can be determined as a problem contract.
[0060] It should be understood that both write-set classification results include the write-set combination corresponding to the target contract, and that the write-set combinations corresponding to the two target contracts included in the two write-set classification results are different, indicating that the two write-set classification results have different write-set combinations, that is, both have write-set combinations corresponding to the target contract but the two write-set combinations are different, and thus the target contract can be determined as a problematic contract.
[0061] In addition, after determining that two write-set classification results are different among the write-set classification results, one or more problematic contracts may be determined.
[0062] For ease of understanding, assume that two different write-set classification results are write-set classification result H and write-set classification result I. For example, write-set classification result H includes write-set combination A1 corresponding to contract C1, write-set combination A2 corresponding to contract C2, and write-set combination A3 corresponding to contract C3. Write-set classification result I includes write-set combination A4 corresponding to contract C1 and write-set combination A5 corresponding to contract C2. Write-set combination A1 includes write-set a1 and write-set a2, write-set combination A2 includes write-set a3 and write-set a4, and write-set combination A3 includes write-set A4 and write-set A5. Including write set a5, write set combination A4 includes write set a5 and write set a2, and write set combination A5 includes write set a3 and write set a4; based on this, since the write set classification result H includes the write set combination A3 corresponding to contract C3, and the write set classification result I does not include the write set combination corresponding to contract C3, contract C3 is a problematic contract; since the write set combination A1 corresponding to contract C1 includes write set a1 and write set a2, and the write set combination A4 corresponding to contract C1 includes write set a5 and write set a2, contract C1 is a problematic contract.
[0063] Furthermore, any write set includes state data and contract identification data. The state data can be represented by a key-value pair, and the contract identification data can be represented by a string. Based on this, assume that two different write set classification results are write set classification result H and write set classification result I. For example, write set classification result H includes write set combination A1 corresponding to contract C1, write set combination A2 corresponding to contract C2, and write set combination A3 corresponding to contract C3. Write set classification result I includes write set combination A4 corresponding to contract C1 and write set combination A5 corresponding to contract C2. Write set combination A1 includes write set a1 and write set a2, write set combination A2 includes write set a3 and write set a4, write set combination A3 includes write set a5, write set combination A4 includes write set a6 and write set a2, write set combination A5 includes write set a3 and write set a4. The state data of write set a1 is k1:v1 (key-value pair), write set combination A1 includes write set a2 and write set a3, write set combination A4 includes write set a3 and write set a4, and the state data of write set a1 is k1:v1 (key-value pair). The state data of write set a2 is k2:v2, the state data of write set a3 is k3:v3, the state data of write set a4 is k4:v4, the state data of write set a5 is k5:v5, and the state data of write set a6 is k1:v11; based on this, since the write set classification result H includes the write set combination A3 corresponding to contract C3, and the write set classification result I does not include the write set combination corresponding to contract C3, contract C3 is a problematic contract; since the write set combination A1 corresponding to contract C1 includes write set a1 and write set a2, the write set combination A4 corresponding to contract C1 includes write set a6 and write set a2, and the value V1 in write set a1 is different from the value V11 in write set a6, contract C1 is a problematic contract.
[0064] The blockchain contract detection method provided by the embodiment of the present invention can accurately determine the problematic contracts through the above method, thereby improving the detection accuracy of the problematic contracts.
[0065] Based on any of the above embodiments, in the method, any of the write sets includes state data and contract identification data. The contract identification data is used to uniquely identify a contract, and the state data is the write state data involved in the execution of the contract identified by the contract identification data.
[0066] In one embodiment, the state data is represented by a key-value pair, that is, the structure of the state data is key: value. Furthermore, the type of key can be a byte array, that is, the key to be written; the type of value is a byte array, that is, the value to be written.
[0067] In one embodiment, the contract identification data may be represented by a character string. Further, the contract identification data is the name of the contract.
[0068] Accordingly, the determining that there are two different write-set classification results among the write-set classification results, and both of the two write-set classification results include a write-set combination corresponding to the target contract, and the write-set combinations corresponding to the two target contracts included in the two write-set classification results are different, and determining the target contract as a problem contract includes: Determining that there are two different write-set classification results among the write-set classification results, and both of the two write-set classification results include a write-set combination corresponding to a target contract, and determining merged state data of the two write-set combinations corresponding to the target contract based on the two write-set combinations corresponding to the target contract included in the two write-set classification results; the merged state data of any of the write-set combinations is obtained by merging state data included in all write-sets in the write-set combination; Performing hash processing on the two merged state data respectively to obtain two hash state data; It is determined that the two hash state data are different, and the target contract is determined to be a problematic contract.
[0069] Here, the merged state data of any write-set combination is obtained by merging the state data included in all write-sets in the write-set combination, so that only hash processing needs to be performed on the state data later, thereby improving the comparison efficiency of the two write-set combinations, that is, improving the detection efficiency of problematic contracts.
[0070] In a specific embodiment, if the state data is represented by a key-value pair, and the structure of the state data is key:value, the key type can be a byte array, and the value type is a byte array, then the state data (key-value pairs) included in all write sets in the write set combination are merged into the merged state data of the write set combination in alphabetical order. For example, the write set combination includes write set a1 and write set a2, and the state data of write set a1 is k1:v1, and the state data of write set a2 is k2:v2, then k1, v1, k2, and v2 are merged into one merged state data in alphabetical order.
[0071] In the blockchain contract detection method provided by the embodiment of the present invention, the merged state data of any write-set combination is obtained by merging the state data included in all write-sets in the write-set combination, so that only hash processing needs to be performed on the state data subsequently, thereby improving the comparison efficiency of the two write-set combinations, that is, improving the detection efficiency of the problem contract; at the same time, the two merged state data are hashed respectively to obtain two hash state data, so that it is only necessary to compare the two hash state data to determine whether the two write-set combinations are the same, thereby improving the comparison efficiency of the two write-set combinations, that is, improving the detection efficiency of the problem contract.
[0072] Based on any of the above embodiments, in the method, the above step 120 includes: Based on the block height of the target block, obtaining the block execution result stored by the master node; Based on the block height of the target block, query the block execution result corresponding to the target block from other nodes among the multiple nodes except the master node, and receive the block execution results fed back by other nodes among the multiple nodes except the master node.
[0073] It should be noted that each node provides a query interface for block execution results, so that other nodes can quickly query the corresponding block execution results according to the block height.
[0074] The blockchain contract detection method provided by the embodiment of the present invention can quickly obtain the block execution result corresponding to the target block stored in each node in the blockchain through the above method, thereby improving the detection efficiency of the problem contract.
[0075] Based on any of the above embodiments, in this method, any of the write sets includes status data and contract identification data; the above step 130 includes: classifying each of the block execution results according to the contract identification data, and obtaining the write set classification results corresponding to each of the block execution results.
[0076] It should be noted that since the write set includes state data and contract identification data, based on this, the write set in the block execution result can be classified according to the contract identification data.
[0077] The blockchain contract detection method provided by the embodiment of the present invention can quickly classify the execution results of each block according to the contract identification data through the above method, thereby improving the detection efficiency of problematic contracts.
[0078] Based on any of the above embodiments, Figure 2 This is a second flow chart of the method for detecting a blockchain contract provided by an embodiment of the present invention. Figure 2 As shown, the above step 110 includes steps 111 to 113.
[0079] Step 111, obtaining the block height information sets respectively stored by the multiple nodes.
[0080] Among them, the block height information set stored by any of the nodes includes the block height information of the multiple nodes. Further, the block height information of any of the nodes includes node identification data, block height and update time of the block height information.
[0081] It should be understood that each node in the blockchain maintains a block height information set, and any block height information set includes the block height information of all nodes in the blockchain.
[0082] Here, the node identification data is used to uniquely identify the node, and the block height is the block height of the block of the node identified by the node identification data.
[0083] Step 112, based on each of the block height information sets, determine the unsynchronized blocks in the blockchain.
[0084] It should be understood that since the block height information set includes node identification data, block height and update time of block height information, based on this, the update time of block height information in the block height information of multiple nodes of unsynchronized blocks is different.
[0085] In one embodiment, it is determined whether there are two different block height information sets in each block height information set, and based on the two different block height information sets, the unsynchronized blocks in the blockchain are determined.
[0086] Before the above step 112, based on each block height information set, it is determined whether there are any unsynchronized blocks in the blockchain.
[0087] Step 113: Based on the unsynchronized blocks, determine the target block of the problem contract to be determined in the blockchain.
[0088] Here, the number of the unsynchronized blocks may be one or more. In one embodiment, the unsynchronized blocks are directly determined as target blocks.
[0089] Furthermore, the master node periodically executes the embodiment of the present invention, that is, the master node starts a scheduled task to periodically determine whether there is a target block that needs to be determined for the problematic contract.
[0090] The blockchain contract detection method provided by the embodiment of the present invention can first determine the unsynchronized blocks, and then accurately determine the target block of the problem contract to be determined based on the unsynchronized blocks. Compared with detecting the problem contracts on all blocks, it is very likely that there is no problem contract after avoiding the problem contract detection, thereby reducing data processing time, avoiding occupying computing resources, and improving data processing efficiency.
[0091] Based on any of the above embodiments, in the method, the above step 112 includes: Determine, from each of the block height information sets, a block height information set that is different from the block height information set stored by the master node; Based on a block height information set different from the block height information set stored by the master node and the block height information set stored by the master node, determining the unsynchronized blocks in the blockchain.
[0092] Here, there may be one or more block height information sets different from the block height information set stored in the master node.
[0093] It should be understood that since the block height information set includes node identification data, block height and update time of block height information, based on this, based on the block height information set different from the block height information set stored by the master node, and the comparison result of the block height information set stored by the master node, the unsynchronized blocks in the blockchain can be determined.
[0094] The blockchain contract detection method provided by the embodiment of the present invention determines a block height information set different from the block height information set stored by the master node from each block height information set, so that it is only necessary to compare the block height information set stored by other nodes with the block height information set stored by the master node, that is, to improve the comparison efficiency, thereby improving the efficiency of determining asynchronous blocks, and further improving the detection efficiency of problematic contracts.
[0095] Based on any of the above embodiments, in the method, determining the unsynchronized blocks in the blockchain based on a block height information set different from the block height information set stored by the master node and the block height information set stored by the master node includes: Determining first target block height information from a block height information set different from the block height information set stored by the master node, wherein the first target block height information is identical to the second target block height information in the block height information set stored by the master node in terms of node identification data and block height, and the first target block height information is different from the second target block height information in terms of update time; It is determined that the update time difference between the first target block height information and the second target block height information is greater than a preset time difference, and the block corresponding to the block height in the first target block height information is determined as an unsynchronized block in the blockchain.
[0096] Here, the first target block height information may be one or more.
[0097] Here, the preset time difference value may be preset according to actual conditions, and the preset time difference value is the time interval allowed for synchronization.
[0098] It should be understood that the two compared block height information should be for the same block, that is, the first target block height information and the second target block height information are the same in node identification data and block height. If the blocks are not synchronized, the update time of the two block height information should be different, that is, the first target block height information and the second target block height information are different in update time, and considering that there is inevitably a difference in the update time of the block height of each node updating the same block, the update time difference is considered to be synchronized within the allowed preset time difference. If the update time difference is greater than the preset time difference, it means that the block height has timed out and has not been updated.
[0099] The blockchain contract detection method provided by the embodiment of the present invention, through the above-mentioned method, only when the update time difference between the first target block height information and the second target block height information is greater than the preset time difference, the block corresponding to the block height in the first target block height information is determined as an unsynchronized block in the blockchain, thereby improving the accuracy of determining the unsynchronized blocks, and then improving the accuracy of determining the target blocks, avoiding the situation where there is a high possibility that there is no problem contract after the problem contract detection, thereby reducing data processing time, avoiding occupying computing resources, and improving data processing efficiency.
[0100] Based on any of the above embodiments, considering that although there are unsynchronized blocks, it does not necessarily mean that there is a problematic contract; based on this, the above step 113 includes: determining that the number of the unsynchronized blocks is greater than or equal to the block number threshold, and determining the target block from the unsynchronized blocks.
[0101] The block number threshold is the product of the total number of blocks in the blockchain and a preset ratio. The preset ratio can be set according to actual needs, for example, 0.5.
[0102] It should be noted that all the unsynchronized blocks may be determined as target blocks, or some of the unsynchronized blocks may be determined as target blocks.
[0103] It should be understood that if there are a large number of unsynchronized blocks, it indicates that there is a high probability that there is a problem with the contract involved. At this time, the problem contract will be detected to avoid the possibility that there is no problem contract after the problem contract detection, thereby reducing data processing time, avoiding the occupation of computing resources, and improving data processing efficiency.
[0104] The blockchain contract detection method provided by the embodiment of the present invention, through the above-mentioned method, only when a large area of blocks in the blockchain are out of sync, it is determined that there may be a problem contract, and then the target block of the problem contract to be determined is determined from the out of sync blocks, so as to avoid the possibility that there is no problem contract after the problem contract detection, thereby reducing data processing time, avoiding the occupation of computing resources, and improving data processing efficiency.
[0105] Based on any of the above embodiments, the method further includes: Receive the target block height broadcast by the target node; Based on the node identification data of the target node, determining the block height information of the target node from the block height information set stored by the master node; Determine that the block height in the block height information of the target node is different from the target block height, update the block height in the block height information of the target node to the target block height, and update the update time in the block height information of the target node.
[0106] It should be noted that each node in the blockchain needs to broadcast its own block height to other nodes. For example, the master node broadcasts its own block height to other nodes in multiple nodes except the master node. Furthermore, each node in the blockchain broadcasts its own block height to other nodes at a regular interval.
[0107] Specifically, when a node receives the block height broadcast by other nodes, it needs to determine whether the block height has been updated. If so, the block height and update time of the other nodes are updated to the corresponding block height information.
[0108] In a specific embodiment, the update time in the block height information of the updated target node is the current time.
[0109] In addition, if it is determined that the block height in the block height information of the target node is the same as the target block height, there is no need to update the block height information of the target node.
[0110] The blockchain contract detection method provided by the embodiment of the present invention receives the target block height broadcast by the target node, updates the block height information of the target node in the block height information set stored by the master node, so that the asynchronous blocks can be accurately determined by the update time later, thereby improving the accuracy of determining the target block, avoiding the possibility that there is no problem contract after the problem contract detection, thereby reducing data processing time, avoiding occupying computing resources, and improving data processing efficiency.
[0111] Based on any of the above embodiments, after the above step 140, the method further includes: The transaction executed according to the problematic contract is set to a failed state, and the write set involved in the execution according to the problematic contract in the block execution result set is deleted.
[0112] Specifically, the write sets involved in the execution of the problematic contract in the block execution results stored by the master node are deleted, and the write sets involved in the execution of the problematic contract in the block execution results stored by other nodes among the multiple nodes except the master node are deleted.
[0113] The blockchain contract detection method provided by the embodiment of the present invention, through the above-mentioned method, after determining the problematic contract, sets all transactions executed according to the problematic contract to a failed state, and deletes all write sets involved in the execution of the problematic contract in the block execution result set, thereby making the execution results associated with the problematic contract consistent, and making the block execution results stored in each node in the blockchain consistent, that is, ensuring that the block execution results of each block in the blockchain are consistent, thereby ensuring the consistency of the blockchain, and ensuring that the block height of the blockchain can grow.
[0114] Based on any of the above embodiments, after the above step 140, the method further includes: Add the problematic contract to the contract blacklist stored by the master node; The problematic contract is synchronized to other nodes among the multiple nodes except the master node, so that the other nodes among the multiple nodes except the master node can add the problematic contract to the contract blacklist stored in their own storage.
[0115] Among them, transactions executed according to the contracts in the contract blacklist need to be set to a failed state. Based on this, when the block is executed, it will be determined whether the contract to be executed is in the contract blacklist. If it is, the executed transaction will be directly set to a failed state.
[0116] Here, each node in the blockchain stores a contract blacklist, and transactions executed according to the contracts in the contract blacklist need to be set to a failed state, so that the consistency of the blockchain can be guaranteed by simply adding the problematic contract to the contract blacklist.
[0117] In one embodiment, each problematic contract is added to an extension field of a block, so that the problematic contract can be synchronized to other nodes among multiple nodes except the master node in this way.
[0118] Furthermore, the contract blacklist can be managed by an authorized account, such as a system administrator. For example, a user manually adds a contract to the contract blacklist, or a user manually deletes a contract from the contract blacklist.
[0119] The blockchain contract detection method provided by the embodiment of the present invention adds the problematic contract to the contract blacklist stored in each node in the blockchain in the above manner, and the transaction executed according to the contract in the contract blacklist needs to be set to a failed state to avoid the existence of write sets involving the problematic contract in subsequent block execution results, thereby eliminating the need to delete the write sets involved in the execution of the problematic contract in the block execution result set, thereby improving system efficiency, and the consistency of the blockchain can be always guaranteed by simply adding the problematic contract to the contract blacklist.
[0120] The blockchain contract detection device provided by the present invention is described below. The blockchain contract detection device described below and the blockchain contract detection method described above can be referenced to each other.
[0121] Figure 3 is a schematic diagram of the structure of a detection device for a blockchain contract provided by an embodiment of the present invention, such as Figure 3 As shown, the data processing device deployed in the master node of the blockchain includes: a block determination module 310, a result acquisition module 320, a result classification module 330 and a contract determination module 340. The blockchain includes multiple nodes.
[0122] The block determination module 310 is used to determine the target block of the problem contract to be determined in the blockchain.
[0123] The result acquisition module 320 is used to obtain the block execution result set corresponding to the target block; the block execution result set includes the block execution results stored by the multiple nodes respectively, and any of the block execution results includes a write set of at least one transaction, and any write set of the transaction is the write data involved in the execution of the transaction according to a contract.
[0124] The result classification module 330 is used to classify each of the block execution results according to the contract category to obtain the write-set classification results corresponding to each of the block execution results; the write-set classification results corresponding to any of the block execution results include at least one write-set combination corresponding to the contract, and any write-set combination corresponding to the contract includes at least one write-set involved in the execution of the contract.
[0125] The contract determination module 340 is configured to determine if there are two write-set classification results whose write-set combinations are different among the write-set classification results, and determine the contracts corresponding to the different write-set combinations as problematic contracts.
[0126] The detection device for blockchain contracts provided by an embodiment of the present invention determines a target block of a problem contract to be determined in a blockchain, obtains a block execution result set corresponding to the target block, and the block execution result set includes block execution results stored by multiple nodes respectively, and any block execution result includes a write set of at least one transaction, and the write set of any transaction is the write data involved in the execution of a transaction according to a contract, so as to classify each block execution result according to the contract category, and obtain the write set classification result corresponding to each block execution result, and the write set classification result corresponding to any block execution result includes a write set combination corresponding to at least one contract, and the write set combination corresponding to any contract includes at least one write set involved in the execution of the contract, so that the master node determines whether there are two write set classification results in each write set classification result. The write set combination is different, and the contract corresponding to the different write set combination can be determined as a problem contract. Compared with manual inspection of the problem contract, the problem contract can be accurately inspected based on each write set classification result, that is, the inspection accuracy of the problem contract is improved. At the same time, the master node detects the problem contract based on the above method, which can improve the detection efficiency of the problem contract and reduce the detection cost of the problem contract compared with manual inspection.
[0127] Figure 4 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 4As shown, the electronic device may include: a processor (processor) 410, a communication interface (Communications Interface) 420, a memory (memory) 430 and a communication bus 440, wherein the processor 410, the communication interface 420, and the memory 430 communicate with each other through the communication bus 440. The processor 410 can call the logic instructions in the memory 430 to execute the following method: determine the target block of the problem contract to be determined in the blockchain; obtain the block execution result set corresponding to the target block; the block execution result set includes the block execution results stored by the multiple nodes respectively, any of the block execution results includes at least one write set of transactions, and the write set of any transaction is the write data involved in the execution of the transaction according to a contract; classify each of the block execution results according to the contract category to obtain the write set classification result corresponding to each of the block execution results; the write set classification result corresponding to any of the block execution results includes at least one write set combination corresponding to the contract, and any write set combination corresponding to the contract includes at least one write set involved in the execution of the contract; determine that there are two write set classification results in each of the write set classification results that have different write set combinations, and determine the contracts corresponding to the different write set combinations as problem contracts.
[0128] In addition, the logic instructions in the above-mentioned memory 430 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention, or the part that contributes to the relevant technology or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0129] On the other hand, an embodiment of the present invention discloses a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, the computer program including program instructions, and when the program instructions are executed by a computer, the computer can execute the methods provided by the above-mentioned method embodiments, for example, including: determining a target block of a problem contract to be determined in the blockchain; obtaining a block execution result set corresponding to the target block; the block execution result set includes block execution results stored by the multiple nodes respectively, any of the block execution results includes a write set of at least one transaction, and the write set of any of the transactions is the write data involved in the execution of the transaction according to a contract; classifying each of the block execution results according to the contract category, and obtaining a write set classification result corresponding to each of the block execution results; the write set classification result corresponding to any of the block execution results includes a write set combination corresponding to at least one contract, and the write set combination corresponding to any of the contracts includes at least one write set involved in the execution of the contract; determining that the write set combinations of two write set classification results in each of the write set classification results are different, and determining the contracts corresponding to the different write set combinations as problem contracts.
[0130] On the other hand, an embodiment of the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which is implemented when the processor executes the blockchain contract detection method provided by the above embodiments, for example, including: determining a target block of a problem contract to be determined in the blockchain; obtaining a block execution result set corresponding to the target block; the block execution result set includes block execution results stored by the multiple nodes respectively, any of the block execution results includes a write set of at least one transaction, and the write set of any of the transactions is the write data involved in the execution of the transaction according to a contract; classifying each of the block execution results according to the contract category to obtain a write set classification result corresponding to each of the block execution results; the write set classification result corresponding to any of the block execution results includes a write set combination corresponding to at least one contract, and the write set combination corresponding to any of the contracts includes at least one write set involved in the execution of the contract; determining that there are two write set classification results in each of the write set classification results that have different write set combinations, and determining the contracts corresponding to the different write set combinations as problem contracts.
[0131] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, i.e., 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 embodiment. Those of ordinary skill in the art may understand and implement it without creative effort.
[0132] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods of each embodiment or some parts of the embodiment.
[0133] Finally, it should be noted that the above embodiments are only used to illustrate the present invention, rather than to limit the present invention. Although the present invention is described in detail with reference to the embodiments, it should be understood by those skilled in the art that various combinations, modifications or equivalent substitutions of the technical solutions of the present invention do not depart from the spirit and scope of the technical solutions of the present invention, and should be included in the scope of the claims of the present invention.
Claims
1. A method for detecting a blockchain contract, characterized in that: Applied to a master node in a blockchain, the blockchain comprising a plurality of nodes, the method comprising: Determine a target block of the problem contract to be determined in the blockchain; Obtaining a block execution result set corresponding to the target block; the block execution result set includes the block execution results respectively stored by the multiple nodes, any of the block execution results includes a write set of at least one transaction, and any of the write sets of the transaction is the write data involved in the execution of the transaction according to a contract; Classifying the execution results of each block according to the contract category to obtain write-set classification results corresponding to each block execution result; the write-set classification result corresponding to any of the block execution results includes a write-set combination corresponding to at least one contract, and the write-set combination corresponding to any of the contracts includes at least one write-set involved in the execution of the contract; It is determined that there are two write-set classification results in each of the write-set classification results whose write-set combinations are different, and contracts corresponding to the different write-set combinations are determined as problematic contracts.
2. The method for detecting a blockchain contract according to claim 1, characterized in that: The determining that there are two write-set classification results in each of the write-set classification results that have different write-set combinations, and determining the contracts corresponding to the different write-set combinations as problematic contracts, includes: determining that two of the write-set classification results are different from each other, and one of the two write-set classification results includes the write-set combination corresponding to the target contract, and the other of the two write-set classification results does not include the write-set combination corresponding to the target contract, and determining the target contract as a problem contract; or, It is determined that there are two different write-set classification results among the write-set classification results, and both of the two write-set classification results include a write-set combination corresponding to a target contract, and the write-set combinations corresponding to two target contracts included in the two write-set classification results are different, and the target contract is determined to be a problem contract.
3. The method for detecting a blockchain contract according to claim 2, characterized in that: Any of the write sets includes state data and contract identification data; The determining that there are two different write-set classification results among the write-set classification results, and both of the two write-set classification results include a write-set combination corresponding to the target contract, and the write-set combinations corresponding to the two target contracts included in the two write-set classification results are different, and determining the target contract as a problem contract includes: Determining that there are two different write-set classification results among the write-set classification results, and both of the two write-set classification results include a write-set combination corresponding to a target contract, and determining merged state data of the two write-set combinations corresponding to the target contract based on the two write-set combinations corresponding to the target contract included in the two write-set classification results; the merged state data of any of the write-set combinations is obtained by merging state data included in all write-sets in the write-set combination; Performing hash processing on the two merged state data respectively to obtain two hash state data; It is determined that the two hash state data are different, and the target contract is determined to be a problematic contract.
4. The method for detecting a blockchain contract according to claim 1, characterized in that: The obtaining of a block execution result set corresponding to the target block includes: Based on the block height of the target block, obtaining the block execution result stored by the master node; Based on the block height of the target block, query the block execution result corresponding to the target block from other nodes among the multiple nodes except the master node, and receive the block execution results fed back by other nodes among the multiple nodes except the master node.
5. The method for detecting a blockchain contract according to claim 1, characterized in that: Any of the write sets includes state data and contract identification data; The block execution results are classified according to the contract category to obtain the write set classification results corresponding to the block execution results, including: The execution results of each block are classified according to the contract identification data to obtain the write set classification results corresponding to the execution results of each block.
6. The method for detecting a blockchain contract according to any one of claims 1 to 5, characterized in that: The step of determining a target block of a problem contract to be determined in the blockchain includes: Obtaining block height information sets respectively stored by the multiple nodes; the block height information set stored by any of the nodes includes block height information of the multiple nodes, and the block height information of any of the nodes includes node identification data, block height, and update time of the block height information; Determining the unsynchronized blocks in the blockchain based on each of the block height information sets; Based on the unsynchronized blocks, a target block of the problem contract to be determined in the blockchain is determined.
7. The method for detecting a blockchain contract according to claim 6, characterized in that: The determining, based on each of the block height information sets, of the unsynchronized blocks in the blockchain includes: Determine, from each of the block height information sets, a block height information set that is different from the block height information set stored by the master node; Based on a block height information set different from the block height information set stored by the master node and the block height information set stored by the master node, determining the unsynchronized blocks in the blockchain.
8. The method for detecting a blockchain contract according to claim 7, characterized in that: The determining of the unsynchronized blocks in the blockchain based on the block height information set different from the block height information set stored by the master node and the block height information set stored by the master node comprises: Determining first target block height information from a block height information set different from the block height information set stored by the master node, wherein the first target block height information is identical to the second target block height information in the block height information set stored by the master node in terms of node identification data and block height, and the first target block height information is different from the second target block height information in terms of update time; It is determined that the update time difference between the first target block height information and the second target block height information is greater than a preset time difference, and the block corresponding to the block height in the first target block height information is determined as an unsynchronized block in the blockchain.
9. The method for detecting a blockchain contract according to claim 6, characterized in that: The step of determining a target block of a problem contract to be determined in the blockchain based on the unsynchronized block includes: Determine that the number of the unsynchronized blocks is greater than or equal to a block number threshold, and determine the target block from the unsynchronized blocks; The block number threshold is the product of the total number of blocks in the blockchain and a preset ratio.
10. The method for detecting a blockchain contract according to claim 6, characterized in that: The method further comprises: Receive the target block height broadcast by the target node; Based on the node identification data of the target node, determining the block height information of the target node from the block height information set stored by the master node; Determine that the block height in the block height information of the target node is different from the target block height, update the block height in the block height information of the target node to the target block height, and update the update time in the block height information of the target node.
11. The method for detecting a blockchain contract according to any one of claims 1 to 5, characterized in that: After determining that there are two write-set classification results whose write-set combinations are different among the write-set classification results, and determining the contracts corresponding to the different write-set combinations as problematic contracts, the method further includes: The transaction executed according to the problematic contract is set to a failed state, and the write set involved in the execution according to the problematic contract in the block execution result set is deleted.
12. The method for detecting a blockchain contract according to any one of claims 1 to 5, characterized in that: After determining that there are two write-set classification results whose write-set combinations are different among the write-set classification results, and determining the contracts corresponding to the different write-set combinations as problematic contracts, the method further includes: Add the problematic contract to the contract blacklist stored by the master node; Synchronize the problematic contract to other nodes among the multiple nodes except the master node, so that the other nodes among the multiple nodes except the master node can add the problematic contract to the contract blacklist stored in themselves; Among them, transactions executed according to the contracts in the contract blacklist need to be set to a failed state.
13. A blockchain contract detection device, characterized in that: A master node deployed in a blockchain, wherein the blockchain includes a plurality of nodes, and the device includes: A block determination module, used to determine the target block of the problem contract to be determined in the blockchain; A result acquisition module, used to acquire a block execution result set corresponding to the target block; the block execution result set includes the block execution results respectively stored by the multiple nodes, any of the block execution results includes a write set of at least one transaction, and any write set of the transaction is the write data involved in the execution of the transaction according to a contract; A result classification module is used to classify each of the block execution results according to the contract category, and obtain the write set classification results corresponding to each of the block execution results; the write set classification results corresponding to any of the block execution results include at least one write set combination corresponding to a contract, and any write set combination corresponding to the contract includes at least one write set involved in the execution of the contract; The contract determination module is used to determine that there are two write-set classification results whose write-set combinations are different among the write-set classification results, and determine the contracts corresponding to the different write-set combinations as problematic contracts.
14. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the method for detecting a blockchain contract as described in any one of claims 1 to 12 is implemented.
15. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for detecting a blockchain contract as described in any one of claims 1 to 12 is implemented.
16. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the method for detecting a blockchain contract as described in any one of claims 1 to 12 is implemented.
