A method for cross-chain data correctness verification based on nested Merkle trees

By deploying nested Merkle tree contracts in a consortium blockchain, the problem of untrusted data in cross-chain systems is solved, enabling rapid verification and storage optimization of cross-chain data, and making it suitable for efficient cross-chain data persistent storage.

CN115357335BActive Publication Date: 2025-12-02NANJING UNIV OF AERONAUTICS & ASTRONAUTICS
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210937882.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-05
Publication Date
2025-12-02
Estimated Expiration
2042-08-05

AI Technical Summary

Technical Problem

In existing consortium blockchain cross-chain systems, data is unreliable, and Merkle trees incur excessive storage and verification overhead for large datasets, making them unsuitable for verification in cross-chain scenarios.

Method used

It adopts a nested Merkle tree structure, and deploys a Merkle tree contract as a proxy contract in the consortium blockchain to manage the insertion, retrieval path and query operations of the Merkle tree. When performing cross-chain queries, it returns the Merkle path for verification, reducing storage pressure and verification overhead.

Benefits of technology

It enables rapid verification and correctness assurance of cross-chain data, reduces the storage pressure and computational overhead of Merkle trees, and is suitable for efficient cross-chain data persistent storage.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115357335B_ABST
    Figure CN115357335B_ABST
Patent Text Reader

Abstract

This invention discloses a cross-chain data correctness verification method based on nested Merkle trees. The method first creates a nested Merkle tree during consortium blockchain initialization. As data is continuously written to the chain, Merkle nodes are created for the latest data and inserted into the tree. Simultaneously, nodes in the Merkle tree are connected to their parent and sibling nodes using UniqueKeys, ultimately resulting in a linked list of Merkle nodes. When querying data across chains, the Merkle leaf node corresponding to the target data is first obtained. The complete Merkle path is obtained by traversing upwards from the leaf node. During data cross-chain processing, the data and its Merkle path are packaged and sent to the cross-chain request chain for verification, thus ensuring the correctness of the cross-chain data. This invention reduces the storage pressure on the Merkle tree by using a nested Merkle tree method, reduces network communication overhead during transmission, simplifies verification calculations, and accelerates the query and traversal process in the persistently stored Merkle tree by linking Merkle tree nodes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of blockchain, specifically a cross-chain data correctness verification method based on nested Merkle trees. Background Technology

[0002] Blockchain, with its secure, reliable, and tamper-proof data properties, is widely used in fields such as evidence storage and retrieval, and logistics traceability. Furthermore, as its applications expand and become more specialized, several different types of blockchain have emerged. Blockchain can be broadly categorized into three types: public blockchains, private blockchains, and consortium blockchains.

[0003] In cases where companies do not want to disclose all their data but still want to take advantage of the immutability and traceability of blockchain data, consortium blockchains have become a better option.

[0004] Despite the large number of existing consortium blockchains, there is a lack of effective means for data interoperability between them. To break down data silos between consortium blockchains, cross-chain technology has become increasingly important, and some cross-chain frameworks suitable for consortium blockchains have emerged. However, the security of each individual consortium blockchain is guaranteed by its own organizational structure and consensus algorithm. Cross-chain systems composed of multiple blockchains cannot guarantee their security and are prone to situations where forged false data is returned to the requesting blockchain. To avoid such attacks, Merkle trees can be used to ensure the correctness of the data.

[0005] A Merkle tree is a special type of binary tree consisting of a root node, a set of intermediate nodes, and a set of leaf nodes. First proposed by Merkle Ralf in 1980, Merkle trees were widely used in file systems and peer-to-peer (P2P) systems. Its main characteristics are: the bottommost leaf nodes contain stored data or its hash value; non-leaf nodes (including intermediate and root nodes) contain the hash values ​​of the contents of their two child nodes.

[0006] In real-world scenarios, consortium blockchains handle large amounts of real-time data. Maintaining a conventional Merkle tree requires extensive re-hash calculations, consuming significant computing resources. Furthermore, as data is continuously written, the storage requirements of the Merkle tree increase exponentially, placing immense storage pressure on the consortium blockchain. Additionally, persistent storage and efficient querying of the Merkle tree within a consortium blockchain context are also challenges that need to be addressed.

[0007] Patent CN112769894A uses Merkle trees to verify power grid equipment, but it does not solve the problem of increased storage and verification overhead of Merkle trees due to real-time information writing, and it is not applicable to cross-chain verification scenarios. In patent CN111262788A, the storage of Merkle trees is optimized, but there is no significant improvement in query and indexing speed. Summary of the Invention

