Contract verification based on MPT tree and alliance chain contract write set construction method
By adopting contract verification based on MPT tree and consortium chain contract writing set construction methods in the blockchain system, the problem of difficult to guarantee the consistency of smart contract execution in multilingual smart contract verification and consortium chain scenarios is solved, efficient and accurate block verification and error positioning are achieved, and the system's fault tolerance and reliability are improved.
Patent Information
- Application Number
- CN202510018407.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-07
- Publication Date
- 2025-03-21
- Estimated Expiration
- 2045-01-07
AI Technical Summary
It is difficult for existing blockchain systems to ensure the consistency of smart contract execution in multilingual smart contract verification and alliance chain scenarios, especially when dynamic data updates and complex contract logic verification, traditional technologies are difficult to meet the needs of high fault tolerance and reliability.
The contract verification based on MPT tree and the alliance chain contract write set construction method are used to design the block correctness judgment module and the error contract positioning module. Through the combination of self-verification and global verification, the efficiency and accuracy of block verification are improved, and the errors in the execution of multilingual smart contracts are dynamically identified through the write set generation and comparison mechanism.
It realizes consistency verification and error positioning of smart contract execution, improves the efficiency and accuracy of block verification, ensures high fault tolerance and reliability in the alliance chain environment, and has the advantages of high verification efficiency, accurate error positioning, strong system stability and good scalability.
Smart Images

