Cross-chain transaction method, system and storage medium of Hash locking and side chain technology

文档序号:1817380 发布日期:2021-11-09 浏览:8次 中文

阅读说明:本技术 哈希锁定和侧链技术的跨链交易方法、系统、可存储介质 (Cross-chain transaction method, system and storage medium of Hash locking and side chain technology ) 是由 陈艳姣 徐文渊 冉渝阳 于 2021-08-31 设计创作,主要内容包括:本发明公开了一种基于哈希锁定和侧链技术的跨链交易方法,涉及区块链领域。本发明包括以下步骤:创建第一终端和第二终端基于哈希锁定的原子交换数据传输机制;创建基于SPV锚定模式跨链数据转移机制;第一终端和第二终端在所述SPV锚定模式监督状态下,实现基于哈希锁定的原子交换数据传输。本发明利用侧链技术解决哈希锁定技术中的只能实现资产交换而不能解决资产转移的缺点,而利用哈希锁定技术,无需额外增加一条侧链或者中继链就可以实现跨链资产转移。(The invention discloses a cross-chain transaction method based on Hash locking and side chain technology, and relates to the field of block chains. The invention comprises the following steps: creating an atom exchange data transmission mechanism based on hash locking of a first terminal and a second terminal; creating a cross-chain data transfer mechanism based on the SPV anchoring mode; and the first terminal and the second terminal realize the atom exchange data transmission based on the Hash locking under the supervision state of the SPV anchoring mode. The invention solves the defect that only asset exchange can be realized but asset transfer cannot be realized in the Hash locking technology by utilizing the side chain technology, and can realize cross-chain asset transfer by utilizing the Hash locking technology without additionally adding a side chain or a relay chain.)

1.A cross-chain transaction method based on Hash locking and side chain technology is characterized by comprising the following steps:

creating an atom exchange data transmission mechanism based on hash locking of a first terminal and a second terminal;

creating a cross-chain data transfer mechanism based on the SPV anchoring mode;

and the first terminal and the second terminal realize the atom exchange data transmission based on the Hash locking under the supervision state of the SPV anchoring mode.

2. The cross-chain transaction method based on the hash locking and side chain technology as claimed in claim 1, wherein the atom exchange data transmission mechanism comprises the following specific steps:

a, generating a random number, and calculating a hash value of the random number;

a uses the hash value and generates a contract T1 at time T1, and simultaneously locks the data which A needs to transmit; a sends the hash value to B and sends information to A, proving that the data which needs to be transmitted of A is locked;

b uses the hash value to generate a contract T2 at time T2, and simultaneously locks the data needing to be transmitted by B;

a, constructing a contract T3 and unlocking the contract T2 by using a random number, acquiring data to be transmitted by B, and simultaneously exposing the random number;

b uses the exposed random number to construct a contract T3 to unlock T2 and obtain the data required to be transmitted by A.

3. The cross-chain transaction method based on hash locking and side chain technology as claimed in claim 1, wherein the principle of the atom exchange data transmission mechanism is that two parties of data transmission analyze internal data of the two parties through a hash value, and a time difference exists in timeout time setting of hash locking.

4. The cross-chain transaction method based on hash locking and side chain technology as claimed in claim 1, wherein the SPV anchor mode cross-chain data transfer mechanism specifically includes the following contents:

locking the data of the A, and setting a confirmation period for locking the data of the A;

when the confirmation period of the data A is over, the data B generates coinage data transmission and provides SPV (SPV) certification of the coinage data transmission A, and meanwhile, generated data B transmission information is locked and waits for a competition period;

and after the competition period is ended, the B obtains the data and simultaneously realizes the transmission of the data.

5. The method of claim 4, wherein if data A is lost during the contention period, the data A is proved to be lost by using a new SPV, and the coinage data transmission of B fails.

6. A cross-chain transaction system based on Hash locking and side-chain technology is characterized by comprising:

a mechanism creation module: the atom exchange data transmission mechanism is used for creating hash locking based on the first terminal and the second terminal; the data transfer mechanism is also used for creating a cross-chain data transfer mechanism based on the SPV anchoring mode;

a data transmission module: and the method is used for realizing the transmission of the atomic exchange data based on the Hash locking by the first terminal and the second terminal under the supervision state of the SPV anchoring mode.

7. A computer storage medium, having stored thereon a computer program for performing the steps of a hash lock and sidechain technique based cross-chain transaction as claimed in any of claims 1-5 when executed by a processor.

Technical Field

The invention relates to the field of block chains, in particular to a cross-chain transaction method, a system and a storage medium based on Hash locking and side chain technology.

