Crypto glossary
Hashed timelock contract (HTLC)
A hashed timelock contract (HTLC) locks funds so the recipient must reveal a secret before a deadline to claim them, or the sender gets a refund.
An HTLC combines two conditions. The hashlock says the funds can be claimed by whoever presents the preimage of a given hash, a secret value. The timelock says that if nobody does so before a certain block height or time, the original sender can take the funds back. Either the secret is revealed and the payment goes through, or the deadline passes and it is cancelled.
This simple construction powers Lightning routing. When Alice pays Carol through Bob, Alice locks funds to Bob and Bob locks funds to Carol, all under the same hash. Carol reveals the secret to claim her payment, which lets Bob claim his from Alice, so no intermediary can steal the funds. The same idea enables atomic swaps between chains and submarine swaps between Lightning and on-chain bitcoin.
HTLCs have weaknesses. Locked funds can be stuck until the timelock expires if a payment fails mid-route, which attackers can exploit to jam channels. Because every hop uses the same hash, payments can be correlated, a privacy issue that newer designs based on point timelock contracts aim to fix.
Example
In an atomic swap, Alice locks BTC with an HTLC and Bob locks LTC with the same hash; when Alice reveals the secret to claim the LTC, Bob uses it to claim the BTC.
