Detailed Description
The present application will be described in further detail with reference to the following drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the relevant invention and not restrictive of the invention. It should be noted that, for convenience of description, only the portions related to the present invention are shown in the drawings.
It should be noted that the embodiments and features of the embodiments in the present application may be combined with each other without conflict. The present application will be described in detail below with reference to the embodiments with reference to the attached drawings.
The applicant wishes to propose a cross-chaining scheme with a two-tier network corresponding to multiple backbones, which is more cost-effective than the prior art, but also has the problem of double flowers-if the operator cheats the exchange of assets with the other chain after the deposit, the other chain will not be able to verify. For example, assume that there are 3 main chains (A chain, B chain, C chain); an asset AAA runs on the chain A, an asset BBB runs on the chain B, an asset CCC runs on the chain C, and the exchange ratio of the AAA to the BBB to the CCC is 1:1: 1; assuming that the operator privately deposits 100AAA in the two-tier network and immediately exchanges with the BBB of a certain user in the two-tier network, the 100AAA is overflowed by the air and eventually fails authentication on the a chain, but the operator has exchanged 100BBB and submitted to the B chain, causing damage to the B chain.
The above problems can be solved by embodiments of the present application.
Fig. 1 is a flowchart of a method for predicting inter-chain of multiple main chains of a speaker. As shown in fig. 1, in this embodiment, the present invention provides a predictive engine multi-main-chain cross-link method suitable for a two-layer network node, where a two-layer network has state trees corresponding to main chains, initial root hashes of the state trees are the same, each main chain is configured with a cross-chain verification contract and a predictive engine contract, and a zero-knowledge proof circuit for verifying transaction information is deployed in the cross-chain verification contract, where the method includes:
s11: when the first main chain block is detected to be generated by the first main chain, synchronizing first transactions in the first main chain block, which need to call the first type of contracts, in sequence; wherein the first type of contract comprises a deposit contract and a withdrawal contract; each first transaction is credited at a first backbone, the first backbone block further for the predictive engine to:
sending the first transaction information of each first transaction in sequence to other main chains so that main chain nodes of other main chains can store and verify the first transaction information through a prompter contract;
s12: performing each first transaction to update a first state tree of a first backbone on the two-tier network;
s13: responding to a triggered settlement condition, generating zero-knowledge proof evidence according to second transaction information of each second transaction in sequence, and generating first proof data according to each second transaction and the zero-knowledge proof evidence in sequence;
s14: sending the first proof data to each backbone for the backbone nodes of each backbone:
judging whether the sequence of each second transaction in the first certification data is matched with the stored second transaction information through the cross-link verification contract so as to verify whether the sequence of each second transaction in the first certification data is correct:
and if the sequence is correct, inputting the zero-knowledge proof evidence into a zero-knowledge proof circuit to verify whether each second transaction message is correct:
if the verification is correct, ending;
the first transaction information and the second transaction information comprise operation types, user addresses and the number of certificates of receipt.
Specifically, taking as an example that the first transaction information of each first transaction in sequence is sent to each other main chain, so that the main chain nodes of each other main chain can store each first transaction information through a language predictive machine contract to certify each first transaction information, including "the first transaction information of each first transaction is stored in sequence, a fourth transaction is generated according to each first transaction information, the fourth transaction is sent to each other main chain, so that the main chain nodes of each other main chain can execute the fourth transaction through the language predictive machine contract, and each first transaction information is certified when the fourth transaction is executed successfully";
suppose there are 3 main chains (chain A, chain B, chain C); an asset AAA runs on the chain A, an asset BBB runs on the chain B, an asset CCC runs on the chain C, and the exchange ratio of the AAA to the BBB to the CCC is 1:1: 1; the two-layer network is provided with a state tree TreeA of the chain A, a state tree TreeB of the chain B and a state tree TreeC of the chain C, and the initial root hash of TreeA, TreeB and TreeC is the same; the first main chain is an 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 a first type of contract, tx1 requests a user A to deposit 100AAA, and tx2 requests a user B to withdraw 10 AAA;
the main chain node of the A chain generates a main chain block (100) comprising tx1 and tx2, and tx1 and tx2 are verified on the A chain;
the nodes of the two-layer network execute step S11, and synchronize tx1 and tx2 in sequence when detecting that the A chain generates a block (100);
when monitoring that the A chain generates a block (100), the prophetic generates tx3 according to transaction information (default, addr (A),100) of tx1 and transaction information (withdraw, addr (B),10) of tx2, and sends tx3 to the B chain and the C chain; in more embodiments, the transaction information may also be configured according to actual requirements, for example, configured as a user address, an asset type, an asset quantity, an operation type, and the like, so that the same technical effect may be achieved;
main chain nodes of the B chain and the C chain execute tx3 through a presupportion machine contract, and when the tx3 is executed successfully, the memories (dispose, addr (A), (100)) and (withdraw, addr (B), (10)) are stored;
the nodes of the two-layer network execute the step S12, execute tx1, tx2 to update TreeA on the two-layer network;
assume that each second transaction in order is tx1, tx2, tx 11-tx 20;
responding to the triggered settlement condition, executing a step S13 by the nodes of the two-layer network, generating proof of zero knowledge proof1 according to the transaction information of tx1, tx2 and tx11 to tx20 in sequence, and generating proof data proofchunk1 according to tx1, tx2, tx11 to tx20 and proof 1; in further embodiments, the condition for triggering settlement may be configured according to actual requirements, for example, configured to achieve the same technical effect when the time is the first time since the last settlement, or configured to receive the settlement request;
the node of the two-layer network executes the step S14, and sends proofchunk1 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 sequence of tx1, tx2 and tx11 to tx20 in the proofchunk1 is matched with the stored transaction information of tx1, tx2 and tx11 to tx20 through a cross-chain verification contract so as to verify whether the sequence of tx1, tx2 and tx11 to tx20 in the proofchunk1 is correct:
assuming the sequence is correct, the main chain nodes of the A chain, the B chain and the C chain input proof1 into a zero-knowledge proof circuit to verify whether the transaction information of tx1, tx2, tx11 to tx20 is correct:
assuming the verification is correct, the process is ended.
It should be noted that tx1 and tx2 are transactions synchronized from the a chain, and assuming 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 the 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 the proofchunk1 is correct;
for the B chain, the main chain node of each main chain judges whether the sequence of tx11 to tx20 in the proofchunk1 is matched with the stored transaction information of tx11 to tx20 so as to verify whether the sequence of each transaction synchronized from the B chain in the proofchunk1 is correct;
assuming that each transaction in the proofchunk1 is tx1, tx11, tx2, tx12 to tx20, as long as the sequence of the transaction information of tx1 and tx2 is tx1 → tx2 and the sequence of the transaction information of tx11 to tx20 is tx11 → tx20 in the transaction information of the main chain node certificate of each main chain, the main chain node verification sequence of each main chain is also correct;
the embodiment enables a plurality of main chains to maintain a common account book on a two-layer network, thereby saving the cost; and only on the basis of correct transaction sequence and transaction information, the two-layer network can continue to operate normally, so that double flowers are prevented.
Preferably, the method further comprises:
when the monitored sequence is incorrect or the verification is incorrect, rolling back the state tree of each main chain to the 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 the second transactions in sequence so as to regenerate the zero-knowledge proof evidence and the first proof data.
When the sequence of the chain A, the chain B and the chain C is monitored to be incorrect, or the verification is incorrect, the nodes of the two-layer network roll back TreeA-TreeC to the state when tx1, tx2 and tx 11-tx 20 are not executed;
the nodes of the two-layer network return the step of generating zero-knowledge proof evidence according to the second transaction information of the second transactions in sequence so as to regenerate proof1 and proof 1;
it should be understood by those skilled in the art that, assuming tx21 is also executed on the two-tier network, tx21 is executed by means of the execution results of one or more transactions among tx1, tx2, tx11 to tx20, then tx21 should also be rolled back when rolling back TreeA to TreeC.
Preferably, before generating the zero-knowledge proof evidence according to the second transaction information of the second transactions in sequence, the method further includes:
receiving third transactions which are generated by a plurality of clients and need to call the second type of contracts; wherein the second type of contract comprises a transfer contract and a cross-chain transfer contract; each third transaction is also for the predictive engine: storing third transaction information of each third transaction in sequence;
performing the following operations for each third transaction: and executing the third transaction to update a second state tree of a second main chain needing to be bridged and specified by the third transaction on the two-layer network, and a third state tree of a third main chain to be bridged and specified by the third transaction.
Specifically, the backbone nodes of the present application are 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, assume that tx 11-tx 15 are third transactions invoking contracts of a second type, and tx 16-tx 20 are first transactions invoking contracts of a first type synchronized from a block (101) of an A-chain; it can be seen that the nodes of the two-layer network are synchronized to tx1 and tx2 from block (100) of the a chain, then sequentially receive tx11 to tx15, and sequentially synchronize to tx16 to tx20 from block (101) of the a chain; the order of transactions is thus tx1, tx2, tx11 to tx 20; correspondingly, the prediction machine sends the transaction information of tx1, tx2, tx11 to tx20 in sequence.
For tx1, tx2, tx11 to tx 20: the main chain nodes of the A chain, the B chain and the C chain only verify whether the sequence of tx1, tx2, tx16 to tx20 is correct or not.
Those skilled in the art will appreciate that the transaction information for the third transaction that invokes the second type of contract should also include the asset type.
Preferably, generating the first proof data from the sequential second transaction, zero knowledge proof of knowledge proofs comprises:
generating first proof data according to each second transaction, the first tree root and the zero-knowledge proof evidence in sequence; wherein the first tree root is generated according to the Mercker tree root of each state tree;
determining, by the cross-link verification contract, whether the order of the second transactions in the first attestation data matches the second transaction information stored to verify whether the order of the second transactions in the first attestation data is correct comprises:
calculating a third root according to each second transaction and the stored second root through the cross-link verification contract, and 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 the number of the first and second groups,
and judging whether the sequence of each second transaction in the first certification data is matched with the stored second transaction information through the cross-link verification contract so as to verify whether the sequence of each second transaction in the first certification data is correct.
Specifically, the proofchunk1 further includes a first tree root; FIG. 2 is a schematic diagram of generating a first tree root according to an embodiment of the present invention, and as shown in FIG. 2, a chain tree root is generated according to merkleothorash (tree A) -merkleothorash (tree C), and its value is assumed to be R1;
main chain nodes of the A chain, the B chain and the C chain calculate chain tree roots 'according to tx1, tx2 and tx 11-tx 20 through cross-chain verification contracts, wherein the stored chain tree roots (namely the last chain tree root, the value of which is assumed to be R2) and the value of the chain tree root' is assumed to be R3; if R1 ═ R3, the value of the stored chain tree root is updated from R2 to R1; and the number of the first and second groups,
whether the sequence of tx1, tx2 and tx11 to tx20 in the proofchunk1 is matched with the stored transaction information of tx1, tx2 and tx11 to tx20 is judged through a cross-chain verification contract so as to verify whether the sequence of tx1, tx2 and tx11 to tx20 in the proofchunk1 is correct.
Preferably, the nodes of the two-layer network pay a plurality of deposit on each main chain, and the main chain nodes of each main chain deduct a first amount of deposit when monitoring the sequence is incorrect or verification is incorrect.
The embodiment punishs the nodes of the two-layer network, and further prevents double flowers.
Preferably, the validating each first transaction information by the predictive engine contract includes:
storing each first transaction information into a language prediction machine contract;
determining, by the cross-link verification contract, whether the order of the second transactions in the first attestation data matches the second transaction information stored to verify whether the order of the second transactions in the first attestation data is correct comprises:
requesting each second transaction information from the president contract through the cross-link verification contract;
and judging whether the sequence of each second transaction in the first certification data is matched with the stored second transaction information so as to verify whether the sequence of each second transaction in the first certification data is correct.
The above-described embodiments store each second transaction information in a predictive engine contract. In further embodiments, the rights of each other contract to access each second transaction information may also be configured according to actual requirements, e.g., cross-chain validation contracts may be configured to access each second transaction information, while some other contracts are configured as contracts that do not have access to each second transaction information.
Preferably, generating the first proof data from the sequential second transaction, zero knowledge proof of knowledge proofs comprises:
generating first proof data according to the second transaction information and the zero-knowledge proof evidence;
determining, by the cross-link verification contract, whether the order of the second transactions in the first attestation data matches the second transaction information stored to verify whether the order of the second transactions in the first attestation data is correct comprises:
and judging whether the second transaction information in the first certification data is the same as the stored second transaction information through the cross-link verification contract so as to verify whether the sequence of the second transaction information in the first certification data is correct.
The above-described embodiment reduces the data amount of the first certification data.
Preferably, the sending the first transaction information of each first transaction in sequence to each other main chain comprises:
storing the first transaction information of each first transaction in sequence, and sending each first transaction information to other main chains; and each first transaction information is also used for sending each first transaction information to the first main chain node when the predicting machine monitors the first main chain node of the initial network, so that the first main chain node can store and verify each first transaction information through the contract of the predicting machine.
The embodiment accelerates the speed of synchronizing the main chain block data by the main chain node of the initial network and improves the correctness of the synchronizing 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 necessary for the operation of the apparatus 300 are also stored. The CPU301, ROM302, and RAM303 are connected to each other via a bus 304. An input/output (I/O) interface 305 is also connected to bus 304.
The following components are connected to the I/O interface 305: an input portion 306 including a keyboard, a mouse, and the like; an output section 307 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; 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, or the like. The communication section 309 performs communication processing via a network such as the internet. A 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 mounted on the drive 310 as necessary, so that a computer program read out therefrom is mounted into the storage section 308 as necessary.
In particular, according to an embodiment 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 through the communication section 309, and/or installed from the removable medium 311.
As yet another aspect, the present application also provides a computer-readable storage medium, which may be the computer-readable storage medium included in the apparatus of the above-described embodiment; or it may be a separate computer readable storage medium not incorporated into the device. The computer readable storage medium stores one or more programs for use by one or more processors in performing the methods described in the present application.
The flowchart 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 described in the embodiments of the present application may be implemented by software or hardware. The described units or modules may also be provided in a processor, for example, each of the described units may be a software program provided in a computer or a mobile intelligent device, or may be a separately configured hardware device. Wherein the designation of a unit or module does not in some way constitute a limitation of the unit or module itself.
The above description is only a preferred embodiment of the application and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the invention herein disclosed is not limited to the particular combination of features described above, but also encompasses other arrangements formed by any combination of the above features or their equivalents without departing from the spirit of the present application. For example, the above features may be replaced with (but not limited to) features having similar functions disclosed in the present application.