Background

Nowadays, decentralized electronic money based on blockchains is becoming more and more popular. For example, in bitcoin, all transactions are recorded on a common transaction ledger-blockchain maintained by a set of scattered peer nodes. With the development of technology and market, the variety of cryptocurrency is more and more, and meanwhile, a large number of different block chains emerge. Each chain is equivalent to an independent ledger, and value transfer cannot be realized between different ledgers under normal conditions. The cooperation and value circulation between different chains become new requirements of users, so that the block chain 'cross-chain technology' is produced. The mainstream cross-link technologies include notary technology, hash locking technology, and side-chain and relay-chain technology.

Notary technology, also known as witness mechanisms, is an intermediary approach. If the blockchain a and the blockchain B cannot directly interoperate, a common trusted third party can be introduced as an intermediary, and the common trusted intermediary verifies and forwards the cross-chain message. Many times, this notary/intermediary is the exchange. The method has the advantages of supporting heterogeneous block chain cross-chain and has the defects of centralized risk and incapability of realizing transfer only by switching.

A typical implementation of a hash lock is the hash time lock contract HTLC (hashed TimeLock Contract). The hash time lock was first present in the lightning network of bitcoins. Hash time locking skillfully adopts a Hash lock and a time lock, so that a receiver of the asset is forced to determine collection within a certain time and generate a collection certificate to a payer, otherwise, the asset is returned to the payer. The proof of receipt can be used by the payor to acquire a quantitative asset of equal value on the recipient blockchain or to trigger other events. Hash locking can only exchange but not transfer assets or information, so that the use scene is limited.

The side chain is used to refer to the block chain that is parallel to the main block chain. The main block chain can be connected to a side chain or connected by the side chain; in this way, the side chains can operate independently of the main block chain (e.g., by using a spare record keeping approach). From the perspective of single chain of the main chain, the side chain can virtually improve the performance of the main chain in a transverse and longitudinal direction. The transverse direction is to communicate a plurality of side chains with the main chain, put most of transactions on the side chains, and then realize the transaction by communicating with the main chain, so that the TPS of the main chain can be virtually lifted. By longitudinal, it is meant that the side chains may have functions not present in the main chain, through which the main chain appears to support these functions as well. Most of the side chains are now also referred to as anchored side chains (pendant) as described by BlockStream. Anchored side chains are primarily meant to support bi-directional anchoring of the asset, i.e., circulation of the asset between the main chain and the side chain. Currently, the implementation of bi-directional anchoring side chains includes the following 4.

1) Single escrow pattern a single escrow pattern is the simplest way to achieve bidirectional anchoring, with the same basic principle as a single notary mechanism. The trading participant sends the digital assets to the escrow party, who sends the corresponding assets to the trading party side chain account on the side chain.

2) The joint anchoring mode uses the mode of notary alliance as an asset hosting party, and reduces the risk of a single center by using a multi-signature mode.

3) Drive chain mode the drive chain concept was proposed by the Bitcin Hivemed founder Paul. In the drive chain, the transaction processing node represents the role of the notary group, responsible for funds escrow and unlocking. The transaction processing node submits asset locking information on other chains to the block, initiates a proposal, and unlocks the specified asset on the current chain after voting and confirmation.

4) Spv (simple payload verification) anchor mode refers to the ability of a lightweight client to verify the existence of a transaction without downloading all the block data. An SPV certificate contains two parts: a block header list; a cryptographic proof, such as a mercker proof, that a certain output occurs in a certain block of the list. If a transaction is to be proven to exist in a block, the final root of the Merck tree is calculated using the hash value of the transaction and the hash values of other related transactions, and compared with the root at the head of the block. If the calculation result is consistent with the transaction tree root of the block head, the transaction is proved to exist in the block. And the relay means that the data on the other chain can be verified on the chain without depending on a third party.

Disclosure of Invention

In view of this, the present invention provides a cross-link transaction method, system and storage medium for hash locking and side chain technology, which solves the disadvantage that only asset exchange but not asset transfer in the hash locking technology is realized by using the side chain technology, and can realize cross-link asset transfer without adding an additional side chain or relay chain by using the hash locking technology.

In order to achieve the purpose, the invention adopts the following technical scheme:

a cross-chain transaction method based on Hash locking and side chain technology comprises the following steps:

creating an atom exchange data transmission mechanism based on hash locking of a first terminal and a second terminal;

creating a cross-chain data transfer mechanism based on the SPV anchoring mode;

and the first terminal and the second terminal realize the atom exchange data transmission based on the Hash locking under the supervision state of the SPV anchoring mode.

