Multi-main chain cross-chain method, computer device and storage medium
By introducing multi-main chain solutions and zero-knowledge proof circuits to verify transaction information in the second-layer network, the high cost and double-spending problems of existing cross-chain solutions are solved, and the consistency of multiple main chain ledgers and the correctness of transactions are achieved. Prevent cheating by operators.
Patent Information
- Application Number
- CN202111456551.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-02
- Publication Date
- 2024-10-25
- Estimated Expiration
- 2041-12-02
AI Technical Summary
Existing cross-chain solutions based on the second-layer network are generally one-to-one, resulting in high costs and double-spending problems, and cannot effectively prevent verification failures during asset exchange after operators cheat on deposits.
Introduce a multi-main chain solution into the second-layer network, use state trees and cross-chain verification contracts, and use zero-knowledge proof circuits to verify transaction information, ensure the correctness of transaction sequences and information, prevent double spending, and roll back the state tree when necessary to restore the original condition.
It achieves the prevention of double spending on the basis of cost saving, ensures the consistency of the ledgers of multiple main chains and the correctness of transactions, and avoids cheating by operators.
Smart Images

Figure CN114138903B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology, and specifically to a multi-main chain cross-chain method, computer equipment and storage medium. Background Art
[0002] The current cross-chain solution based on the second-layer network is generally one-to-one, with one second-layer network corresponding to one main chain. The applicant hopes to propose a cross-chain solution in which one second-layer network corresponds to multiple main chains. Compared with the existing technology, the above solution saves more costs, but there is also the problem of double spending. Summary of the invention
[0003] In view of the above-mentioned defects or deficiencies in the prior art, it is desirable to provide a multi-main chain cross-chain method, computer device and storage medium for preventing double spending on the basis of cost saving.
[0004] In a first aspect, the present invention provides a multi-main chain cross-chain method applicable to nodes of a second-layer network, wherein there are state trees corresponding to each main chain on the second-layer network, the initial root hash of each state tree is the same, each main chain is configured with a cross-chain verification contract, and a zero-knowledge proof circuit for verifying transaction information is deployed in the cross-chain verification contract, and the above method includes:
[0005] When it is detected that the first main chain has generated a first main chain block, the first transactions in the first main chain block that need to call transfer contracts are synchronized in order; wherein the transfer contracts include deposit contracts, withdrawal contracts, transfer contracts, and cross-chain transfer contracts;
[0006] Perform the following operations on each first transaction:
[0007] Determine whether the transfer contract called by the first transaction is a cross-chain transfer contract:
[0008] If no, execute the first transaction to update the first state tree of the first main chain on the second layer network;
[0009] If yes, execute the first transaction to update the first state tree of the first main chain on the second-layer network, and the second state tree of the second main chain to be cross-chained specified by the first transaction;
[0010] Generate zero-knowledge proof evidence according to the transaction information of each first transaction in sequence, and generate first proof data according to each first transaction and the zero-knowledge proof evidence in sequence;
[0011] The first proof data is sent to the first main chain and other main chains for the main chain node of the first main chain to:
[0012] The cross-chain verification contract is used to determine whether the order of each first transaction in the first proof data is the same as that of each first transaction in the first main chain block:
[0013] If the transaction information of each first transaction in the first proof data is the same, the zero-knowledge proof evidence is input into the zero-knowledge proof circuit to verify whether the transaction information of each first transaction in the first proof data is correct:
[0014] If the verification is correct, then end;
[0015] The first proof data is also used to provide the main chain nodes of other main chains:
[0016] Input the zero-knowledge proof evidence into the zero-knowledge proof circuit to verify whether the transaction information of each first transaction in the first proof data is correct:
[0017] If the verification is correct, each first transaction is executed.
[0018] 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 multi-main chain cross-chain method provided according to various embodiments of the present invention.
[0019] In a third aspect, the present invention also provides a storage medium storing a computer program, which enables a computer to execute the multi-main chain cross-chain method provided according to various embodiments of the present invention.
[0020] The multi-main chain cross-chain method, computer device and storage medium provided by many embodiments of the present invention sequentially synchronize the first transactions in the first main chain block that need to call the transfer contract when monitoring that the first main chain has generated the first main chain block; perform the following operations on each first transaction: determine whether the transfer contract called by the first transaction is a cross-chain transfer contract: if not, execute the first transaction to update the first state tree of the first main chain on the second-layer network; if yes, execute the first transaction to update the first state tree of the first main chain on the second-layer network, and the second state tree of the second main chain to be cross-chain specified by the first transaction; generate zero-knowledge proof evidence in sequence according to the transaction information of each first transaction, and generate first proof data according to the first transactions and zero-knowledge proof evidence in sequence; send the first proof data to the first main chain and other main chains, so as to prevent double spending on the basis of saving costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Other features, objects and advantages of the present application will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings:
[0022] Figure 1 A flowchart of a multi-main chain cross-chain method provided by one embodiment of the present invention.
[0023] Figure 2 A schematic diagram of the structure of a device provided in one embodiment of the present invention. DETAILED DESCRIPTION
[0024] The present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the relevant invention, rather than to limit the invention. It is also necessary to explain that, for ease of description, only the parts related to the invention are shown in the accompanying drawings.
[0025] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present 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.
[0026] The applicant hopes to propose a cross-chain solution in which one layer 2 network corresponds to multiple main chains. Compared with the existing technology, the above solution is more cost-saving, but there is also the problem of double spending - if the operator cheats and deposits and exchanges with assets from another chain, the other chain will not be able to verify. For example, suppose there are 3 main chains (chain A, chain B, and chain C); asset AAA runs on chain A, asset BBB runs on chain B, and asset CCC runs on chain C. The exchange ratio of AAA to BBB to CCC is 1:1:1; suppose the operator privately deposits 100AAA in the layer 2 network and immediately exchanges it with BBB of a user in the layer 2 network. The 100AAA is extra out of thin air and will eventually fail to be verified on chain A, but the operator has already exchanged 100BBB and submitted it to chain B, causing harm to chain B.
[0027] The above problems can be solved by various embodiments of the present application.
[0028] Figure 1 This is a flow chart of a multi-main chain cross-chain method provided by one embodiment of the present invention. Figure 1 As shown, in this embodiment, the present invention provides a multi-main chain cross-chain method applicable to nodes of a second-layer network, where there are state trees corresponding to each main chain on the second-layer network, the initial root hash of each state tree is the same, each main chain is configured with a cross-chain verification contract, and a zero-knowledge proof circuit for verifying transaction information is deployed in the cross-chain verification contract, and the above method includes:
[0029] S11: when it is detected that the first main chain has generated a first main chain block, the first transactions in the first main chain block that need to call transfer contracts are synchronized in order; wherein the transfer contracts include deposit contracts, withdrawal contracts, transfer contracts, and cross-chain transfer contracts;
[0030] Perform the following operations on each first transaction:
[0031] S131: Determine whether the transfer contract called by the first transaction is a cross-chain transfer contract:
[0032] If no, then execute step S132: execute the first transaction to update the first state tree of the first main chain on the second layer network;
[0033] If yes, then execute step S133: execute the first transaction to update the first state tree of the first main chain on the second-layer network, and the second state tree of the second main chain to be cross-chained specified by the first transaction;
[0034] S15: Generate zero-knowledge proof evidence according to the transaction information of each first transaction in sequence, and generate first proof data according to each first transaction and the zero-knowledge proof evidence in sequence;
[0035] S17: Send the first proof data to the first main chain and other main chains, so that the main chain node of the first main chain:
[0036] The cross-chain verification contract is used to determine whether the order of each first transaction in the first proof data is the same as that of each first transaction in the first main chain block:
[0037] If the transaction information of each first transaction in the first proof data is the same, the zero-knowledge proof evidence is input into the zero-knowledge proof circuit to verify whether the transaction information of each first transaction in the first proof data is correct:
[0038] If the verification is correct, then end;
[0039] The first proof data is also used to provide the main chain nodes of other main chains:
[0040] Input the zero-knowledge proof evidence into the zero-knowledge proof circuit to verify whether the transaction information of each first transaction in the first proof data is correct:
[0041] If the verification is correct, each first transaction is executed.
[0042] Specifically, assume that there are three main chains (chain A, chain B, and chain C); chain A has asset AAA, chain B has asset BBB, and chain C has asset CCC, and the exchange ratio of AAA to BBB to CCC is 1:1:1; on the second-layer network, there is a state tree TreeA of chain A, a state tree TreeB of chain B, and a state tree TreeC of chain C, and the initial root hashes of TreeA, TreeB, and TreeC are the same; the first main chain mentioned above is chain A, and the main chain nodes of chain A sequentially generate the main chain block block (100) according to tx1~tx10, where tx1 and tx2 are transactions that need to call transfer contracts, tx1 is user A's request to deposit 100 AAA, and tx2 is user B's request to withdraw 10 AAA;
[0043] The node of the second layer network executes step S11, and upon detecting that the A chain has generated block (100), synchronizes tx1 and tx2;
[0044] Take tx1 as an example:
[0045] The node of the second-layer network executes step S131 to determine whether the transfer contract called by tx1 is a cross-chain transfer contract:
[0046] Since the transfer contract called by tx1 is a deposit contract, step S132 is executed: tx1 is executed (that is, the status data of user A + 100) to update TreeA on the second-layer network;
[0047] The same is true for tx2, which will not be repeated here;
[0048] The node of the second-layer network executes step S15, generates zero-knowledge proof evidence proof1 according to the transaction information of tx1 and tx2, and generates proof data proofchunk1 according to tx1, tx2 and zero-knowledge proof evidence; It should be understood by those skilled in the art that the transaction information can be configured according to actual needs, generally including the transaction sender address, the transaction receiver address, the transaction type, and the amount;
[0049] The nodes of the second-layer network execute step S17 and send proofchunk1 to chain A, chain B, and chain C;
[0050] The main chain node of chain A verifies through the cross-chain verification contract whether tx1 and tx2 are in the same order as tx1 and tx2 in block (100);
[0051] Since they are the same, the zero-knowledge proof proof1 is input into the zero-knowledge proof circuit to verify whether the transaction information of tx1 and tx2 in the proof data is correct;
[0052] Assuming the verification is correct, then end.
[0053] Since the main chain nodes of chain B and chain C do not have the order of transactions in block (100), the main chain nodes of chain B and chain C input the zero-knowledge proof proof1 into the zero-knowledge proof circuit to verify whether the transaction information of tx1 and tx2 in the proof data is correct:
[0054] Assuming the verification is correct, execute tx1 and tx2.
[0055] The above embodiment enables multiple main chains to maintain a common ledger on the second-layer network, saving costs; and the second-layer network can continue to operate normally only when the transaction sequence and transaction information are correct, preventing double spending.
[0056] Preferably, the above method further comprises:
[0057] When a different order is detected or verification fails, the first state tree is rolled back, or the first state tree and the second state tree are rolled back to the state when each first transaction is not executed;
[0058] Return to sequentially synchronize the first transactions in the first main chain block that need to call the transfer contract to regenerate the zero-knowledge proof evidence and the first proof data;
[0059] After receiving the regenerated first proof data, the main chain nodes of other main chains verify whether the transaction information of each first transaction in the first proof data is correct, and further include:
[0060] Roll back the main chain to the state before the first transaction is executed.
[0061] Specifically, taking block (100) as an example, when the nodes of the second-layer network detect that the order is different or the verification fails, they roll back TreeA and TreeB on the second-layer network to the state before tx1 and tx2 are executed;
[0062] The nodes of the second-layer network return to the step of "synchronizing the first transaction in the first main chain block that needs to call the transfer contract in sequence"; finally, the nodes of the second-layer network will regenerate proof1 and proofchunk1;
[0063] After receiving the regenerated proofchunk2, the main chain nodes of chain B and chain C need to roll back their respective main chains to the state before executing tx1 and tx2 before verifying whether the transaction information of tx1 and tx2 in proofchunk1 is correct.
[0064] Those skilled in the art should understand that, taking the B chain as an example, if the main chain node of the B chain receives the regenerated first proof data, if there is tx3 (the execution of tx3 requires the execution result of tx1), the main chain node of the B chain should also roll back tx3.
[0065] Preferably, before inputting the zero-knowledge proof evidence into the zero-knowledge proof circuit to verify whether the transaction information of each first transaction in the first proof data is correct, the other main chain nodes further include:
[0066] Receiving each first transaction sent by a main chain node of the first main chain or by a relay server;
[0067] The main chain nodes of other main chains input the zero-knowledge proof evidence into the zero-knowledge proof circuit to verify whether the transaction information of each first transaction in the first proof data is correct, including:
[0068] The cross-chain verification contract is used to determine whether the order of each first transaction in the first proof data is the same as that of each first transaction sent by the first main chain node or relay server:
[0069] If the first transaction information is the same, the zero-knowledge proof evidence is input into the zero-knowledge proof circuit to verify whether the transaction information of each first transaction in the first proof data is correct.
[0070] Specifically, before the main chain nodes of chain B and chain C execute "inputting the zero-knowledge proof evidence into the zero-knowledge proof circuit to verify whether the transaction information of each first transaction in the first proof data is correct", they also include:
[0071] Receive tx1 and tx2 sent by the main chain node of chain A or by the relay server;
[0072] At this point, the main chain nodes of chain B and chain C have a transaction order, and the main chain nodes of chain B and chain C are the same as the main chain nodes of chain A. The cross-chain verification contract can also be used to determine whether the order of tx1 and tx2 in proofchunk1 is the same as that of tx1 and tx2 sent by the main chain node of chain A or the relay server.
[0073] Preferably, the nodes of the second-layer network pay a certain amount of deposit on each main chain. When the main chain node of the first main chain detects a different order or verification fails, the first amount of deposit is deducted; when the main chain nodes of other main chains fail to verify, the first amount of deposit is deducted.
[0074] Assuming that the main chain nodes of chain A to chain C all fail to verify, the main chain nodes of chain A to chain C will deduct the first amount of deposit from the nodes of the second-layer network.
[0075] The above embodiment punishes the nodes of the second layer network to further prevent double spending.
[0076] Figure 2 A schematic diagram of the structure of a device provided in one embodiment of the present invention.
[0077] like Figure 2 As shown, as another aspect, the present application also provides a device 200, including one or more central processing units (CPU) 201, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 202 or the program loaded from the storage part 208 to the random access memory (RAM) 203. In the RAM 203, various programs and data required for the operation of the device 200 are also stored. The CPU 201, the ROM 202, and the RAM 203 are connected to each other through a bus 204. An input / output (I / O) interface 205 is also connected to the bus 204.
[0078] The following components are connected to the I / O interface 205: an input section 206 including a keyboard, a mouse, etc.; an output section 207 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 208 including a hard disk, etc.; and a communication section 209 including a network interface card such as a LAN card, a modem, etc. The communication section 209 performs communication processing via a network such as the Internet. A drive 210 is also connected to the I / O interface 205 as needed. A removable medium 211, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 210 as needed, so that a computer program read therefrom is installed into the storage section 208 as needed.
[0079] In particular, according to an embodiment of the present disclosure, the method described in any of the above embodiments can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program tangibly contained on a machine-readable medium, and the computer program includes a program code for executing any of the above methods. In such an embodiment, the computer program can be downloaded and installed from a network through the communication part 209, and / or installed from the removable medium 211.
[0080] As another aspect, the present application also provides a computer-readable storage medium, which may be a computer-readable storage medium included in the apparatus of the above embodiment; or a computer-readable storage medium that exists independently and is not assembled into the device. The computer-readable storage medium stores one or more programs, which are used by one or more processors to execute the method described in the present application.
[0081] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square 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 square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be realized by a dedicated hardware-based system that performs a specified function or operation, or can be realized by a combination of dedicated hardware and computer instructions.
[0082] The units or modules involved in the embodiments described in the present application may be implemented by software or by hardware. The units or modules described may also be arranged in a processor. For example, each of the units may be a software program arranged in a computer or a mobile smart device, or may be a separately configured hardware device. The names of these units or modules do not, in some cases, constitute limitations on the units or modules themselves.
[0083] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the concept of the present application. For example, the above features are replaced with the technical features with similar functions disclosed in the present application (but not limited to) to form a technical solution.
Claims
1. A multi-main chain cross-chain method, It is characterized in that There are state trees corresponding to each main chain on the second-layer network, the initial root hash of each state tree is the same, each main chain is configured with a cross-chain verification contract, and a zero-knowledge proof circuit for verifying transaction information is deployed in the cross-chain verification contract. The method is applicable to nodes of the second-layer network, and the method includes: When it is detected that the first main chain has generated a first main chain block, the first transactions in the first main chain block that need to call transfer contracts are synchronized in order; wherein the transfer contracts include deposit contracts, withdrawal contracts, transfer contracts, and cross-chain transfer contracts; Perform the following operations on each of the first transactions: Determine whether the transfer contract called by the first transaction is a cross-chain transfer contract: If no, execute the first transaction to update the first state tree of the first main chain on the second-layer network; If yes, execute the first transaction to update the first state tree of the first main chain on the second-layer network, and the second state tree of the second main chain to be cross-chained specified by the first transaction; Generate zero-knowledge proof evidence in sequence according to the transaction information of each of the first transactions, and generate first proof data according to each of the first transactions and the zero-knowledge proof evidence in sequence; The first proof data is sent to the first main chain and other main chains so that the main chain node of the first main chain: Determine, through the cross-chain verification contract, whether the order of each of the first transactions in the first proof data is the same as that of each of the first transactions in the first main chain block: If the zero-knowledge proof is the same, the zero-knowledge proof evidence is input into the zero-knowledge proof circuit to verify whether the transaction information of each of the first transactions in the first proof data is correct: If the verification is correct, then end; The first proof data is also used for the main chain nodes of other main chains: Inputting the zero-knowledge proof evidence into the zero-knowledge proof circuit to verify whether the transaction information of each of the first transactions in the first proof data is correct: If the verification is correct, each of the first transactions is executed.
2. The method according to claim 1, It is characterized in that Also includes: When a different order is detected or verification fails, the first state tree is rolled back, or the first state tree and the second state tree are rolled back to the state when each of the first transactions is not executed; Returning the first transaction that needs to call the transfer contract in the first main chain block synchronized in order to regenerate the zero-knowledge proof evidence and the first proof data; After receiving the regenerated first proof data, the main chain nodes of other main chains verify whether the transaction information of each of the first transactions in the first proof data is correct, and further include: Roll back the main chain to the state before executing each of the first transactions.
3. The method according to claim 1, It is characterized in that Before the main chain nodes of other main chains input the zero-knowledge proof evidence into the zero-knowledge proof circuit to verify whether the transaction information of each of the first transactions in the first proof data is correct, the main chain nodes further include: Receiving each of the first transactions sent by the main chain node of the first main chain or by the relay server; The inputting of the zero-knowledge proof evidence into the zero-knowledge proof circuit to verify whether the transaction information of each of the first transactions in the first proof data is correct, performed by the main chain nodes of each other main chain, includes: Determine, through the cross-chain verification contract, whether the order of each of the first transactions in the first proof data is the same as the order of each of the first transactions sent by the first main chain node or the relay server: If the zero-knowledge proof is the same, the zero-knowledge proof evidence is input into the zero-knowledge proof circuit to verify whether the transaction information of each of the first transactions in the first proof data is correct.
4. The method according to claim 1, It is characterized in that The nodes of the second-layer network pay a certain amount of deposit on each main chain. When the main chain node of the first main chain detects a different order or verification fails, the first amount of deposit is deducted; when the main chain nodes of other main chains fail to verify, the first amount of deposit is deducted.
5. A computer device, It is 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 4.
6. A storage medium storing a computer program, It is characterized in that When the program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
