Cross-chain transfer method, computer device and storage medium
By synchronizing cross-chain transactions on the second layer network and updating the status tree root hash, combined with the zero-knowledge proof circuit, the centralized risk and convenience of blockchain cross-chain transfers are solved, and efficient and secure cross-chain transactions are achieved.
Patent Information
- Application Number
- CN202111167266.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-04
- Publication Date
- 2025-09-02
- Estimated Expiration
- 2041-10-04
AI Technical Summary
The existing blockchain cross-chain transfer methods have the problems of centralization risk and inconvenience in use, especially the limitations of hash locking and cross-chain bridges in large-scale applications.
The cross-chain transfer method of the second-layer network is adopted, and the state tree root hash of the main chain and the second-layer network is updated by synchronizing cross-chain transactions, and a zero-knowledge proof circuit is deployed on the second-layer network to realize the decentralization and convenience of cross-chain transactions.
It realizes decentralization and convenience of cross-chain transfers, reduces the complexity of data storage and verification, and improves the efficiency and security of cross-chain transactions.
Smart Images

Figure CN115936696B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology, and specifically to a cross-chain transfer method, computer equipment, and storage medium. Background Art
[0002] There are currently many ways to implement cross-chain blockchains, such as hash locking and cross-chain bridges.
[0003] Hash locking is not suitable for large-scale use and is inconvenient; cross-chain bridges rely on some trusted accounts to transmit messages between chains, which poses some centralization risks. Summary of the Invention
[0004] In view of the above-mentioned defects or deficiencies in the prior art, it is desired to provide a decentralized and convenient cross-chain transfer method, computer device and storage medium.
[0005] In a first aspect, the present invention provides a cross-chain transfer method applicable to nodes of a layer 2 network, wherein the layer 2 network has state trees corresponding to respective main chains, and the initial root hash of each state tree is the same, and the method comprises:
[0006] Synchronize a first cross-chain transaction from the first main chain; wherein the first cross-chain transaction includes the first main chain name of the first main chain where it is located and the second main chain name of the second main chain to be cross-chained;
[0007] Execute a first cross-chain transaction to obtain a plurality of first state data, and update a first state tree of the first main chain according to each first state data to update a first root hash of the first state tree, and update a second state tree of the second main chain according to each first state data to update a second root hash of the second state;
[0008] Update the state hash of the unified ledger of the second-layer network based on the first and second root hashes;
[0009] The first state data and the state hash are sent to the first main chain and the second main chain, so that the first main chain node of the first main chain and the second main chain node of the second main chain execute the first cross-chain transaction according to the first state data and the state hash.
[0010] In a second aspect, the present invention also provides a device comprising one or more processors and a memory, wherein the memory contains instructions executable by the one or more processors so that the one or more processors execute the cross-chain transfer method provided according to various embodiments of the present invention.
[0011] In a third aspect, the present invention further provides a storage medium storing a computer program, which enables a computer to execute the cross-chain transfer method provided according to various embodiments of the present invention.
[0012] The cross-chain transfer method, computer device, and storage medium provided by many embodiments of the present invention synchronize a first cross-chain transaction from a first main chain; execute the first cross-chain transaction to obtain a plurality of first state data, and update the first state tree of the first main chain according to each first state data to update the first root hash of the first state tree, and update the second state tree of the second main chain according to each first state data to update the second root hash of the second state; update the state hash of the unified ledger of the second-layer network according to the first root hash and the second root hash; and send each first state data and state hash to the first main chain and the second main chain, so that the cross-chain transfer is decentralized and easy to use. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] Other features, objects and advantages of the present application will become more apparent upon reading the detailed description of non-limiting embodiments made with reference to the following drawings:
[0014] Figure 1 This is a flowchart of a cross-chain transfer method provided by one embodiment of the present invention.
[0015] Figure 2 for Figure 1 A flow chart of a preferred embodiment of the method is shown.
[0016] Figure 3 for Figure 1 A flow chart of another preferred embodiment of the method is shown.
[0017] Figure 4 for Figure 1 A flow chart of another preferred embodiment of the method is shown.
[0018] Figure 5 A schematic diagram of the structure of a computer device provided in one embodiment of the present invention. DETAILED DESCRIPTION
[0019] The present application will be further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are merely for the purpose of explaining the relevant invention and are not intended to limit the invention. It should also be noted that, for ease of description, only portions relevant to the invention are shown in the accompanying drawings.
[0020] It should be noted that, in the absence of conflict, the embodiments and features of the embodiments in this application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0021] Figure 1 This is a flow chart of a cross-chain transfer method provided by one embodiment of the present invention. Figure 1As shown, in this embodiment, the present invention provides a cross-chain transfer method applicable to nodes of a second-layer network. The second-layer network has state trees corresponding to each main chain, and the initial root hash of each state tree is the same. The above method includes:
[0022] S11: Synchronize a first cross-chain transaction from the first main chain; wherein the first cross-chain transaction includes the first main chain name of the first main chain where it is located and the second main chain name of the second main chain to be cross-chained;
[0023] S13: Execute a first cross-chain transaction to obtain a plurality of first state data, and update the first state tree of the first main chain according to each first state data to update the first root hash of the first state tree, and update the second state tree of the second main chain according to each first state data to update the second root hash of the second state;
[0024] S15: Update the state hash of the unified ledger of the second-layer network based on the first and second root hashes;
[0025] S17: Send the first state data and the state hash to the first main chain and the second main chain, so that the first main chain node of the first main chain and the second main chain node of the second main chain can execute the first cross-chain transaction according to the first state data and the state hash.
[0026] Assume there are two main chains, A and B. Chain A runs asset AAA, and Chain B runs asset BBB. The exchange ratio of AAA to BBB is 1:1. Chain A is the first main chain, and Chain B is the second main chain. The first cross-chain transaction tx1 is user A's wish to exchange 1 AAA for the corresponding BBB. On the second-layer network, there are the state tree TreeA of Chain A and the state tree TreeB of Chain B. The initial root hash of TreeA and TreeB is the same.
[0027] The nodes in the Layer 2 network execute step S11 and synchronize tx1 from chain A.
[0028] The nodes in the Layer 2 network execute step S13, executing tx1 to obtain some state data. Assume that before executing tx1, the state data of User A in Chain A on the Layer 2 network is 10AAA, and the state data of Chain B on the Layer 2 network is 10BBB. Then, after executing tx1, the state data obtained are 9AAA and 11BBB. The nodes in the Layer 2 network update TreeA based on 9AAA and 11BBB to update the root hash A of TreeA, and update TreeB to update the root hash B of TreeB.
[0029] The nodes of the second-layer network execute step S15 to update the state hash of the unified ledger of the second-layer network based on the root hash A and the root hash B. Assume that statehash = hash(roothashA + roothash(B)), where statehash is the state hash of the unified ledger of the second-layer network, roothashA is the root hash A, and roothashB is the root hash B. Those skilled in the art will appreciate that the method for updating statehash is not limited to the above example and can be configured according to actual needs. As long as it is generated based on roothashA and roothashB, the same technical effect can be achieved.
[0030] The nodes in the Layer 2 network execute step S17 and send 9AAA, 11BBB, and statehash to Chain A and Chain B.
[0031] The nodes of chain A and chain B calculate statehash' based on the previous state hash statehash', 9AAA, and 11BBB. When statehash and statehash' are the same, tx1 is executed. Those skilled in the art should understand that statehash' can be sent by nodes in the second-layer network, or stored by nodes in chain A and chain B, which can achieve the same technical effect.
[0032] The above embodiments make cross-chain transfers decentralized and convenient to use.
[0033] Figure 2 for Figure 1 A flow chart of a preferred embodiment of the method shown is shown. Figure 2 As shown, in a preferred embodiment, the nodes of the second-layer network respectively store a global index table of the state tree of each block of each main chain. The state data is stored in the form of Merkle Mountains. The global index table uses the block height of the main chain to which it belongs as the version number. S11 includes:
[0034] S111: Synchronizing a plurality of first cross-chain transactions from a first block at a first height of a first main chain;
[0035] S13 includes:
[0036] S1311: Perform the following operations on each first cross-chain transaction: execute the first cross-chain transaction to obtain a number of first state data;
[0037] S1312: Update the first Merkle range according to the first state data obtained by executing the first cross-chain transactions;
[0038] S1313: Generate a first Merkle binary tree and a first Merkle root of the first Merkle binary tree according to each root node of the first Merkle mountain range;
[0039] S1314: updating the second Merkle range according to each first state data;
[0040] S1315: Generate a second Merkle binary tree and a second Merkle root of the second Merkle binary tree according to the root nodes of the second Merkle mountain range.
[0041] It should be noted that at this time, the value of the first Merkle root will be used as the first hash, and the value of the second Merkle root will be used as the second hash.
[0042] The above embodiments and Figure 1 The embodiment shown differs in that Figure 1 In the illustrated embodiment and prior art, a Merkle binary tree is generally used to verify the existence of state data. This requires a very large data tree. Furthermore, in prior art, MMRs are generally used to verify the existence of transactions. In this embodiment, however, MMRs are used to verify the existence of state information. If only MMRs were used to verify the existence of state information, assuming a total of 400 million data points (approximately 32 root nodes), the MMR would be very large, requiring at least (32+32)*32, or approximately 2k of data. However, using the method illustrated in this embodiment to construct an MMR, only (32+5)*32 is required, resulting in a lower MMR height and less data.
[0043] Figure 3 for Figure 1 Flow chart of another preferred embodiment of the method shown. Figure 3 As shown, in a preferred embodiment, the nodes of the second-layer network respectively store the global index table of the state tree of each block of each main chain. The global index table uses the block height of the main chain to which it belongs as the version number. S11 includes:
[0044] S112: Synchronizing a plurality of first cross-chain transactions from a first block at a first height of a first main chain;
[0045] S13 includes:
[0046] S1321: Perform the following operations on each first cross-chain transaction: execute the first cross-chain transaction to obtain a number of first state data;
[0047] S1322: Generate a third Merkle binary tree and a third Merkle root of the third Merkle binary tree based on the first state data obtained from executing the first cross-chain transactions;
[0048] S1323: Set the third Merkle root as the first leaf node of the first Merkle range to which it belongs;
[0049] S1324: Update the first Merkle range according to the first leaf node;
[0050] S1325: Generate a first Merkle binary tree and a first Merkle root of the first Merkle binary tree according to each root node of the updated first Merkle mountain range;
[0051] S1326: Generate a fourth Merkle binary tree and a fourth Merkle root of the fourth Merkle binary tree based on the first state data obtained from executing the first cross-chain transactions;
[0052] S1327: Set the fourth Merkle root as the second leaf node of the second Merkle range to which it belongs;
[0053] S1328: Update the second Merkle range according to the second leaf node;
[0054] S1329: Generate a second Merkle binary tree and a second Merkle root of the second Merkle binary tree according to the root nodes of the updated second Merkle mountain range.
[0055] It should be noted that at this time, the value of the first Merkle root will be used as the first hash, and the value of the second Merkle root will be used as the second hash.
[0056] Figure 3 The embodiment shown is Figure 2 The embodiment shown differs in that, according to Figure 3 The MMR constructed by the method of the illustrated embodiment has fewer root nodes and a smaller MMR.
[0057] Further preferably, after the first period of time, the third Merkle binary tree and the fourth Merkle binary tree are saved in a distributed manner with other nodes.
[0058] Preferably, an automated market maker contract is deployed on the second-layer network; wherein the automated market maker contract is deployed with the exchange ratio of each asset between different main chains.
[0059] In the above embodiment, an automated market maker contract AMM is deployed in the second-layer network. Users can store a number of assets in it to earn interest, or they can store a type of asset and automatically exchange it for other types of assets through the AMM.
[0060] Figure 4 for Figure 1 Flow chart of another preferred embodiment of the method shown. Figure 4 As shown, in a preferred embodiment, both the main chain and the second layer network are configured with a zero-knowledge proof circuit for verifying cross-chain transfers, and S17 includes:
[0061] S171: Generate first zero-knowledge proof evidence according to each first state data, state hash, and previous state hash of the state hash;
[0062] S172: Send the first zero-knowledge proof evidence to the first main chain and the second main chain, so that the first main chain node and the second main chain node input the first zero-knowledge proof evidence into the zero-knowledge proof circuit for verification: when the verification passes, execute the first cross-chain transaction according to each first state data and state hash.
[0063] Take S171 as an example, which includes "generating first public input information based on the cross-chain identifier, the state hash, the previous state hash of the state hash, and each first state data; generating first private input information based on the cross-chain identifier, the state hash, the previous state hash, the first state tree, the second state tree, each first state data, the previous state data of each first state data, the first cross-chain transaction, and the cross-chain amount specified by the first cross-chain transaction; generating first zero-knowledge proof evidence based on the first public input information and the first private input information."
[0064] Those skilled in the art will understand that after deploying the above zero-knowledge proof circuit, the nodes of the second-layer network and the nodes of each main chain should generate random parameters Sp and Sv that will be used subsequently;
[0065] The node in the second-layer network executes step S171 and generates public input information pubinput according to the cross-chain identifier op:cross, statehash, the previous state hash statehash', 9AAA, and 11BBB;
[0066] The nodes of the second-layer network generate private input information pri input based on op:cross, statehash, statehash', treeA, treeB, each state data (9AAA, 11BBB), the previous state data of each state data (10AAA, 10BBB), tx1, and the cross-chain amount;
[0067] The nodes in the Layer 2 network generate zero-knowledge proof evidence based on Sp, pub input, and pri input, i.e., prove(Sp,x,w)>π, where x is the pub input and w is the pri input. It should be understood by those skilled in the art that tx1 in pri input can also be replaced with an identifier such as hash(tx1) that can be used to find tx1 based on actual needs, thereby achieving the same technical effect.
[0068] The nodes in the Layer 2 network execute step S172 and send the zero-knowledge proof to Chain A and Chain B.
[0069] The nodes of chain A and chain B input the above zero-knowledge proof evidence into the zero-knowledge proof circuit for verification, that is, verify(Sv,x,π)=verify(Sv,x,prove(Sp,x,w))=yes?
[0070] When the execution is yes, the node of chain A executes tx1 according to 9AAA, 11BBB, and statehash;
[0071] It should be noted that the execution of verify(Sv,x,π)=verify(Sv,x,prove(Sp,x,w))=yes? actually verifies the following:
[0072] Verify the signature information of cross-chain transactions;
[0073] Verify that the value calculated based on statehash', 9AAA, and 11BBB is the same as statehash.
[0074] Those skilled in the art should understand that the method described in this embodiment can also be configured to generate zero-knowledge proof evidence for several cross-chain transactions according to actual needs. Assuming that treeA, treeB, and statehash are generated based on cross-chain transactions tx11 to tx20, the public input information of the zero-knowledge proof evidence should include op:cross, statehash, statehash', and the state data generated by executing tx11 to tx20. The private input information should include op:cross, statehash, statehash', treeA, treeB, the state data generated by executing tx11 to tx20, the previous state data of each state data, tx11 to tx20, and the cross-chain amounts corresponding to tx11 to tx20 respectively; the same technical effect can be achieved.
[0075] Figure 5 A schematic diagram of the structure of a computer device provided in one embodiment of the present invention.
[0076] like Figure 5 As shown, as another aspect, the present application also provides a computer device, including one or more central processing units (CPUs) 501, which can perform various appropriate actions and processes according to programs stored in a read-only memory (ROM) 502 or programs loaded from a storage portion 508 into a random access memory (RAM) 503. Various programs and data required for the operation of the computer device are also stored in the RAM 503. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0077] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, and the like; an output section 507 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and a speaker; a storage section 508 including a hard disk; and a communication section 509 including a network interface card such as a LAN card or a modem. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 510 as needed, so that computer programs read therefrom can be installed into the storage section 508 as needed.
[0078] In particular, according to embodiments of the present disclosure, the methods described in any of the above embodiments can be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program tangibly embodied on a machine-readable medium, the computer program comprising program code for executing any of the above methods. In such embodiments, the computer program can be downloaded and installed from a network via the communication portion 509 and / or installed from the removable medium 511.
[0079] As another aspect, the present application further provides a computer-readable storage medium, which may be the computer-readable storage medium included in the apparatus of the above-described embodiment; or a computer-readable storage medium that exists independently and is not incorporated into a computer device. The computer-readable storage medium stores one or more programs, which are used by one or more processors to execute the methods described in the present application.
[0080] The flow charts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, program segment or a part of code, and the module, program segment or a part of code contains one or more executable instructions for realizing the prescribed logical functions. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a sequence different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented by a dedicated hardware-based system that performs the prescribed function or operation, or can be implemented by a combination of dedicated hardware and computer instructions.
[0081] The units or modules involved in the embodiments described in this application may be implemented in software or hardware. The units or modules described may also be provided in a processor. For example, each of the units may be a software program provided in a computer or mobile smart device, or a separately configured hardware device. The names of these units or modules do not, in certain circumstances, constitute limitations on the units or modules themselves.
[0082] The above description is merely a preferred embodiment of the present application and an illustration of the technical principles employed. Those skilled in the art should understand that the scope of the invention involved in this application is not limited to the technical solutions formed by the specific combination of the above-mentioned technical features, but also encompasses other technical solutions formed by any combination of the above-mentioned technical features or their equivalents without departing from the concept of this application. For example, a technical solution formed by replacing the above-mentioned features with (but not limited to) technical features with similar functions disclosed in this application.
Claims
1. A cross-chain transfer method, characterized in that: There are state trees corresponding to respective main chains on the second-layer network, and the initial root hash of each state tree is the same. The method is applicable to nodes of the second-layer network, and the method includes: Synchronize a first cross-chain transaction from the first main chain; wherein the first cross-chain transaction includes the first main chain name of the first main chain where the transaction is located and the second main chain name of the second main chain to be cross-chained; Executing the first cross-chain transaction to obtain a plurality of first state data, and updating the first state trie of the first main chain according to each of the first state data to update the first root hash of the first state trie, and updating the second state trie of the second main chain according to each of the first state data to update the second root hash of the second state; and updating the state hash of the unified ledger of the second-layer network according to the first root hash and the second root hash; Sending each of the first state data and the state hash to the first main chain and the second main chain, so that the first main chain node of the first main chain and the second main chain node of the second main chain execute the first cross-chain transaction according to each of the first state data and the state hash.
2. The method according to claim 1, characterized in that The nodes of the second-layer network respectively store a global index table of the state tree of each block of each main chain. The state data is stored in the form of Merkle Mountains. The global index table uses the block height of the main chain to which it belongs as the version number. The synchronization of the first cross-chain transaction from the first main chain includes: Synchronize a plurality of first cross-chain transactions from the first block at the first height of the first main chain; The performing of the first cross-chain transaction to obtain a plurality of first state data, updating the first state tree of the first main chain according to each of the first state data to update the first root hash of the first state tree, and updating the second state tree of the second main chain according to each of the first state data to update the second root hash of the second state includes: Perform the following operations on each of the first cross-chain transactions: execute the first cross-chain transaction to obtain a plurality of first state data; Updating a first Merkle range according to each of the first state data obtained by executing each of the first cross-chain transactions; Generate a first Merkle binary tree and a first Merkle root of the first Merkle binary tree according to each root node of the first Merkle mountain range; updating a second Merkle range according to each of the first state data; A second Merkle binary tree and a second Merkle root of the second Merkle binary tree are generated according to the root nodes of the second Merkle tree.
3. The method according to claim 1, characterized in that The nodes of the second-layer network respectively store a global index table of the state tree of each block of each main chain. The global index table uses the block height of the main chain to which it belongs as the version number. Synchronizing the first cross-chain transaction from the first main chain includes: Synchronize a plurality of first cross-chain transactions from the first block at the first height of the first main chain; The performing of the first cross-chain transaction to obtain a plurality of first state data, updating the first state tree of the first main chain according to each of the first state data to update the first root hash of the first state tree, and updating the second state tree of the second main chain according to each of the first state data to update the second root hash of the second state includes: Perform the following operations on each of the first cross-chain transactions: execute the first cross-chain transaction to obtain a plurality of first state data; Generate a third Merkle binary tree and a third Merkle root of the third Merkle binary tree based on each of the first state data obtained by executing each of the first cross-chain transactions; Taking the third Merkle root as the first leaf node of the first Merkle mountain range to which it belongs; Updating the first Merkle range according to the first leaf node; Generate a first Merkle binary tree and a first Merkle root of the first Merkle binary tree according to each root node of the updated first Merkle mountain range; Generate a fourth Merkle binary tree and a fourth Merkle root of the fourth Merkle binary tree based on each of the first state data obtained by executing each of the first cross-chain transactions; Taking the fourth Merkle root as the second leaf node of the second Merkle range to which it belongs; Updating the second Merkle range according to the second leaf node; A second Merkle binary tree and a second Merkle root of the second Merkle binary tree are generated according to the updated root nodes of the second Merkle mountain range.
4. The method according to claim 3, characterized in that Also includes: After the first period of time, the third Merkle binary tree and the fourth Merkle binary tree are distributed and saved with other nodes.
5. The method according to claim 1, wherein An automated market maker contract is deployed on the second-layer network; wherein, the automated market maker contract is deployed with the exchange ratio of each asset between different main chains.
6. The method according to any one of claims 1 to 5, characterized in that The main chain and the second-layer network are both configured with a zero-knowledge proof circuit for verifying cross-chain transfers. The sending of each of the first state data and the state hash to the first main chain and the second main chain so that the first main chain node of the first main chain and the second main chain node of the second main chain execute the first cross-chain transaction according to each of the first state data and the state hash includes: Generate a first zero-knowledge proof evidence according to each of the first state data, the state hash, and a previous state hash of the state hash; The first zero-knowledge proof evidence is sent to the first main chain and the second main chain, so that the first main chain node and the second main chain node input the first zero-knowledge proof evidence into the zero-knowledge proof circuit for verification: when the verification passes, the first cross-chain transaction is executed according to each of the first state data and the state hash.
7. The method according to claim 6, characterized in that Generating the first zero-knowledge proof evidence according to the first state data, the state hash, and the state hash before the state hash includes: Generate first public input information according to the cross-chain identifier, the state hash, the previous state hash of the state hash, and each of the first state data; Generate first private input information based on the cross-chain identifier, the state hash, the previous state hash, the first state tree, the second state tree, each piece of the first state data, the previous state data of each piece of the first state data, the first cross-chain transaction, and the cross-chain amount specified by the first cross-chain transaction; A first zero-knowledge proof evidence is generated according to the first public input information and the first private input information.
8. A computer device, characterized in that: The device comprises: one or more processors; a memory for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors are caused to perform the method according to any one of claims 1 to 7.
9. A storage medium storing a computer program, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Cross-chain gateway interaction system and method and supply chain data management method
CN111445328A
Transaction method, device and system based on block chain and readable storage medium
CN112669157A