Optionally, the atomic exchange data transmission mechanism specifically includes the following steps:

a, generating a random number, and calculating a hash value of the random number;

a uses the hash value and generates a contract T1 at time T1, and simultaneously locks the data which A needs to transmit;

a sends the hash value to B and sends information to A, proving that the data which needs to be transmitted of A is locked;

b uses the hash value to generate a contract T2 at time T2, and simultaneously locks the data needing to be transmitted by B;

a, constructing a contract T3 and unlocking the contract T2 by using a random number, acquiring data to be transmitted by B, and simultaneously exposing the random number;

b uses the exposed random number to construct a contract T3 to unlock T2 and obtain the data required to be transmitted by A.

Optionally, the principle of the atomic exchange data transmission mechanism is that two parties of data transmission analyze internal data of the two parties through a hash value, and a time difference exists between timeout time settings of hash locking.

Optionally, the specific content of the SPV anchor mode cross-chain data transfer mechanism is as follows:

locking the data of the A, and setting a confirmation period for locking the data of the A;

when the confirmation period of the data A is over, the data B generates coinage data transmission and provides SPV (SPV) certification of the coinage data transmission A, and meanwhile, generated data B transmission information is locked and waits for a competition period;

and after the competition period is ended, the B obtains the data and simultaneously realizes the transmission of the data.

Optionally, if the data loss is detected in the competition period, the data loss is proved by adopting the new SPV, and the coinage data transmission of the B fails.

A cross-chain transaction system based on hash locking and side-chain techniques, comprising:

a mechanism creation module: the atom exchange data transmission mechanism is used for creating hash locking based on the first terminal and the second terminal; the data transfer mechanism is also used for creating a cross-chain data transfer mechanism based on the SPV anchoring mode;

a data transmission module: and the method is used for realizing the transmission of the atomic exchange data based on the Hash locking by the first terminal and the second terminal under the supervision state of the SPV anchoring mode.

A computer storage medium having stored thereon a computer program for, when executed by a processor, performing the steps of a cross-chain transaction based on hash-lock and sidechain techniques.

Compared with the prior art, the cross-chain transaction method based on the Hash locking and the side chain technology is provided, wherein the Hash locking can only exchange but not transfer assets or information, and both chains for exchanging assets support the Hash locking and the time locking, so that the use scene is limited. The side chain technology and the relay chain technology can be switched between a main chain and a side chain, so that the privacy can be improved, the cost can be reduced, and the value transfer and settlement process can be accelerated. Aiming at the defects of the existing Hash locking cross-chain technology and side chain cross-chain technology, the invention directly generates a new token in the Hash locking time, thereby realizing cross-chain atomic transaction, avoiding the participation of a side chain or a relay chain, solving the problems of throughput and transaction speed of public chain transaction and improving the expansibility of the public chain.

Drawings

In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.

FIG. 1 is a schematic diagram of an atomic transaction based on hash locking according to the present invention;

fig. 2 shows bidirectional anchoring in SPV mode according to the present invention.

Detailed Description

The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.

The embodiment of the invention discloses a cross-chain transaction method, a system and a storage medium of Hash locking and side chain technology, which comprises the following steps:

and step 1, realizing the atomic exchange based on the Hash locking.

The hash locking based atomic exchange can ensure the safety and atomicity of asset transaction between different chains without the participation of a third party. Hash time locking skillfully adopts a Hash lock and a time lock, and forces a receiver of the property to determine collection in deadlines and generate a collection certificate to a payer, otherwise, the property is returned to the payer. The proof of receipt can be used by the payor to acquire a quantitative asset of equal value on the recipient blockchain or to trigger other events.

As shown in fig. 1, the atomic exchange hash lock mechanism for a and B can be described simply as follows (let a exchange token a on chain a with token B on chain B.

1) A generates a random number s and computes a hash value H(s), where H represents a hash function.

2) A uses h(s) and a time to generate a contract transaction T (h(s), T1) on chain a, locking token a requiring a transaction on chain a for the time.

3) A sends the calculated H(s) to B and sends a transaction to the A chain, proving that the token a to be traded of the A chain is locked.

4) B generates contract transactions with time using h(s), locks tokens B that need to be traded and links the transactions, where the lock time is () on.

5) A builds a locked transaction of the unlock chain B using s, and obtains the generation B of the lock, at which time the random number s is exposed.

6) B constructs the unlocked token a on the unlocked chain a using the published s.