[0008] The purpose of this invention is to solve the problem of unreliable correctness in cross-chain data and to provide a method for verifying the correctness of cross-chain data based on nested Merkle trees.

[0009] Technical solution: A cross-chain data correctness verification method based on nested Merkle trees, comprising the following steps:

[0010] 6) During initialization, the consortium blockchain creates an empty Merkel tree and sets parameters, including the tree height and the latest node of the tree. Then, the Merkel tree after setting the parameters is serialized and stored on the blockchain.

[0011] 7) Deploy the Merkle tree contract to the consortium blockchain and set the Merkle tree contract as a proxy contract, providing interfaces including insertion, path retrieval, and query operations for the Merkle tree;

[0012] 8) When new data is written to the ledger in the consortium blockchain, the Merkle tree contract creates a new Merkle node for the new data, adds it to the current Merkle tree, and performs an update operation on the current Merkle tree based on that position;

[0013] 9) In the Merkle tree contract traversal step 3), update the nodes of the Merkle tree and connect each node of the Merkle tree to its sibling and parent nodes.

[0014] 10) When the requesting chain initiates a cross-chain query request to the target chain, all requests will be processed by the Merkle tree contract first. The Merkle tree contract will query the target data, package the target data and its Merkle path and send it to the requesting chain. After receiving the request, the requesting chain will perform Merkle verification. If the verification is successful, it proves the correctness of the current cross-chain data.

[0015] Preferably, the implementation process of step 3) is as follows: Let the current Merkle tree height be h, the existing data volume be n, the latest node of the Merkle tree be L, the byte stream of the serialized data result be bs, and the hash algorithm be Sha-256. When new data is written to the ledger, if the insertion position of the new data is odd, it is only necessary to perform hash update on the node for the new data; if the insertion position of the new data is even, then it is necessary to obtain the latest node L, concatenate the byte streams of the hashes of the two, and then perform hash update on the node.

[0016] Preferably, after performing a hash update on a node, the ID of the parent node of that node is found, and it is used to populate the ID field of the parent node of the corresponding Merkle node.

[0017] Preferably, in step 3), as new data is continuously written, the fixed-height Merkle tree will soon be filled. To reduce computation, the root node of the previous Merkle tree is used as the first node of the next Merkle tree, which ensures that the height of the Merkle tree is constant, while reducing storage pressure and computational overhead for verification.

[0018] Preferably, in step 5), when the requesting chain initiates a cross-chain query request to the target chain, all requests are first processed by the Merkle tree contract. The Merkle tree contract queries the target data f and reads the key value Key of the corresponding Merkle tree node from the additional data of the target data f, thereby indexing the leaf node of the corresponding Merkle tree. It uses the parent and sibling nodes in the additional information of the leaf node to traverse the Merkle tree in sequence to collect the Merkle path. Finally, it packages the queried data and its Merkle path and sends it to the requesting chain. After receiving the request, the requesting chain performs Merkle verification. If the verification is successful, it proves the correctness of the current cross-chain information inspection data.

[0019] Preferably, the Merkle verification is as follows:

[0020] hashF = Hash(f) (1)

[0021] root hash2==Hash(hashF+Hash(Hash(e)+root hash1)) (2)

[0022] Where: hashF is the hash of data F, Hash(f) and Hash(e) are the hashes of data f and e, and the Merkle path of data f contains hashF, Hash(Hash(e)+root hash1) and root hash2;

[0023] If both sides of equation (2) are equal, then the verification is considered successful.

[0024] Beneficial effects: Compared with the prior art, the outstanding substantive features and significant progress of the present invention are mainly reflected in the following aspects:

[0025] (1) In the cross-chain process, the present invention returns the Merkle path of the target information in addition to returning the information queried by the requesting chain, so that the requesting chain can quickly verify the correctness of the cross-chain data.

[0026] (2) The present invention adopts nested superposition of Merkle trees, which reduces the storage pressure of Merkle trees without affecting data security, and at the same time reduces the overhead of transmitting and verifying Merkle paths.

[0027] (3) By connecting the nodes of the nested Merkle tree with their parent and sibling nodes in a linked list-like manner, this invention accelerates the process of obtaining the Merkle path, reduces the overhead of traversing the Merkle tree, and is well-suited for Merkle persistent storage scenarios.

[0028] Finally, by deploying a Merkle tree contract as a proxy contract, this invention intercepts all cross-chain requests, thereby achieving comprehensive and thorough verification of the correctness of cross-chain data. Attached Figure Description

[0029] Figure 1 Insert a data flow diagram for this invention;

[0030] Figure 2 This is a flowchart illustrating the data verification process for this invention.

