DEFINITION of Hashed Timelock Contract
A Hashed Timelock Contract (HTLC) is a type of smart contract used in cryptocurrency channels to eliminate counterparty risk. It enables implementation of time-bound transactions.
In practical terms, this means that recipients of a transaction have to acknowledge payment by generating cryptographic proof within a certain timeframe. Otherwise, the transaction does not take place.
Atomic cross-chain trading between cryptocurrencies is implemented using HTLC. Bitcoin’s lightning network also uses HTLC. (See also: Bitcoin's Lightning Network: 3 Possible Problems.)
BREAKING DOWN Hashed Timelock Contract
A Hashed Timelock Contract (HTLC) uses several elements from existing cryptocurrency transactions. For example, HTLC transactions use multiple signatures, which consist of a private a public key, to verify and validate transactions. But there are two elements which distinguish HTLC from standard cryptocurrency transactions.
The first one is hashlock. A hashlock is a scrambled version of a cryptographic key generated by the originator of a transaction. It is used to unlock the original hash. In HTLC, the originating party generates a key and hashes it. The hash is stored in a pre-image that is subsequently revealed during the final transaction.
The second important element of HTLC is a timelock. Two different time locks are used to set time constraints on contracts generated using HTLC. The first one is CheckLockTimeVerify (CLTV). It uses a time base to lock and release bitcoins. This means that time constraints are hard coded and coins are released only at a specific time and date or a specific height of block size.
The second one is CheckSequenceVerify (CSV). It is not dependent on time. Instead, it uses the number of blocks generated as a measure to keep track of when to finalize a transaction.
To conduct a transaction using HTLC, interested parties need to open channels with each other.
How Is HTLC Implemented Practically?
Suppose Alice wants to exchange her bitcoin for litecoin from Bob. A typical HTLC transaction between them takes place as follows:
1. Alice generates a hash from her private key and sends it to Bob on litecoin blockchain. She also generates a pre-image of the hash by creating a nominal transaction. This pre-image will help her validate and finalize the transaction.
2. Bob also generates a hash from his key and sends it to Alice. In addition to this, he creates a pre-image by conducting a nominal transaction (in litecoin) with Alice.
3. Once Alice receives Bob’s litecoin transaction, she signs it using the original key that is already available with her in the pre-image. Bob does likewise on his end, using his private key to unlock Alice’s transaction. (See also: What Is Litecoin And How Does It Work?)