The hash function, also called hash function, is a method for creating a small digital "fingerprint" from any kind of data. The hash function compresses a message or data into a digest so that the amount of data becomes small, fixing the format of the data. This function mixes the data shuffled and recreates a fingerprint called a hash value. The hash value is typically represented by a short string of random letters and numbers. From the above process, it can be seen that the hash time lock contract has some constraints: one is that both parties must be able to parse both parties' contract internal data, e.g., s, such as proof of locked assets, etc.; and secondly, the timeout time of the Hash locking needs to be set to ensure that time difference exists, so that the other party can withdraw own assets in time when unilateral cheating occurs.

For bitcoin systems, a hash lock on an asset may be accomplished by building an HTLC. Assuming that both parties to the transaction are a and B, a requires two UTXOs to build the HTLC. A firstly generates a random number s, calculates H(s), and only provides the original image s to calculate H(s) so as to realize Hash locking. Then, A generates a certain amount of bit coins which are sent to a bit coin script by the UTXO, and the spending conditions of the UTXO are set in the script to be two: 1) providing a signature and a pre-image s of B; 2) the signatures of a and B are provided. This transaction is commonly referred to as a credit transaction (fundtransfer), indicating the locking of the asset. A generates another transaction, the deposit transaction is used as the input of a second UTXO, the address of A is output, meanwhile, the nTimeLock field is set as Tlock, the packed transaction is allowed to take effect after T is reached, and time locking is realized, so that the transaction is called a refund transaction (refund transaction). The two transactions together constitute a hash lock contract on a bitcoin system. A sends the two transactions to B, signs the second transaction if B agrees and sends it back to A. For a chain of ether plants such as a graph-complete chain, a contract may be generated. The contract logic is set to: during time t (implementing a time lock), if the address of a can provide the hash pre-image s (implementing a hash lock), the assets locked in the contract may be taken off and the assets that need to be locked are sent to the contract.

Step 2, cross-chain asset transfer based on the SPV anchor mode, as shown in fig. 2.

SPV mode refers to a special address that issues a transaction to the main chain, thereby automatically creating an SPV certificate to the sidechain and initiating a transaction to unlock the corresponding asset on the sidechain. Assuming that asset transfer is performed between the a-chain and the B-chain, cross-chain payment has the following steps:

1) locking the a-chain assets may be accomplished using a multi-signature account.

2) A validation period, which may be one or two days, is waited on the a-chain to ensure that sufficient workload is generated to resist denial of service attacks.

3) After the A-chain validation period is over, the user can create a coinage transaction on the B-chain and provide SPV proof of the A-chain coinage transaction, creating an asset in the B-chain that is in a locked state, and waiting for a competition period.

4) The user waits for a contention period on the B-chain, which is set to prevent double spending. If during the competition period, the user transfers the coin locked on the A chain away, and other users can use the latest SPV to prove the fact, the B chain coin transaction is invalid, and the proof is called as recombination proof.

5) After the competition period (about 1 to 2 days), the B-chain token is generated and can be circulated in the B-chain.

6) The B-chain token returns to the a-chain and the process repeats the 5 steps described above.

And 3, realizing cross-chain transaction based on the Hash locking and SPV anchoring mode.

Assuming that cross-chain transaction is performed between a user A on the A chain and a user B on the B chain, the cross-chain transaction has the following steps

1) User a generates a random number s and computes a hash value H(s), where H represents a hash function.

2) User a locks token a requiring a transaction on the a-chain using h(s) and a validation period of time.

3) User a sends the calculated h(s) to user B and proves that his own token a to be traded has been locked.

4) After the A-chain validation period is over, user B may generate a coinage transaction on the B-chain and provide SPV proof of the A-chain coinage transaction, creating an asset in the B-chain that is in a locked state, and waiting for a competition period.

5) User B waits on the B chain for a contention period (). If during the competition period, user A transfers the coin locked on chain A away, and other users can use the latest SPV to prove the fact, the B chain coin transaction is invalid, and the proof is called as recombination proof.

6) After the competition period is over, the token is generated in the B chain, and the B user obtains the token just generated by using H(s).

Specifically, the invention is mainly based on the block chain technology, utilizes the side chain technology to solve the defect that only asset exchange can be realized but asset transfer cannot be realized in the Hash locking technology, and utilizes the Hash locking technology to realize cross-chain asset transfer without additionally adding a side chain or a relay chain. The technical solution in the embodiment of the present invention will be described in detail below.

Step 1, creating a hash-based locking transaction.

In the embodiment of the invention, a user Alice uses 1BTC and Bob to exchange 50 ETHs, and the cross-chain transaction process is as follows:

1, Alice randomly constructs a character string s and calculates the Hash h(s);