[0031] Figure 3 This is a diagram of the cross-chain request and verification structure of the present invention;

[0032] Figure 4 This is a diagram of the nested Merkle tree structure of the present invention. Detailed Implementation

[0033] To illustrate the technical solutions disclosed in this invention in detail, the following description is provided in conjunction with the accompanying drawings.

[0034] like Figures 1-3 This invention proposes a cross-chain data correctness verification method based on nested Merkle trees, which solves the problem of untrustworthy cross-chain data in systems composed of multiple chains. The implementation process of the method is described in detail below.

[0035] To address the issue of untrusted cross-chain data in cross-chain systems composed of multiple chains, this invention maintains a nested Merkle tree in the consortium blockchain ledger. When querying information across chains, it returns the queried data along with its Merkle path, enabling the requesting chain to verify the legitimacy of the cross-chain data.

[0036] This invention proposes a cross-chain data correctness verification method based on nested Merkle trees for Hyperledger Fabric cross-chain scenarios. The Hyperledger Fabric framework is the most widely used and covers the broadest range of scenarios among existing consortium blockchain frameworks. The Hyperledger Project, founded by the Linux Foundation in October 2015, is an open-source blockchain research and development incubation project dedicated to providing collaborative development of distributed ledgers based on blockchain technology. Its Fabric project aims to create a consortium blockchain platform that provides distributed ledger solutions.

[0037] Fabric's ledger primarily consists of two parts: a key-value (KV) database storing the world state, typically using LevelDB by default; and a blockchain storing all operations that alter the world state. In Fabric, any operation that changes the world state is packaged into a block by the sorting node, which then broadcasts the block to all nodes connected to the consortium blockchain. Therefore, verifying the correctness of cross-chain data based on Fabric requires considering its KV ledger characteristic.

[0038] The specific implementation steps of this invention are as follows:

[0039] S1. During initialization, the consortium blockchain connecting to the cross-chain system creates an empty Merkle tree and sets a series of parameters, including the height h of the Merkle tree, the latest Merkle node LatestNode, etc., and serializes the Merkle tree structure and stores it on the blockchain. The height h can be obtained by taking the logarithm of the current blockchain's throughput tps with respect to the branching tree n of the target Merkle.

[0040] h = log n TPS

[0041] S2. Deploy the contract that processes nested Merkle trees to the consortium blockchain and set it as a proxy contract. All query requests from external blockchains will first be processed by the Merkle tree contract. The function signature design for querying data in the Merkle tree contract is as follows:

[0042] func Query(TargetLedger,K)return(error,V,Proof)

[0043] TargetLedger represents the target ledger for the query. Since data is isolated between different ledgers in Fabric, a cross-ledger call is required to query the data. K is the key corresponding to the target data in the KV ledger. The return value is error, V and Proof. Error represents possible errors during the query process, V is the value corresponding to data K, which is the target data being queried, and Proof consists of the Merkle path corresponding to data K.

[0044] S3. When new data is written to the ledger, a callback to the Merkle tree contract is triggered after the ledger data update to update the nested Merkle tree. Let the current blockchain height be h, the existing data volume be n, the latest Merkle tree node be L, and the byte stream of the serialized data result be bs. This invention uses the Sha-256 hash algorithm. The contract needs to determine the current node's position. If the current insertion position is odd, then only the current data needs to be hashed to create a Merkle node; if the current insertion position is even, then the latest node L needs to be obtained, and the hashed byte streams of the two nodes concatenated before hashing. The specific algorithm is as follows:

[0045]

[0046] Assuming the newly inserted node is numbered i, the numbers of all Merkle tree nodes that need to be updated can be obtained using the following algorithm:

[0047] ChangedNodes = []

[0048] for nodes[i].ParentID! =null:

[0049] ChangedNodes=append(nodes[i].ParentID)

[0050] S4. After creating the corresponding Merkle node for the data, you need to populate the ParentID field of the corresponding Merkle node to maintain normal link relationships.

[0051] S5. As data is continuously written, after the height of the previous Merkle tree is filled, Merkle will create a new Merkle tree and use the root of the previous Merkle tree as the first node of the current Merkle tree. The root node does not have corresponding data; it is a special type of leaf node. The root node has special additional information called RootInfo, which contains the corresponding information of the previous tree, including the required TreeID, etc.

[0052] S6. When another chain initiates a cross-chain query request in the cross-chain system, the request will be captured and processed by the Merkle tree contract first. Taking Figure-3 as an example, let the data to be queried be f. The first step is to obtain the ID of the corresponding Merkle leaf node based on the LeafID in the additional information of data f. Then, the parent node is continuously obtained through the ParentID in the additional information of the Merkle node, and the sibling node ID is obtained through BrotherID. Let the current latest Merkle node be L, and the final Merkle path to be obtained is MerklePath. The overall query algorithm is as follows:

[0053] tmp=L

[0054] MerklePath = []

[0055] for tmp.Parent! = null:

[0056] tmp = tmp.BrotherID

[0057] MerklePath=append(tmp.ParentID)

[0058] tmp = tmp.ParentID

[0059] S7, the Merkle tree contract, after collecting the Merkle paths, packages the query results and Merkle paths and sends them to the request chain.

[0060] S8, the request chain receives the query result V and its Merkle path, with Figure 3 Taking data f as an example, its Merkle path is Hash(g), Hash(Hash(e) + root hash1), root hash2. The specific verification algorithm is as follows:

[0061] hashF = Hash(f)

[0062] root hash2==Hash(hashF+Hash(Hash(e)+root hash1))

[0063] If the request chain verifies that both sides of the equation are equal, the verification is considered successful, thus ensuring the correctness of cross-chain data.

[0064] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A method for verifying the correctness of cross-chain data based on nested Merkle trees, characterized in that, Includes the following steps: 1) During initialization, the consortium blockchain creates an empty Merkel tree and sets parameters, including the tree height and the latest node of the tree. Then, the Merkel tree after setting the parameters is serialized and stored on the blockchain. 2) Deploy the Merkle tree contract to the consortium blockchain and set the Merkle tree contract as a proxy contract, providing interfaces including insertion, path retrieval, and query operations for the Merkle tree; 3) When new data is written to the ledger in the consortium blockchain, the Merkle tree contract creates a new Merkle node for the new data, adds it to the current Merkle tree, and performs an update operation on the current Merkle tree according to the insertion position of the new data. The implementation process of step 3) is as follows: when new data is written to the ledger, if the insertion position of the new data is odd, it is only necessary to perform a hash update on the node for the new data; if the insertion position of the new data is even, it is necessary to obtain the latest node L, concatenate the byte streams of the hashes of the two, and then perform a hash update on the node. 4) In the Merkle tree contract traversal step 3), update the nodes of the Merkle tree and connect each node of the Merkle tree to its sibling and parent nodes. 5) When the requesting chain initiates a cross-chain query request to the target chain, all requests will be processed by the Merkle tree contract first. The Merkle tree contract will query the target data, package the target data and its Merkle path and send it to the requesting chain. After receiving the request, the requesting chain will perform Merkle verification. If the verification is successful, it proves the correctness of the current cross-chain data.

2. The method for cross-chain data correctness verification based on nested Merkle trees as described in claim 1, characterized in that, After performing a hash update on a node, find the ID of the parent node of that node and use it to populate the parent node field of the corresponding Merkle node.

3. The method for cross-chain data correctness verification based on nested Merkle trees as described in claim 2, characterized in that, In step 3), as new data is continuously written, the fixed-height Merkle tree will soon be filled. To reduce computation, the root node of the previous Merkle tree is used as the first node of the next Merkle tree, which ensures that the height of the Merkle tree is constant, while reducing storage pressure and computational overhead for verification.

4. The method for cross-chain data correctness verification based on nested Merkle trees as described in claim 3, characterized in that, In step 5), when the requesting chain initiates a cross-chain query request to the target chain, all requests are first processed by the Merkle tree contract. The Merkle tree contract queries the target data and reads the key value of the corresponding Merkle tree node from the additional data of the target data, thereby indexing the leaf node of the corresponding Merkle tree. It uses the parent and sibling nodes in the additional information of the leaf node to traverse the Merkle tree in order to collect the Merkle path. Finally, it packages the queried data and its Merkle path and sends it to the requesting chain. After receiving the request, the requesting chain performs Merkle verification. If the verification is successful, it proves the correctness of the current cross-chain information inspection data.

5. The method for cross-chain data correctness verification based on nested Merkle trees as described in claim 4, characterized in that, Merkle verification specifically involves: hashD = Hash(d) (1) currRootHash==Hash(hashD+Hash(Hash(b)+preRootHash)) (2) Where: hashD is the hash of the target data d, Hash(d) and Hash(b) are the hashes of the target data d and its sibling node data b, currRootHash is the hash root of the current Merkle tree, preRootHash is the hash root of the previous Merkle tree, and the Merkle path of the target data d contains hashD, Hash(Hash(b)+preRootHash), and currRootHash; If both sides of equation (2) are equal, then the verification is considered successful.

Citation Information

Patent Citations

  • Method and device for maintaining network architecture information of block chain system

    CN113609231A