Latest Articles

Dollar gains, stocks teeter as US data suggests rates to stay higher

The dollar rose and a gauge of global equities slid on Thursday after data once again highlighted persistent U.S. labor market strength, suggesting the...
HomeCryptoHash locking of cross-chain technical solutions

Hash locking of cross-chain technical solutions

Hashlock and the Lightning Network
Hash lock, the full name of Hash TimeLock Contract, is a new technical implementation form proposed in the Lightning Network.

Hash lock mode refers to a mechanism in which users pay by guessing the original value of the hash value within a specified period of time. To put it simply, on the basis of smart contracts, both parties lock the assets first, and if both parties enter the original value of the correct hash value within a limited time, the transaction can be completed.

Under such a mechanism, fast confirmation of micropayments can be achieved, that is to say, the goal of fast confirmation of the Lightning Network can be achieved.

Next, Dabai will use the asset exchange of the application scenario of hash locking as an example to explain to everyone how hash locking is realized.

How to implement hash time lock?
In order to easily understand how the hash time lock is locked, here is an analogy of two locks, one is a hash lock and the other is a time lock.

  1. Hash lock

Locking by hash value, after locking, only the original value that generated the hash value is used to unlock, assuming the number is 123, the value after the hash is a03a, and the lock is locked by a03a, regardless of the hash collision, only Can be unlocked by 123.

  1. Time lock

Time lock requires the hash lock password to be entered within a specified time. If the time of the time lock is 1 hour, the user is required to enter the password of the hash lock within 1 hour. If the password of the hash lock is input after 1 hour, the time lock will still not be opened.

That is to say, the condition for opening the two locks at the same time is to enter the original value of the hash value within the specified time . .

Now Dabai will use the hash time-locking mechanism to exchange his bitcoins for ether at Xiaohei. The specific operation steps are as follows:

(1) Dabai first generates a random number S, and then sends the hash value H(S) of the random number to Xiaohei through the network, assuming that the random number is 123 and the hash value is a03a.

At the same time, Dabai performs time-locking and hash-locking. Assuming that the time-locked time is 1 hour, the hash value of the hash-locked lock is a03a. After locking, the bitcoins to be converted are locked on chain A.

(2) After Xiaohei receives the hash value “a03a” given by Dabai, Xiaohei deploys a smart contract on Ethereum based on this hash value, and deposits the same value of ether into the contract. Xiaohei’s smart contract requires Dabai to provide the password “123” within the specified time before he can take away the ether in the smart contract.

This process is equivalent to that Xiao Hei himself has locked two locks. The hash lock is the same as Dabai’s hash lock, and the same password is required to open it. If the time lock is half an hour.

(3) Dabai uses Xiaohei’s smart contract and enters his own password “123” within half an hour to open Xiaohei’s hash lock on chain B, and then he can take out Xiaohei’s smart contract. Ether (equivalent to Xiao Hei’s Ether, because the smart contract is created by Xiao He, and the ether in the contract is also transferred by Xiao He).

(4) Because Dabai entered the password when calling Xiaohei’s smart contract, Xiaohei also knows that the password is “123”, and he only needs to use this password to open the hash lock on chain A within one hour, Dabai The bitcoins will be transferred to Xiaohei.

Through the above process, it can be seen that Dabai can realize the exchange of Bitcoin to Ethereum through hash time locking. Of course, this often requires Dabai to pay a little more bitcoin to Xiaohei as a handling fee. After all, there is no free labor in the world.

Advantages and disadvantages of hash locking
After listening to Dabai’s explanation, some friends will be confused? Is it possible to have a hash lock? After all, Dabai must enter the hash lock password to take away Xiaohei’s ether, and Xiaohei can only open the hash lock on chain A after Dabai has entered the hash lock password on chain B. It seems that the hash lock can be done, why add a time lock?

In the hash time lock mechanism, if the time exceeds the specified time, the tokens locked in the system will be withdrawn . Therefore, plus the time lock effectively promotes Dabai to unlock the hash lock on chain B within the time specified by Xiaohe, Xiaohe will also unlock the hash on chain A within the time period specified by Dabai because of his own interests. Lock.

There is no need for mutual understanding between the entire process chain and the chain, which in turn promotes the speed of transactions. And if the transaction fails, there is no additional fee for hash locking.

However, the application scenarios of hash locking are relatively limited, and it supports relatively few functions.

Do you hope that the current trading platform will vigorously promote hash locking and move towards a decentralized DEX? Why?