10.02.2016 Views

Bitcoin and Cryptocurrency Technologies

1Qqc4BN

1Qqc4BN

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

10.5 Atomic Cross‐chain Swaps<br />

In <strong>Bitcoin</strong> it’s straightforward to create a single transaction that swaps currency or assets controlled<br />

by different people or entities. This is the intuition behind Coinjoin, which we studied in Chapter 6. It<br />

is also useful for trading smart property, which we looked at briefly in Chapter 9 <strong>and</strong> will return to in<br />

Chapter 11. The same idea enables selling domain names in Namecoin, as mentioned earlier in this<br />

chapter.<br />

But in all these cases, the swap transactions are confined to a single block chain, even if they involve<br />

different types of assets within that block chain. In general, a transaction on one altcoin is entirely<br />

independent of <strong>and</strong> has no way of referring to a transaction that happens on some other altcoin’s<br />

transaction history. But is this a fundamental limitation, or is there some way to swap one type of coin<br />

for another? That is, if Alice wants to sell a quantity ​a ​of altcoin to Bob in exchange for a quantity ​b​of<br />

his bitcoin, can they do so in an atomic fashion, without having to trust each other or relying on an<br />

intermediary, such as an exchange service? At first sight this seems impossible, because there is no<br />

way to force transactions on two different block chains to happen simultaneously. If one of them, say<br />

Alice, carries out her transfer before the other, what prevents him from reneging on his side of the<br />

bargain?<br />

The solution is clever, <strong>and</strong> involves cryptographic commitments <strong>and</strong> time‐locked deposits, both of<br />

which are techniques we’ve seen before. Figure 10.6 describes the protocol. For the moment, assume<br />

that blocks in the two block chains are generated in lockstep: one block is generated every time unit.<br />

Let ​T ​represent the time at the start of the protocol.<br />

1. Alice generates a refundable deposit of ​a​altcoins as follows:<br />

1.1 Alice generates a r<strong>and</strong>om string ​x​<strong>and</strong> computes the hash ​h=H(x)<br />

1.2 Alice generates ​DepositA​as shown below, but doesn’t publish it yet<br />

1.3 Alice generates ​RefundA​, <strong>and</strong> gets Bob’s signature on it<br />

1.4 Once Bob signs ​RefundA​, she publishes DepositA (but doesn’t publish ​RefundA​)<br />

2. Bob generates a refundable deposit of ​b​bitcoins as follows:<br />

2.1 Bob generates ​DepositB ​as shown below, but doesn’t publish it yet<br />

2.2 Bob generates ​RefundB​, <strong>and</strong> gets Alice’s signature on it<br />

2.2 Once Alice signs ​RefundB​, he publishes ​DepositB​(but doesn’t publish ​RefundB​)<br />

3. Case 1: Alice goes through with the swap<br />

3.1 Alice claims the bitcoins by time ​T​ 1​<br />

, revealing ​x​to Bob (<strong>and</strong> everyone) in the process<br />

3.2 Bob claims the altcoins by time ​T​ 2<br />

Case 2: Alice changes her mind, does not claim the altcoins, does not reveal ​x​to Bob<br />

3.1 Bob claims his altcoin refund at time ​T​ 1<br />

3.2 Alice claims her <strong>Bitcoin</strong> refund at time ​T​ 2<br />

280

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!