Figure CN119416273B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of multi-language smart contract verification technology, and in particular to a method for constructing a contract write set based on an MPT tree. Background Art
[0002] As a decentralized distributed ledger technology, blockchain technology has been widely used in finance, supply chain, smart contracts and other fields with its efficiency, transparency and security. As an important part of blockchain, smart contracts can automatically execute predefined rules and logic in the form of code. The introduction of multi-language smart contracts further expands the applicability and development flexibility of blockchain, allowing developers to choose the most suitable programming language to write contracts according to their own needs. However, due to the complexity of smart contracts themselves and the multi-node characteristics of distributed system environments, the execution results of smart contracts may be inconsistent, especially when multi-language contracts are involved. This problem is more prominent.
[0003] In existing blockchain systems, the verification of smart contracts mainly depends on the local execution results of nodes and the consensus mechanism between nodes. However, due to problems such as network delays, node failures, and data tampering in distributed environments, traditional verification mechanisms cannot fully guarantee the consistency of smart contract execution. For example, when the execution results of a contract depend on time, randomness, or the specific state of a node, some nodes may have inconsistent execution results due to environmental differences, which may lead to inconsistent ledgers. In addition, many current blockchain platforms have not introduced effective strategies for multilingual smart contracts during the verification process, resulting in support for multilingual smart contracts remaining at the contract deployment stage, without fully considering the consistency verification and error location issues during operation.
[0004] In the existing technology, the blockchain system mainly uses Merkle Tree to achieve fast data verification and efficient storage. However, Merkle Tree has certain limitations when processing large-scale ledger data and multi-language smart contracts. First, Merkle Tree cannot flexibly adapt to dynamic data update requirements, especially when the blockchain write set information changes frequently, the verification efficiency is low. Secondly, for multi-language smart contracts in the blockchain, the traditional verification mechanism lacks in-depth correlation analysis between the contract execution results and the write set, making it difficult to quickly locate and repair erroneous contracts. These defects are particularly prominent in the scenario of consortium chains, because consortium chains often involve cooperation between multiple different organizations and systems, and their data consistency requirements are higher, and traditional technologies are difficult to meet this demand.
[0005] In addition, the existing technology is also insufficient in terms of accuracy and efficiency of block verification. Block verification usually requires the validator to determine the correctness of the block by comparing the ledger hash in the block with the locally generated ledger hash, but the efficiency of this process is easily affected when the network scales. When there are malicious nodes or erroneous nodes in the verification process, the traditional verification mechanism relies on simple signature statistics and fails to make full use of global block verification information, which may lead to wrong decisions. At the same time, for the implementation of write-set generation and write-set comparison, most of the existing solutions are based on static models and cannot dynamically adapt to the complex changes that occur during the execution of smart contracts, resulting in low efficiency in contract error positioning, which further affects the consistency of the ledger and the stability of the blockchain system.
[0006] In order to improve the consistency of smart contract execution, some existing technologies have attempted to introduce improved data structures, such as the Merkle Patricia Tree (MPT) tree based on Merkle tree optimization. By combining the advantages of the Merkle tree and the prefix tree, the MPT tree has shown significant advantages in blockchain account data management and transaction set hash generation. However, the application scope of these solutions is mostly limited to static account data management, and their actual application in multi-language smart contract verification and alliance chain scenarios is still insufficient. Specifically, although the MPT tree can efficiently manage ledger data, existing solutions have failed to fully utilize its characteristics to dynamically verify the complex contract execution logic in the blockchain and locate erroneous contracts. In particular, when it is necessary to verify multiple nodes and multiple transactions at the same time, it is difficult for existing technologies to quickly generate write sets that are closely related to the contract execution results and perform in-depth verification based on write sets.
[0007] Therefore, how to provide a contract verification method based on the MPT tree and a consortium chain contract write set construction method is an urgent problem that technicians in this field need to solve. Summary of the invention
[0008] One purpose of the present invention is to propose a contract verification and alliance chain contract write set construction method based on MPT tree. The present invention adopts the verification and write set construction method based on MPT tree, and accurately identifies the erroneous contract and optimizes the account book update process by designing the block correctness judgment module and the error contract positioning module, thereby ensuring the consistency of the account book data and the efficiency of the system. By combining self-verification and global verification, the efficiency and accuracy of block verification are effectively improved; at the same time, through the write set generation and comparison mechanism, the errors in the execution of multi-language smart contracts are dynamically identified, ensuring high fault tolerance and reliability in the alliance chain environment, and having the advantages of high verification efficiency, accurate error positioning, strong system stability and good scalability.
[0009] According to the different functions of the blocks, the blocks are divided into the creation block, the guardian block, the sending block, the receiving block, the contract deployment block, and the contract execution block. Among them, the sending block, the receiving block, the contract deployment block, and the contract execution block all belong to the account block, and the creation block and the guardian block belong to the trustworthy block. The guardian block (Daemon Block) collects the current status information of the account in epochs, packages the account chain status regularly, and executes and sorts the contract operations in the account chain. The contract deployment block and the contract execution block complete the deployment or call of the contract after the guardian block is sorted and packaged.
[0010] System liveness is a term used in the context of distributed systems when a system continues to run. Liveness means that it will not stop running even if errors occur in the system, and in the context of blockchain it means that the system will continue to add new blocks to the chain and will not stop running at any time.
[0011] System safety means that even if there are faulty nodes in the system, the network ends with a single decision across all reliable nodes.
[0012] The MPT-tree-based contract verification and alliance chain contract write set construction method according to an embodiment of the present invention includes the following steps:
[0013] S1. Generate blocks through mining by miners, and the blocks include block headers, ledger hashes, and write set information;
[0014] S2. Verify the block using a block correctness judgment module, wherein the block correctness judgment module includes a self-verification module and a global verification module;
[0015] S3. Identify the erroneous contract using an erroneous contract location module, wherein the erroneous contract location module includes a write set generation module and a contract correctness judgment module;
[0016] S4. Return the identification result and the modified write set information to the miner for updating the blockchain ledger.
[0017] Optionally, the self-verification module specifically includes: after the verifier performs a verification operation on the block, the contract in the block is executed and a ledger is generated; the root hash of the ledger is compared with the ledger hash of the block itself, if the two are the same, it is determined that the block has no erroneous contract, otherwise, the block is marked as containing an erroneous contract.
[0018] Optionally, the global verification module includes system activity verification and system security verification.
[0019] Optionally, the system activity verification includes the following steps:
[0020] Prerequisites: Byzantine fault-tolerant consensus mechanism is adopted, and the fault tolerance of the system is N=3f+1, where N represents the total number of nodes in the network, including correct nodes and error nodes. The correct nodes represent nodes that perform verification tasks normally, and the error nodes represent nodes that cannot perform verification tasks normally. The current system contains f error nodes and f unknown nodes.
[0021] When there are at most f erroneous nodes that do not respond, the number of remaining responding nodes is Nf=2f+1. Miners verify signatures by collecting at least 2f+1 blocks within a certain period of time, where the number of signatures of at least one type reaches or exceeds f+1. When miners receive f+1 signatures of the same type, they judge the correctness or error of the block.
[0022] Optionally, the system security verification includes the following steps:
[0023] Set the prerequisites: During the global verification process, only the block producer collects signatures for verification, and there is only one block producer for the same block; there are two different decisions A and B, the number of signatures of A is f+1, and the number of signatures of B is 2f, where A represents a correct block, B represents an incorrect block, and f represents the number of incorrect nodes; During the verification process, the block producer collects f+1 signatures of the same type, that is, it determines that there is at least one signature of the correct node; when any one of the signatures of A and B is greater than or equal to f+1, a decision is made and the other decision is discarded, so as to maintain consistency when receiving different decisions.
[0024] Optionally, the writeset generation module is used to generate a writeset for each multilingual smart contract transaction, and the writeset includes the following information:
[0025] Key value, used to represent the data key in the write set;
[0026] Data value, used to represent the data content corresponding to the data key;
[0027] Data type, used to indicate the attribute type of the write set data;
[0028] Data address, used to indicate the storage location of the data in the write set;
[0029] The execution results of the multi-language smart contract are recorded by generating a write set, and the hash value of the write set is associated with the received block information.
[0030] Optionally, the contract correctness judgment module specifically includes:
[0031] When the block fails verification in step S2, the verifier further verifies the block and generates: the write set modified by the verifier as the remote write set; verification result information; and the verifier signature information, which is used to feed back to the miner;
[0032] After receiving the remote write-set, the miner compares the remote write-set with the local write-set based on the local write-set generated by the local execution contract. If the remote write-set is consistent with the local write-set, the contract is determined to be correct; otherwise, it is marked as an error contract and added to the specified error contract set.
[0033] The beneficial effects of the present invention are:
[0034] First, the block correctness judgment module designed by the present invention can not only quickly identify erroneous contracts in the block, but also effectively ensure the activity and security of the system by combining the self-verification module and the global verification module. In the self-verification module, the verifier can quickly determine whether there is an error in the block by comparing the ledger hash and the block ledger root hash; while the global verification module ensures that the system can still achieve correct block judgment in the case of malicious nodes or network delays through activity verification and security verification. This two-layer verification mechanism effectively improves the efficiency and accuracy of block verification, especially in the alliance chain environment with high fault tolerance requirements, and can ensure the stable operation of the system under dynamic conditions.
[0035] Secondly, the design of the error contract positioning module greatly improves the efficiency of identifying error contracts by introducing a write set generation and comparison mechanism. The write set generation module proposed in the present invention can generate a detailed write set containing key values, data values, data types and data addresses for each multilingual smart contract transaction, and associate these write sets with the hash values recorded in the block. On this basis, the contract correctness judgment module realizes the dynamic identification and positioning of error contracts by accurately comparing remote write sets with local write sets. This mechanism not only solves the problem of the inability to quickly locate error contracts in the prior art, but also can optimize the update process of the ledger in subsequent operations through flexible management of write sets, thereby improving the consistency and scalability of the system.
[0036] In addition, the present invention utilizes the characteristics of the MPT tree to efficiently manage blockchain ledger data, and is specifically optimized for multi-node, multi-language smart contract scenarios of the alliance chain. By improving the write-set generation strategy and block verification process, the present invention achieves significant performance improvements in dynamic updates of ledger data and multi-language contract logic verification. For example, when the execution result of a contract depends on time, randomness, or node status, the present invention records the detailed write set of the contract execution to ensure that subsequent nodes can maintain ledger consistency based on the same write set results, thereby avoiding ledger conflicts caused by inconsistent contract results in traditional technologies. This dynamic management method based on the MPT tree not only improves verification efficiency, but also enhances the system's anti-tampering capabilities and data transparency. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0038] Figure 1 This is the overall flow chart of the MPT-tree-based contract verification and alliance chain contract write set construction method proposed in the present invention;
[0039] Figure 2 This is a block structure diagram of the MPT tree-based contract verification and alliance chain contract write set construction method proposed in the present invention. DETAILED DESCRIPTION
[0040] The present invention will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, which only illustrate the basic structure of the present invention in a schematic manner, and therefore only show the components related to the present invention.
[0041] refer to Figure 1 and Figure 2 , the contract verification and alliance chain contract write set construction method based on MPT tree includes the following steps:
[0042] S1. Generate blocks through mining by miners, and the blocks include block headers, ledger hashes, and write set information;
[0043] S2. Verify the block using a block correctness judgment module, wherein the block correctness judgment module includes a self-verification module and a global verification module;
[0044] S3. Identify the erroneous contract using an erroneous contract location module, wherein the erroneous contract location module includes a write set generation module and a contract correctness judgment module;
[0045] S4. Return the identification result and the modified write set information to the miner for updating the blockchain ledger.
[0046] In this implementation, the self-verification module specifically includes: after the verifier performs a verification operation on the block, the contract in the block is executed and an account book is generated; the root hash of the account book is compared with the account book hash of the block itself. If the two are the same, it is determined that the block has no erroneous contract. Otherwise, the block is marked as containing an erroneous contract.
[0047] In this implementation, the global verification module includes system activity verification and system security verification.
[0048] In this implementation, the system activity verification includes the following steps:
[0049] Prerequisites: Byzantine fault-tolerant consensus mechanism is adopted, and the fault tolerance of the system is N=3f+1, where N represents the total number of nodes in the network, including correct nodes and error nodes. The correct nodes represent nodes that perform verification tasks normally, and the error nodes represent nodes that cannot perform verification tasks normally. The current system contains f error nodes and f unknown nodes.
[0050] When there are at most f erroneous nodes that do not respond, the number of remaining responding nodes is Nf=2f+1. Miners verify signatures by collecting at least 2f+1 blocks within a certain period of time, where the number of signatures of at least one type reaches or exceeds f+1. When miners receive f+1 signatures of the same type, they judge the correctness or error of the block.
[0051] In this implementation, the system security verification includes the following steps:
[0052] Set the prerequisites: During the global verification process, only the block producer collects signatures for verification, and there is only one block producer for the same block; there are two different decisions A and B, the number of signatures of A is f+1, and the number of signatures of B is 2f, where A represents a correct block, B represents an incorrect block, and f represents the number of incorrect nodes; During the verification process, the block producer collects f+1 signatures of the same type, that is, it determines that there is at least one signature of the correct node; when any one of the signatures of A and B is greater than or equal to f+1, a decision is made and the other decision is discarded, so as to maintain consistency when receiving different decisions.
[0053] In this implementation, the writeset generation module is used to generate a writeset for each multilingual smart contract transaction. The writeset includes the following information:
[0054] Key value, used to represent the data key in the write set;
[0055] Data value, used to represent the data content corresponding to the data key;
[0056] Data type, used to indicate the attribute type of the write set data;
[0057] Data address, used to indicate the storage location of the data in the write set;
[0058] The execution results of the multi-language smart contract are recorded by generating a write set, and the hash value of the write set is associated with the received block information.
[0059] In this implementation, the contract correctness judgment module specifically includes:
[0060] When the block fails verification in step S2, the verifier further verifies the block and generates: the write set modified by the verifier as the remote write set; verification result information; and the verifier signature information, which is used to feed back to the miner;
[0061] After receiving the remote write-set, the miner compares the remote write-set with the local write-set based on the local write-set generated by the local execution contract. If the remote write-set is consistent with the local write-set, the contract is determined to be correct; otherwise, it is marked as an error contract and added to the specified error contract set.
[0062] Embodiment 1:
[0063] In order to verify the feasibility of the present invention in implementation, the present invention is applied to the smart contract verification and ledger consistency maintenance of the financial alliance chain. This embodiment involves fund settlement and contract execution between multiple financial institutions. Due to the widespread application of multilingual smart contracts, different nodes may cause inconsistent ledger data due to system differences when executing contracts, especially in high-frequency transactions and multi-node synchronous operations. The problem is more prominent. The present invention effectively solves the above problems by introducing a verification method and write set construction mechanism based on the MPT tree, and significantly improves the verification efficiency and ledger consistency of the system.
[0064] In actual applications, the financial alliance chain system includes 15 participating nodes, including 10 correct nodes and 5 error nodes that may have faults or delays. The nodes verify the blocks through the Byzantine fault-tolerant consensus mechanism. After generating the blocks, the miner nodes broadcast the ledger hash and write set information to other verification nodes. The verification node verifies the block through the block correctness judgment module of the present invention. First, it uses its own verification module to quickly compare the ledger hash to screen the error block; then, it collects signatures under fault-tolerant conditions through the global verification module to further verify the activity and security of the block. When an error contract is detected in the block, the system uses the error contract positioning module to locate the error contract by comparing the remote write set and the local write set, and records it in the error contract set.
[0065] The specific test data is as follows: In a high-frequency trading scenario, 200 transactions are generated by smart contract processing every second. The test runs for 24 hours and the system generates a total of 17,280 blocks. In the traditional verification method, the inconsistency rate of ledger data caused by faulty nodes is as high as 2.5%, while after using the verification method of the present invention, the inconsistency rate is reduced to 0.1%. At the same time, the system performs well in locating faulty contracts, and the average locating time is shortened from 6 seconds in the traditional method to 2 seconds, and the overall block verification efficiency is improved by 35%.
[0066] The test also recorded detailed performance data of block verification and error location. The data table is shown in Table 1 below.
[0067] Table 1 Block verification and error location performance test data table
[0068] ;
[0069] It can be seen from the above experimental data that the present invention not only significantly reduces the incidence of inconsistent ledger data, but also achieves a significant improvement in block verification efficiency and error contract positioning accuracy. In practical applications, the method of the present invention can effectively adapt to complex scenarios of multi-language smart contracts, ensure the real-time synchronization and data consistency of financial alliance chain ledgers, and provide strong support for the safe and stable operation of multi-node distributed systems. In addition, the data table further illustrates the superiority of the present invention in processing high-frequency transactions and multi-node collaborative environments, fully proving its application value and technical advantages.
[0070] The above description is only a preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can make equivalent replacements or changes according to the technical scheme and inventive concept of the present invention within the technical scope disclosed by the present invention, which should be covered by the protection scope of the present invention.
Claims
1. The MPT-tree-based contract verification and alliance chain contract write set construction method is characterized by: The steps include: S1. Generate blocks through mining by miners. The blocks include block headers and block bodies. The block headers store the ledger hash, and the block bodies store write set information and error contracts. S2. Use the block correctness judgment module to judge whether there is an erroneous contract in the block, and the block correctness judgment module includes a self-verification module and a global verification module; S3. Identify the erroneous contract using an erroneous contract location module, wherein the erroneous contract location module includes a write set generation module and a contract correctness judgment module; S4. Return the hash value of the error contract to update the blockchain ledger; The global verification module includes system activity verification and system security verification; The system activity verification includes the following steps: Prerequisites: Byzantine fault-tolerant consensus mechanism is adopted, and the fault tolerance of the system is N=3f+1, where N represents the total number of nodes in the network, including correct nodes and error nodes. The correct nodes represent nodes that perform verification tasks normally, and the error nodes represent nodes that cannot perform verification tasks normally or intentionally send wrong data or send different data to different nodes, so that the nodes of the entire cluster cannot reach a consensus in the end; the current system contains f error nodes and f unknown nodes; When there are at most f erroneous nodes that do not respond, the number of remaining responding nodes is Nf=2f+1. Miners verify signatures by collecting at least 2f+1 blocks within a certain period of time, where the number of signatures of at least one type reaches or exceeds f+1. When miners receive f+1 signatures of the same type, they determine the correctness or error of the block. The system security verification includes the following steps: Set the prerequisites: During the global verification process, only the block producer collects signatures for verification, and there is only one block producer for the same block; there are two different decisions A and B, the number of signatures of A is f+1, and the number of signatures of B is 2f, where A represents a correct block, B represents an incorrect block, and f represents the number of incorrect nodes; During the verification process, the block producer collects f+1 signatures of the same type, that is, it determines that at least one correct node’s signature is included; when the number of signatures of A and B is greater than or equal to f+1, the block producer makes a decision and discards the other decision, thereby maintaining consistency when receiving different decisions; The contract correctness judgment module specifically includes: When the block fails verification in step S2, the verifier locates the faulty contract in the block and generates: the write set modified by the verifier as the remote write set; verification result information; and the verifier signature information, which is used to feed back to the miner; After receiving the remote write set, the miner compares the remote write set with the local write set based on the local write set generated by the miner's own execution of the contract. If the remote write set is consistent with the local write set, the contract is determined to be correct; otherwise, it is marked as an error contract and added to the specified error contract set.
2. The MPT-tree-based contract verification and alliance chain contract write set construction method according to claim 1, characterized in that: The self-verification module specifically includes: after the verifier performs an execution operation on the block, the contract in the block is run and the root hash of the corresponding account book is generated; the root hash of the account book is compared with the account book hash of the block itself. If the two are the same, it is determined that the block has no erroneous contract, otherwise, the block is marked as containing an erroneous contract.
3. The MPT tree-based contract verification and alliance chain contract write set construction method according to claim 1 is characterized in that: The write set generation module is used to generate a write set for each multilingual smart contract transaction. The write set includes the following information: Key value, used to represent the data key in the write set; Data value, used to represent the data content corresponding to the data key; Data type, used to indicate the attribute type of the write set data; Data address, used to indicate the storage location of the data in the write set; The write set generated by the execution of the multi-language smart contract is recorded, and the hash value of the write set is associated with the received block information.
Citation Information
Patent Citations
A mining method and device based on block chain, a mining machine and a block chain system
CN109255614A
Blockchain intelligent contract transaction concurrent execution method
CN110517140A