Hashlock

Also: HTLC hashlock, hash time-locked contract

cryptography · advanced

A script condition that requires the spender to reveal a preimage whose hash matches a value committed on-chain. The cryptographic half of an HTLC.

A hashlock is a script clause that locks a UTXO until someone reveals a secret. The output commits to a hash H; the spender provides a preimage x such that SHA256(x) == H. The simplest form:

``
OP_SHA256 <H> OP_EQUALVERIFY ... rest of the script ...
``

Hashlocks are the cryptographic half of an [HTLC](/glossary/htlc) — Hash Time-Locked Contract — the building block of [Lightning](/glossary/lightning) payment routing. The "hash" half locks until a preimage is revealed; the "time" half makes the lock expire after a deadline so funds aren't stranded if the preimage never comes.

A multi-hop Lightning payment uses one shared preimage R across every channel in the path. The receiver creates R and tells the sender only H = SHA256(R). Each channel along the route conditionally pays out on revealing R. When the receiver finally pulls funds at their end by revealing R, the preimage propagates backward through the channels — every hop can now also claim its payment, atomically.

Hashlocks predate Lightning. They show up in atomic swaps, where two parties exchange coins on different chains using the same preimage to guarantee both swaps happen or neither does. They also appear in time-bound deposit scripts and any "claim by revealing X" pattern.

Related terms

Where you'll see this