Gold standard: atomic swap

Since Ethereum launched, the community has been exploring ways to use smart contracts to compute cryptographic proofs that allow transactions on one chain to be trustlessly verified on another chain. In fact, back in 2016, the Dogethereum DAO raised well over 5000 ETH to verify Dogecoin transactions in an Ethereum smart contract. This effort aims to develop a cross-chain bridge between Doge, which is similar to Bitcoin, and Ethereum. Unfortunately, this challenge has proven difficult, with the millions of dollars worth of DAO bounty staying unclaimed for years. In addition, the on-chain smart contracts simply lack the computing power to validate cross-chain transactions cryptographically.

What is an atomic swap

The current gold standard for cross-chain transactions is Atomic Swap. That is to rely on off-chain actors to validate transactions in a trustless manner and record the results in on-chain smart contracts. For example, let’s say that Alice holds a token on chain A, and Bob holds a token on chain B. They want to do a swap, allowing Alice to move her token from chain A to chain B, and vice versa for Bob. An atomic swap consists of multiple steps performed by both Alice and Bob, and the swap is only successful after all the steps are successful. If any one of them fails to perform any step, the swap will not happen, and they will each still hold their original tokens.

  • Alice uses her private key A to create a Hashed Timelock Contract (HTLC) on chain A.

  • Alice deposits her tokens to HTLC A. The contract generates a hashed key A and stores it in HTLC A for the public to see.

  • Bob sees hashed key A and wants to trade with Alice.

  • Bob uses his private key B and hashed key A to create another HTLC on chain B.

  • Bob deposits his tokens to the HTLC B he just created on chain B.

  • Now, if Alice is satisfied that Bob puts enough tokens in HTLC B, Alice uses her private key A to unlock HTLC B and withdraws Bob’s tokens.

  • In the process, HTLC B will record proof of withdrawal in HTLC B for everyone to see.

  • Bob uses his private key B and the proof of withdrawal on B to unlock HTLC A and get Alice’s tokens.

All these happen without Alice or Bob knowing each other. They can use public communication channels to exchange information about the next step in the process. It is also important to note that if any party is unhappy at any time, he or she can simply refuse to perform the next step. The “timelock” in HTLC will expire after some time (eg, 2 hours), allowing each party to withdraw their original deposits. For example, if Bob does not put enough tokens into HTLC B, Alice could simply not unlock HTLC B and wait for HTLC A to expire.

The advantage of the atomic swap approach is that it is entirely decentralized and trustless. It is the “right way” to do cross-chain bridges, and is the gold standard every alternative solution must compare to.

Why atomic swap is not widely used

However, the disadvantages are also glaring.

First, as the Dogethereum challenge had shown, it is not easy to create interoperable HTLCs across different blockchains, programming languages, and VM runtimes.

Second, The multi-step process involving on-chain smart contract calls and cryptographic proofs is too complex for most users. It is challenging to grasp those concepts. And worse, if you do not understand the technical details, it is straightforward to make mistakes and fall into scams. If Alice is a retail investor who is new to chain B, she faces additional hurdles.

  • Alice needs to operate in two different wallets and switch wallets at different steps, which could be very confusing and error-prone. Such errors could lead to failed exchanges or even leaked private keys.

  • Alice typically has no native token on chain B to pay for gas fees or to even withdraw the tokens she receives from HTLC B.

The UI and UX of HTLC-based atomic swap are very challenging. That has severely limited its usefulness.

Third, atomic swap requires both parties of the exchange (i.e., Alice and Bob) to be online at the same time. Since cross-chain exchanges do not happen all that often, it is nearly impossible to match parties with exact opposite exchange needs at the same time.

The bridge liquidity pool, including the lock-and-mint pool, emerged as the solution for those challenges. Today, most cross-chain bridges are pool-based.

Last updated