Detailed Description
The application is described in further detail below with reference to the drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the application and are not limiting of the application. It should be noted that, for convenience of description, only the portions related to the application are shown in the drawings.
It should be noted that, without conflict, the embodiments of the present application and features of the embodiments may be combined with each other. The application will be described in detail below with reference to the drawings in connection with embodiments.
The applicant hopes to propose a two-tier network cross-link scheme corresponding to multiple backbones, which is more cost-effective than the prior art, but also has the double-flower problem-if the operator cheats the deposit and exchanges assets with the other link, the other link cannot be verified. For example, assume that there are 3 backbones (A chain, B chain, C chain), an asset AAA is running on the A chain, an asset BBB is running on the B chain, an asset CCC is running on the C chain, the exchange ratio of AAA to BBB and CCC is 1:1:1, and assuming that an operator deposits 100AAA in the two-layer network privately and exchanges with BBB of a certain user in the two-layer network immediately, the 100AAA is out of order, and finally authentication on the A chain fails, but the operator has exchanged 100BBB and submitted to the B chain, causing harm to the B chain.
The above problems can be solved by the embodiments of the present application.
FIG. 1 is a flowchart of a method for multi-backbone cross-chain of a predictor in accordance with an embodiment of the present invention. As shown in fig. 1, in this embodiment, the present invention provides a method for implementing a multi-backbone chain crossing of a predictor applicable to a two-layer network node, where the two-layer network node has state trees corresponding to each backbone, initial root hashes of each state tree are the same, each backbone is configured with a cross-chain verification contract and a predictor contract, and a zero knowledge proof circuit for verifying transaction information is deployed in the cross-chain verification contract, and the method includes:
S11, when the first main chain is monitored to generate a first main chain block, sequentially synchronizing first transactions needing to call a first type contract in the first main chain block, wherein the first type contract comprises a deposit contract and a withdrawal contract, each first transaction is stored in the first main chain, and the first main chain block is further used for a predictor:
Transmitting the first transaction information of each first transaction in sequence to other main chains so as to enable the main chain nodes of the other main chains to store and verify each first transaction information through a prophetic contract;
S12, executing each first transaction to update a first state tree of a first main chain on the two-layer network;
S13, responding to a trigger settlement condition, sequentially generating zero knowledge proof evidence according to second transaction information of each second transaction, and generating first proof data according to each second transaction and the zero knowledge proof evidence in sequence;
and S14, transmitting the first proving data to each main chain so as to enable the main chain nodes of each main chain to:
judging whether the sequence of each second transaction in the first proving data is matched with the stored second transaction information or not through a cross-chain verification contract so as to verify whether the sequence of each second transaction in the first proving data is correct or not:
and if the order is correct, inputting the zero knowledge proof evidence into a zero knowledge proof circuit to verify whether each second transaction information is correct or not:
if the verification is correct, ending;
the first transaction information and the second transaction information comprise operation types, user addresses and license quantity.
Specifically, taking sending the first transaction information of each first transaction in sequence to other backbones for the backbone nodes of the other backbones to store each first transaction information through a forestation contract, which includes "storing the first transaction information of each first transaction in sequence, generating a fourth transaction according to each first transaction information, sending the fourth transaction to other backbones for the backbone nodes of the other backbones to execute the fourth transaction through the forestation contract, and storing each first transaction information when executing the fourth transaction successfully" as an example;
Assuming that 3 main chains (A chain, B chain and C chain) are arranged, wherein an asset AAA is operated on the A chain, an asset BBB is operated on the B chain, an asset CCC is operated on the C chain, the exchange ratio of AAA and BBB to CCC is 1:1:1, state trees treeA and TreeB of the A chain and state tree TreeB of the B chain are arranged on the two-layer network, the initial root hashes of TreeA, treeB and TreeC are the same, the first main chain is the A chain, main chain nodes of the A chain generate a main chain block (100) according to tx 1-tx 10 in sequence, wherein tx1 and tx2 are transactions needing to call first type contracts, tx1 is a user A requesting deposit of 100 AAA, and tx2 is a user B requesting withdrawal of 10 AAA;
The main chain node of the A chain generates a main chain block (100) comprising tx1 and tx2, wherein tx1 and tx2 exist on the A chain;
the method comprises the steps that S11 is executed by a node of a two-layer network, and tx1 and tx2 are synchronized in sequence when a block (100) generated by an A chain is monitored;
When the prophetic machine monitors that the A chain generates a block (100), generating tx3 according to transaction information (potential, addr (A), 100) of tx1 and transaction information (withdraw, addr (B), 10) of tx2, and sending tx3 to the B chain and the C chain;
The main chain nodes of the B chain and the C chain execute tx3 through a prophetic contract, and when tx3 is executed successfully, certificates (position, addr (A), 100) and (widthwart, addr (B), 10) are stored;
the node of the two-layer network executes step S12 to execute tx1 and tx2 to update TreeA on the two-layer network;
Assume that each second transaction in sequence is tx1, tx2, tx11 to tx20;
In response to triggering the settlement condition, the node of the two-layer network executes step S13 to generate zero knowledge proof1 according to the transaction information of tx1, tx2, tx 11-tx 20 and proof data proofchunk1 according to tx1, tx2, tx 11-tx 20 and proof1 in sequence;
Step S14 is executed by the nodes of the two-layer network, and proofchunk is sent to the A chain, the B chain and the C chain;
The main chain nodes of the A chain, the B chain and the C chain judge whether the sequences of tx1, tx2, tx11 to tx20 in proofchunk1 are matched with the transaction information of the stored tx1, tx2, tx11 to tx20 or not through a cross-chain verification contract so as to verify whether the sequences of tx1, tx2, tx11 to tx20 in proofchunk are correct or not:
assuming that the order is correct, the main chain nodes of the A chain, the B chain and the C chain input proof of zero knowledge circuit to verify whether the transaction information of tx1, tx2, tx 11-tx 20 is correct or not:
Assuming that the verification is correct, it ends.
It should be noted that tx1 and tx2 are transactions synchronized from the a-chain, and if tx11 to tx20 are transactions synchronized from the B-chain, then:
For the A chain, the main chain node of each main chain judges whether the sequence of tx1 and tx2 in proofchunk1 is matched with the stored transaction information of tx1 and tx2 so as to verify whether the sequence of each transaction synchronized from the A chain in proofchunk is correct or not;
For the B chain, the main chain node of each main chain judges whether the sequence of tx 11-tx 20 in proofchunk1 is matched with the stored transaction information of tx 11-tx 20 so as to verify whether the sequence of each transaction synchronized from the B chain in proofchunk is correct or not;
Assuming that each transaction in proofchunk1 is tx1, tx11, tx2, tx12 to tx20, as long as the sequence of the transaction information of tx1 and tx2 is tx1 to tx2 and the sequence of the transaction information of tx11 to tx20 is tx11 to tx20 in the transaction information of the main chain node of each main chain, the verification sequence of the main chain node of each main chain is correct;
The embodiment ensures that a common account book is maintained on the two-layer network by a plurality of main chains, saves cost, and can continue normal operation only on the basis of correct transaction sequence and transaction information, thereby preventing double flowers.
Preferably, the method further comprises:
When the sequence is detected to be incorrect or verification is incorrect, rolling back the state tree of each main chain to a state when each second transaction is not executed;
And returning to the step of generating the zero-knowledge proof evidence according to the second transaction information of each second transaction in sequence so as to regenerate the zero-knowledge proof evidence and the first proof data.
When the sequence on the A chain, the B chain and the C chain is detected to be incorrect or verification is incorrect, the nodes of the two-layer network roll back TreeA-TreeC to a state when tx1, tx2 and tx 11-tx 20 are not executed;
The nodes of the two-layer network return to the step of generating zero knowledge proof evidence according to the second transaction information of each second transaction in sequence so as to regenerate proof1 and proofchunk1;
it will be appreciated by those skilled in the art that if tx21 is also performed on the two-tier network, tx21 should be rolled back by means of the result of one or more of tx1, tx2, tx11 to tx20, and then tx21 should be rolled back when rolling back TreeA to TreeC.
Preferably, before generating the zero knowledge proof evidence according to the second transaction information of each second transaction in sequence, the method further comprises:
receiving third transactions which are generated by a plurality of clients and need to call a second class contract, wherein the second class contract comprises a transfer contract and a cross-chain transfer contract;
And executing the third transaction to update a second state tree of the second main chain to be crossed, which is designated by the third transaction, on the two-layer network, and a third state tree of the third main chain to be crossed, which is designated by the third transaction.
Specifically, the backbone node of the present application is configured to receive transactions of a first type of contract generated by a client, while the nodes of the two-tier network are configured to receive transactions of a second type of contract generated by the client.
In connection with the embodiment shown in FIG. 1, it is assumed that tx 11-tx 15 is the third transaction invoking the second type contract, tx 16-tx 20 is the first transaction invoking the first type contract synchronized from the A-chain block (101), it can be seen that the nodes of the two-layer network are synchronized to tx1, tx2 from the A-chain block (100), then receive tx 11-tx 15 in order, and then synchronize to tx 16-tx 20 in order from the A-chain block (101), so that the order of each transaction is tx1, tx2, tx 11-tx 20, and accordingly, the predictors send the transaction information of tx1, tx2, tx 11-tx 20 in order.
And only verifying whether the sequences of tx1, tx2, tx16 to tx20 are correct for the main chain nodes of the tx1, tx2, tx11 to tx20, namely the A chain, the B chain and the C chain.
Those skilled in the art will appreciate that the transaction information for the third transaction invoking the second type of contract should also include the asset type.
Preferably, generating the first proof data from the sequential second transactions, zero knowledge proof evidence comprises:
generating first proof data according to each second transaction, a first tree root and zero knowledge proof evidence in sequence, wherein the first tree root is generated according to the merck tree root of each state tree;
judging whether the sequence of each second transaction in the first proving data is matched with the stored second transaction information or not through a cross-chain verification contract so as to verify whether the sequence of each second transaction in the first proving data is correct or not comprises the following steps:
Calculating a third root from each second transaction, the stored second root by the cross-chain validation contract, updating the value of the second root to the value of the first root when the third root is the same as the first root, and
And judging whether the sequence of each second transaction in the first proving data is matched with the stored second transaction information or not through a cross-chain verification contract so as to verify whether the sequence of each second transaction in the first proving data is correct or not.
Specifically, proofchunk also includes a first root CHAIN TREE root, fig. 2 is a schematic diagram of generating the first root according to an embodiment of the present invention, as shown in fig. 2, CHAIN TREE root is generated according to merkleroothash (tree A) -merkleroothash (tree C), and the value is assumed to be R1;
The main chain nodes of the A chain, the B chain and the C chain calculate CHAIN TREE root 'according to tx1, tx2, tx 11-tx 20 through a cross-chain verification contract, the stored CHAIN TREE root (namely the last CHAIN TREE root, the value of which is assumed to be R2), the value of CHAIN TREE root' is assumed to be R3, if R1=R3, the stored CHAIN TREE root value is updated from R2 to R1, and
Whether the sequence of tx1, tx2, tx 11-tx 20 in proofchunk1 is correct or not is judged by the cross-link verification contract to be matched with the transaction information of tx1, tx2, tx 11-tx 20 of the stored certificate or not so as to verify whether the sequence of tx1, tx2, tx 11-tx 20 in proofchunk1 is correct or not.
Preferably, the nodes of the two-layer network pay a plurality of deposits on each main chain, and the main chain nodes of each main chain deduct the first number of deposits when the sequence is detected to be incorrect or verification is incorrect.
The above embodiment penalizes the nodes of the two-layer network, further preventing double flowers.
Preferably, the storing of each first transaction information by the foreseeing machine contract includes:
storing each first transaction information into a prophetic contract;
judging whether the sequence of each second transaction in the first proving data is matched with the stored second transaction information or not through a cross-chain verification contract so as to verify whether the sequence of each second transaction in the first proving data is correct or not comprises the following steps:
Requesting each second transaction information from the predictive engine contract by cross-chain validation contract;
And judging whether the sequence of each second transaction in the first proving data is matched with each second transaction information of the stored certificate so as to verify whether the sequence of each second transaction in the first proving data is correct.
The above embodiment stores each second transaction information in the predictive engine contract. In further embodiments, the rights of the other contracts to access the second transaction information may also be configured according to actual needs, e.g., a cross-chain validation contract may be used to access the second transaction information while some other contracts are configured as contracts that are not accessible to the second transaction information.
Preferably, generating the first proof data from the sequential second transactions, zero knowledge proof evidence comprises:
Generating first proof data according to each second transaction information and zero knowledge proof evidence;
judging whether the sequence of each second transaction in the first proving data is matched with the stored second transaction information or not through a cross-chain verification contract so as to verify whether the sequence of each second transaction in the first proving data is correct or not comprises the following steps:
judging whether the second transaction information in the first proving data is the same as the stored second transaction information or not through a cross-link verification contract so as to verify whether the sequence of the second transaction information in the first proving data is correct or not.
The above-described embodiments reduce the data amount of the first certification data.
Preferably, transmitting the first transaction information of each first transaction in sequence to each other backbone comprises:
And each first transaction information is also used for the predictor to send each first transaction information to the first main chain node when the first main chain node of the initial network access is monitored, so that each first transaction information is stored by the first main chain node through the predictor contract.
The embodiment accelerates the speed of synchronizing the main chain block data of the main chain nodes of the primary network, and improves the accuracy of synchronizing the main chain block data.
Fig. 3 is a schematic structural diagram of an apparatus according to an embodiment of the present invention.
As shown in fig. 3, as another aspect, the present application also provides an apparatus 300 including one or more Central Processing Units (CPUs) 301 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 302 or a program loaded from a storage section 308 into a Random Access Memory (RAM) 303. In the RAM303, various programs and data required for the operation of the device 300 are also stored. The CPU301, ROM302, and RAM303 are connected to each other through a bus 304. An input/output (I/O) interface 305 is also connected to bus 304.
Connected to the I/O interface 305 are an input section 306 including a keyboard, a mouse, and the like, an output section 307 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, a speaker, and the like, a storage section 308 including a hard disk, and the like, and a communication section 309 including a network interface card such as a LAN card, a modem, and the like. The communication section 309 performs communication processing via a network such as the internet. The drive 310 is also connected to the I/O interface 305 as needed. A removable medium 311 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is installed on the drive 310 as needed, so that a computer program read therefrom is installed into the storage section 308 as needed.
In particular, according to embodiments of the present disclosure, the method described in any of the above embodiments may be implemented as a computer software program. 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 performing any of the methods described above. In such an embodiment, the computer program may be downloaded and installed from a network via the communication portion 309, and/or installed from the removable medium 311.
As a further 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 may be a computer-readable storage medium that exists alone and is not assembled into a device. The computer-readable storage medium stores one or more programs for use by one or more processors to perform the methods described herein.
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units or modules involved in the embodiments of the present application may be implemented in software or in hardware. The described units or modules may also be provided in a processor, for example, each of the units may be a software program provided in a computer or a mobile smart device, or may be separately configured hardware devices. Wherein the names of the units or modules do not in some cases constitute a limitation of the units or modules themselves.
The above description is only illustrative of the preferred embodiments of the present application and of the principles of the technology employed. It will be appreciated by persons skilled in the art that the scope of the application referred to in the present application is not limited to the specific combinations of the technical features described above, but also covers other technical features formed by any combination of the technical features described above or their equivalents without departing from the spirit of the application. Such as the above-mentioned features and the technical features disclosed in the present application (but not limited to) having similar functions are replaced with each other.