Hashed TimeLock Contract (HTLC)
Community Submission - Author: Anonymous
The term Hashed TimeLock Contract (HTLC) refers to a special feature that is used to create
smart contracts that are able to modify payment channels. Technically, the HTLC feature enables the implementation of time-bound transactions between two users. In practice, the recipient of a HTLC transaction has to acknowledge the payment by submitting a cryptographic proof within a specified timeframe (number of blocks). If the recipient forfeits or fails to claim the payment, the funds will be returned to the original sender.
The HTLC feature is applied in both bidirectional and routed payment channels to allow the secure transfers of funds over various channels, without requiring trust on any of the intermediaries.
There are two key elements which distinguish HTLC from standard cryptocurrency transactions, which are:
- Hashlock: a function that restricts the spending of funds until a certain piece of data is publicly disclosed (as a cryptographic proof). Such proof may also be referred to as the pre-image of the hashlock. The pre-image is simply the piece of information that is used to generate the hashlock, and to later unlock its funds.
- Timelock: is a function that restricts the spending of funds until a specific time (or block height) in the future. It can be achieved in Bitcoin, for example, using functions like CheckLockTimeVerify or CheckSequenceVerify.
The Bitcoin
Lightning Network is among the most popular use cases of Hashed Timelocked Contracts. By implementing HTLC into payment channels, funds can be transacted from user to user through interconnected payment channels, without requiring any level of trust. This process is known as network routing. It allows Alice to exchange funds with Carol even if they are not directly connected through a payment channel. HTLC’s enable Alice to send her funds to Carol through other participants of the network (e.g., Bob) - and the hashlock and timelock features ensure that Bob cannot intercept the funds.
Besides being used on the Lightning Network, HTLCs can also be useful in other contexts, such as cross-chain
atomic swaps, financial smart contracts and escrow, and much more.