Hash Time Locked Contracts: Difference between revisions
Fixed references tag and added category technical |
|||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
A ''' | A '''Hash Time Locked Contract''' or '''HTLC''' is a class of payments that use [[hashlock]]s and [[timelock]]s to require that the receiver of a payment either acknowledge receiving the payment prior to a deadline by generating cryptographic proof of payment or forfeit the ability to claim the payment, returning it to the payer.<ref name="russell_htlc" /> | ||
The cryptographic proof of payment the receiver generates can then be used to trigger other actions in other payments, making HTLCs a powerful technique for producing | The cryptographic proof of payment the receiver generates can then be used to trigger other actions in other payments, making HTLCs a powerful technique for producing | ||
Line 12: | Line 12: | ||
== HTLCs in payment channels == | == HTLCs in payment channels == | ||
[[Payment channels]] already use timelocks, and it can be relatively simple conceptually to extend them with hashlocks. | [[Payment channels]] already use timelocks, and it can be relatively simple conceptually to extend them with hashlocks. This provides the useful benefit of making payments routable across two or more payment channels, as done in the Lightning Network <ref name="lightning_network_htlc"/>. | ||
=== Example === | === Example === | ||
# Alice opens a payment channel to Bob, and Bob opens a payment channel to Charlie. | # Alice opens a payment channel to Bob, and Bob opens a payment channel to Charlie. | ||
# Alice wants to buy something from Charlie for | # Alice wants to buy something from Charlie for 1,000 satoshis. | ||
# Charlie generates a random number and generates its SHA256 hash. Charlie gives that hash to Alice. | # Charlie generates a random number and generates its SHA256 hash. Charlie gives that hash to Alice. | ||
# Alice uses her payment channel to Bob to pay him 1,000 satoshis, but she adds the hash Charlie gave her to the payment along with an extra condition: in order for Bob to claim the payment, he has to provide the data which was used to produce that hash. | # Alice uses her payment channel to Bob to pay him 1,000 satoshis, but she adds the hash Charlie gave her to the payment along with an extra condition: in order for Bob to claim the payment, he has to provide the data which was used to produce that hash. | ||
Line 27: | Line 27: | ||
<references> | <references> | ||
<ref name="russell_htlc">[https://rusty.ozlabs.org/?p=462 Lightning Networks Part II: Hashed Timelock Contracts (HTLCs)]</ref> | <ref name="russell_htlc">[https://rusty.ozlabs.org/?p=462 Lightning Networks Part II: Hashed Timelock Contracts (HTLCs)]</ref> | ||
<ref name="lightning_network_htlc">[https://lightning.network/lightning-network-paper.pdf#page=30 Hashed Timelock Contract (HTLC) in the Lightning Network paper]</ref> | |||
</references> | </references> | ||
[[Category:Technical]] | [[Category:Technical]] |
Latest revision as of 07:30, 4 October 2021
A Hash Time Locked Contract or HTLC is a class of payments that use hashlocks and timelocks to require that the receiver of a payment either acknowledge receiving the payment prior to a deadline by generating cryptographic proof of payment or forfeit the ability to claim the payment, returning it to the payer.[1]
The cryptographic proof of payment the receiver generates can then be used to trigger other actions in other payments, making HTLCs a powerful technique for producing conditional payments in Bitcoin.
HTLCs in cross-chain atomic swaps
Atomic cross-chain trading allows some amount of one cryptocurrency (such as bitcoin on mainnet) to be traded for some amount of cryptocurrency on another block chain (such as bitcoin on a sidechain).
Descriptions of cross-chain atomic swaps are probably the origin of the technique now called HTLCs.[citation needed]
HTLCs in payment channels
Payment channels already use timelocks, and it can be relatively simple conceptually to extend them with hashlocks. This provides the useful benefit of making payments routable across two or more payment channels, as done in the Lightning Network [2].
Example
- Alice opens a payment channel to Bob, and Bob opens a payment channel to Charlie.
- Alice wants to buy something from Charlie for 1,000 satoshis.
- Charlie generates a random number and generates its SHA256 hash. Charlie gives that hash to Alice.
- Alice uses her payment channel to Bob to pay him 1,000 satoshis, but she adds the hash Charlie gave her to the payment along with an extra condition: in order for Bob to claim the payment, he has to provide the data which was used to produce that hash.
- Bob uses his payment channel to Charlie to pay Charlie 1,000 satoshis, and Bob adds a copy of the same condition that Alice put on the payment she gave Bob.
- Charlie has the original data that was used to produce the hash (called a pre-image), so Charlie can use it to finalize his payment and fully receive the payment from Bob. By doing so, Charlie necessarily makes the pre-image available to Bob.
- Bob uses the pre-image to finalize his payment from Alice