This page is the Simplified Technical English version of ZIP 300. The source ZIP is the normative text. Read the writing rules to understand the marked words.
ZIP 300: Cross-chain Atomic Transactions
ZIP: 300 Title: Cross-chain Atomic Transactions Owners: Daira-Emma Hopwood <daira@jacaranda.org> Original-Authors: Jay Graber Status: Proposed Category: Informational Created: 2017-03-08 License: MIT Pull-Request: <https://github.com/zcash/zips/pull/123>
Abstract
This Informational ZIP contains a proposed specification for a standard protocol. The protocol is for cross-chain atomic transactions (XCAT) between Zcash and Bitcoin, or other cryptocurrencies that are derived from Bitcoin.
Status
This ZIP applies only to transparent cross-chain swaps. It depends on the script system that Zcash inherited from Bitcoin. At the time of writing (September 2020), the protocol was not in wide use.
Motivation
With a well-defined standard for cross-chain transactions, the liquidity of cryptocurrencies can increase. A well-defined standard can also be useful for third-party services, for example decentralized exchanges.
Specification
The proposed protocol for XCAT is a set of hash time-locked contracts on the two chains. Two parties that want to do a cross-chain exchange create these contracts.
For an exchange, it is necessary for each party to have the public keys of the other party, on the two chains. The party that wants to start the exchange is the "seller". The seller creates two hash time-locked contracts. To do this, the seller generates pay-to-script-hash (P2SH) addresses with the XCAT protocol and the public key of the counterparty (the "buyer").
In this example, the seller that starts the exchange has the name "Alice". The buyer that agrees to complete the exchange has the name "Bob".
Alice wants to start an XCAT exchange from Bitcoin to Zcash. She selects a random number R and hashes it. Then she creates a P2SH address on the Zcash block chain with her public key and the public key of Bob. She waits for Bob to fund this address with the amount that he wants to trade. (The agreement on the amount to trade and on the exchange rate is outside the scope of this protocol. This agreement can be determined out-of-band, or in the user interface of an application that uses XCAT internally.)
The script in the P2SH address has this form:
OP_IF
[HASHOP] <hash digest of R> OP_EQUALVERIFY OP_DUP OP_HASH160 <Alice's pubkey hash>
OP_ELSE
<time-out duration (24 hours)> CHECKLOCKTIMEVERIFY OP_DROP OP_DUP OP_HASH160 <Bob's pubkey hash>
OP_ENDIF
OP_EQUALVERIFY
OP_CHECKSIG
There are two scenarios to spend funds from this P2SH address. The first scenario is a successful atomic swap. In this scenario, Alice gets the money that she asked for, and Bob gets access to the secret R. Bob can use R to redeem his funds on the other block chain. The second scenario is a fail case. In this case, Bob gets his money back if Alice does not follow through.
- Success case: Alice spends the funds that Bob sent to the address. In this process, she reveals the random number R that she hashed to create the script.
- Fail case: Alice does not spend the funds that Bob sent to the address in the timeout period. Thus Bob sends his funds back to himself and cancels the transaction.
Alice creates this P2SH address on the Zcash block chain. At the same time, she must also create a P2SH address on the Bitcoin block chain. She funds this second address herself, with the amount of BTC that she wants to trade away.
The script for this second transaction has this form:
OP_IF
[HASHOP] <hash digest of R> OP_EQUALVERIFY OP_DUP OP_HASH160 <Bob's pubkey hash>
OP_ELSE
<time-out duration (48 hours)> CHECKLOCKTIMEVERIFY OP_DROP OP_DUP OP_HASH160 <Alice's pubkey hash>
OP_ENDIF
OP_EQUALVERIFY
OP_CHECKSIG
The two scenarios to spend funds from this second P2SH address are as follows:
- Success case: Bob uses R to spend the funds from this P2SH address. Alice revealed R to Bob before this step. She revealed R when she spent from the P2SH address that Bob sent ZEC to on the Zcash block chain. The cross-chain atomic transaction is now complete, and both parties have the funds that they requested.
- Fail case: Bob does not follow through on his part of the trade in the timeout period. Thus Alice sends her funds back to herself and cancels the transaction.
Timeout Periods
The XCAT protocol has timeout periods on the two transactions. With these timeout periods, a party can get a refund if the counterparty misbehaves. Thus the XCAT protocol can work.
In the example above, the timeout period is 24 hours for the first transaction and 48 hours for the second transaction. But these values are only suggestions. Consider the actual timeout periods to be variables. For each implementation of XCAT, these variables depend on the factors that follow.
Duration
Two transactions are important here. In the first transaction, the initiating party reveals R. In the second transaction, the other party uses the revealed R. The time-lock period on the first transaction must be significantly shorter than the time-lock period on the second transaction. The purpose is to give the other party enough time to use R to redeem their funds.
For example, Alice reveals R when she spends the funds that Bob sent to her P2SH address. After this, Bob must have enough time to use R to redeem his funds on the other block chain, before Alice can refund herself. If the delay between the first and second timeout periods is too short, Alice can possibly spend Bob's funds at the last minute. Then she can quickly refund herself on the other block chain, before Bob can redeem his portion with the R that she reveals.
Note: If the P2SH scripts use long time-locks, the transactions do not necessarily take a long time. If both parties respond immediately and do their trades on time with the correct information, the full cross-chain atomic trade can occur quickly. The full duration of the timeout period for each transaction passes only in the fail case. The fail case occurs when Alice or Bob does not complete the exchange that they agreed to.
Block times
The relative block times of the two block chains must be taken into account in the protection of the timeout period.
Rationale
Users are free to make their own protocols for cross-chain atomic transactions. But a well-defined protocol can be an aid to adoption. It can also be a support for third-party services that want to supply this functionality.