alice sends h(s) to Bob;

3, Alice locks 1BTC asset of Alice through a contract, sets a longer locking time, and then sets the conditions for obtaining the BTC: bob provides the original value s of h(s);

bob locks 50ETH to its own contract, setting a relatively short lock time (). And setting an acquisition condition of 50 ETH: alice provides the original value s of h(s);

alice sends the character string s to Bob's contract to obtain 50 ETHs;

bob observes the s value of Alice in the step 5, and sends the s value to Alice contract to successfully obtain 1 BTC; this completes the exchange of assets.

7. If it times out, the locked asset returns to the original master.

Step 2, cross-chain asset transfer based on SPV anchoring mode

In the embodiment of the invention, the 1BTC on the user bitcoin is transferred to the Etherhouse to become 50 ETH.

1) Locking 1BTC on bitcoin may be implemented using a multi-signature account.

2) An acknowledgement period is waited on the bits for a time to ensure that sufficient workload is generated to resist denial of service attacks.

3) After the confirmation period on bitcoin is over, the user may create a coinage transaction on the Etherhouse and provide SPV proofs of the bitcoin-over-coin transaction, the created Etherhouse asset being in a locked state, requiring a wait for a competition period.

4) The user waits for a contention period (preventing double spending) in the ether house. If a user diverts a coin locked on a bitcoin away during a competitive period and other users can use the latest SPV to prove this, the EtherFang coinage transaction fails, which is called a reorganization proof.

When the bitcoin network needs to use the SPV to perform simple payment verification, the steps are as follows:

1) calculating a transaction hash value of the payment to be verified; the node acquires and stores all block heads of the longest chain from the block chain network to the local;

2) the node acquires a Mercker tree hash authentication path corresponding to payment to be verified from the block chain;

3) calculating a root hash value of the Mercker tree according to the hash authentication path, comparing the calculation result with the root hash value of the Mercker tree in the local block head, and positioning the block containing the payment to be verified;

4) verifying whether the block head of the block is contained in the known longest chain or not according to the position of the block head, determining the confirmation quantity obtained by the payment, and if so, proving that the payment is true and valid.

Step 3, realizing cross-chain transaction based on Hash locking and SPV anchoring mode

Assuming that a cross-chain transaction is conducted between a user Alice in bitcoin and a user Bob in an etherhouse, the cross-chain transaction has the following steps:

1) the user Alice generates a random number s and computes a hash value H(s), where H represents a hash function.

2) The user Alice locks the token a requiring a transaction on the bitcoin using h(s) and a validation period time, t 1.

3) The user Alice sends the calculated h(s) to the user Bob and proves that his or her token a to be traded has been locked.

4) After the confirmation period of the bitcoin is over, user B may generate a coinage transaction at the ethernet bay and provide SPV proof of the bitcoin lock transaction, and the resulting ethernet bay asset is in a locked state and needs to wait for a contention period.

5) User B waits on the ether house for a contention period (). If during the competition period, user A transfers the locked coin off the bitcoin and other users can use the latest SPV to prove the fact, the Ethengfang coinage transaction is invalid, and the proof is called a reorganization proof.

6) After the competition period is over, the house generates tokens and the B user uses h(s) to obtain the tokens that have just been generated.

When the bitcoin network needs to use the SPV to perform simple payment verification, the steps are as follows:

1) calculating a transaction hash value of the payment to be verified; the node acquires and stores all block heads of the longest chain from the block chain network to the local;

2) the node acquires a Mercker tree hash authentication path corresponding to payment to be verified from the block chain;

3) calculating a root hash value of the Mercker tree according to the hash authentication path, comparing the calculation result with the root hash value of the Mercker tree in the local block head, and positioning the block containing the payment to be verified;

4) verifying whether the block head of the block is contained in the known longest chain or not according to the position of the block head, determining the confirmation quantity obtained by the payment, and if so, proving that the payment is true and valid.

A cross-chain transaction system based on hash locking and side-chain techniques, comprising:

a mechanism creation module: the atom exchange data transmission mechanism is used for creating hash locking based on the first terminal and the second terminal; the data transfer mechanism is also used for creating a cross-chain data transfer mechanism based on the SPV anchoring mode;

a data transmission module: the method is used for realizing the hash locking based atomic exchange data transmission of the first terminal and the second terminal in the SPV anchoring mode supervision state.

A computer storage medium having stored thereon a computer program for performing the steps of a cross-chain transaction based on hash-locking and side-chain techniques when executed by a processor.

The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

9页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种区块链系统匿名抢红包方法、设备及储存介质

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!