What is a Hashed Timelock Contract (HTLC)?

There are many aspects about cryptocurrency most people have never heard of, and one of these technological features goes by the name of Hashed Timelock Contracts or HTLCs. This feature can prove to be quite powerful when it comes conducting payments, so it’s time to take a closer look at what this exactly means for Bitcoin and potentially for other cryptocurrencies as well.

Hashed Timelock Contract

An Overview of HTLC

The Hashed Timelock Contract is a very technical implementation of cryptocurrency payments. It requires the recipient of a payment to acknowledge the reception of said transfer prior to a deadline, which is done by generating a cryptographic proof of payment or forfeit the ability to claim the payment, returning it to the payer. So far, that sounds not out of the ordinary. However, there is a small twist to this whole concept.

The cryptographic proof of payment the receiver generates can then be used to trigger other actions in other payments. This makes making HTLCs a powerful technique for producing conditional payments in Bitcoin. It is not difficult to see why this technology would be so powerful and popular, and in fact, there are multiple sue cases where this technology will come in handy.

For instance, it is not impossible to think the cryptocurrency ecosystem will be introduced to atomic cross-chain trading based on hashed Timelock Contracts. This type of trading allows users to exchange some amount of one cryptocurrency (such as bitcoin on mainnet) into some amount of cryptocurrency on another block chain (such as bitcoin on a sidechain). This can be achieved by using sidechains – as proposed by Drivechain. However, a proper payment channel would need to be provided.

This implementation of Hashed Timelock Contracts as part of atomic cross-chain trading is probably the origin of the technique now called HTLCs. It is important to note that it is also possible to use HTLC in payment channels moving forward. Payment channels use timelocks by default. However, they can be “extended” with hashlocks, and as a result, one would be able to route [Bitcoin] payments through two or more payment channels.

All of this sounds amazing and exciting. However, when it comes to cryptocurrency payments, there is a secondary aspect to Hashed Timelock Contracts. This technology also allows the recipient of a payment to forfeit the ability to claim the pending transfer, and by doing so, they will effectively return the money to the sender. Although it could prove to be quite useful in the long run, up until now, that seemed very improbable where bitcoin is concerned.

This is how HTLC scripts look like:

1

 

2

3

4

5

6

7

OP_IF

 

    [HASHOP] <digest> OP_EQUALVERIFY OP_DUP OP_HASH160 <seller pubkey hash>

OP_ELSE

    <num> [TIMEOUTOP] OP_DROP OP_DUP OP_HASH160 <buyer pubkey hash>

OP_ENDIF

OP_EQUALVERIFY

OP_CHECKSIG

HASHOP is a hashing algorithm (RIPEMD, SHA256). TIMEOUTOP is either OP_CHECKSEQUENCEVERIFY or OP_CHECKLOCKTIMEVERIFY. This script allows the “buyer” to buy the preimage to <digest> by forcing the seller to reveal it when they claim their funds, and if the seller doesn’t reveal it, the buyer can get their money back after the timeout period.

It’s really easy to understand how cross-chain atomic swaps can be built with this mechanism:

  1. Ann randomly samples K, the key, and she hashes it, producing X.
  2. To produce the preimage of X, Ann creates a transaction paying Bill 1 BTC, with a timeout of 1 day.
  3. Bill waits for Ann’s transaction to appear in the Bitcoin blockchain. After that, he submits an HTLC transaction paying Ann 0.02 ZEC for the preimage of X with a smaller timeout of half a day.
  4. Ann can obtain her ZEC once Bill’s transaction appears in the Zcash blockchain. The script forces Ann to reveal K.
  5. Bill can obtain his BTC once he sees Ann’s reveal of K.

The timeouts are selected so that Bill always has an opportunity to obtain a refund before Ann, otherwise, she could wait to obtain her refund, and then claim his money by revealing K.

Conclusion

In the end, HTLCs are a well-known and simple technique for building protocols for atomic swaps. Conditional payments can be quite beneficial to cryptocurrency as a whole in the future, so it is not difficult to see why developers are excited about Hashed Timelock Contracts. HTLCs are a fundamental tool in the Lightning network, in zero-knowledge contingent payments (ZKCP).  The opportunities for this technological feature are virtually limitless. Hashed Timelock Contracts are an area of development well worth exploring further.

intelligent crypto
How are  regular people making returns of as much as 70% in a year with no risk?  By properly setting up a FREE Pionex grid bot - click the button to learn more.
Crypto arbitrage still works like a charm, if you do it right! Check out Alphador, leading crypto arbitrage bot to learn the best way of doing it.

Philipp Traugott
Philipp Traugott

Phil Traugott is a staff writer at CaptainAltcoin. As a trained marketing specialist for copywriting and creative campaigns, he has been advising top companies on the following topics: online marketing, SEO and software branding for more than 10 years. The topic of crypto currencies is becoming increasingly important for companies and investors and he found it very alluring and fitting for his skillset which prompted him to pivot his career towards blockchain and cryptocurrencies.

We will be happy to hear your thoughts

Leave a reply

CaptainAltcoin
Logo