Atomic Swaps Explained: What They Are, How They Work, and Why They Are Important

Atomic Swaps enable parties to swap cryptocurrencies P2P by minimizing the need for trusted third party arbitration and the cost of mediation through programmatic escrows.

Atomic Swaps Explained: What They Are, How They Work, and Why They Are Important

Edit: Liquality Atomic Swaps are live for users to swap crypto p2p.

Try out our products:

Why Are Atomic Swaps Important?

The Cost of Mediation: Trusted Third Parties in Exchanges, DEXs, and OTC Markets

Prior to Bitcoin, transactions suffered from the inherent weaknesses of a trust-based model. Such models require parties to depend on institutions to facilitate transactions and reverse them in case of disputes. Lacking transaction finality, the need for trust spreads and parties involved in a transaction inherit the cost of mediation. The cost of mediation is typically expressed through fees and higher prices.

As alternatives, Bitcoin, Ethereum, and other cryptocurrency networks aim to offer natively secure and peer-to-peer (P2P) ways to transact. Yet, their markets still suffer from the added friction, risk, and cost of trusted third parties. Why do we still suffer the cost of mediation?

Centralized exchanges (eg. QuadrigaCX, Shapeshift), decentralized exchanges (DEXs, like EtherDelta and Bancor), and other financial services (eg. over-the-counter OTC escrow and custody solutions) reincarnate intermediation on decentralized networks, reintroducing the cost of mediation. By reverting back to old paradigms, these companies:

  1. Pass on more costs to their users, and
  2. Act as systematic points of failure

As such, it is critical to build solutions that disintermediate if we are to realize the potential of P2P programmable money. Luckily, Satoshi offered the foundation: “Transactions that are computationally impractical to reverse would protect sellers from fraud, and routine escrow mechanisms could easily be implemented to protect buyers” (Nakamoto, Bitcoin).

Atomic Swaps exemplify the application of irreversible transactions and escrow mechanisms. In doing so, they demonstrate what is possible through disintermediation and programmable money: P2P liquidity networks in an internet of money. Parties could atomic swap cryptocurrencies without:

  1. Trusting their counterparty, and
  2. Requiring mediation through a trusted third party

How Do Atomic Swaps Work?

The Challenge of Swapping Cryptocurrencies Without Trusted Third Party Mediation

As described in the Bitcoin Wiki: "The problem of an atomic swap is one where (at least) two parties, Alice and Bob, own coins, and want to exchange them without having to trust a third party (centralized exchange). A non-atomic trivial solution would have Alice send her coins to Bob, and then have Bob send other coins to Alice - but Bob has the option of going back on his end of the bargain and simply not following through with the protocol, ending up with both sets of coins."

In any other situation, Alice and Bob could pay an escrow service provider to act as the trusted third party. But given their propensity to minimize trust and the cost of mediation, they need some way to overcome this Mexican Standoff. The solution? Interactive escrows that ensure no single party ever holds both cryptocurrencies at the same time.

Mexican standoff in non-atomic swaps - Liquality
A Mexican Standoff between two parties in a non-atomic swap

Minimizing the Cost of Mediation through P2P Interactive, Programmable Escrows

In a typical ETH/BTC swap that is facilitated by a third party custodial escrow service, the workflow is as follows:

Third party custodial escrow service and the cost of mediation in non-atomic swaps - Liquality
Third Party Custodial Escrow Service + the Cost of Mediation: Success Scenario

Here, both party A and B deposit funds into a central escrow service. Once the service provider takes their fees, they send the remaining funds to the respective intended recipients. The middleman helps manage counterparty risk and settlement risk, but also introduces custodial risk.

Let’s observe the drawbacks of custodial risk:

Third party custodial escrow service and custodial risk in a non-atomic swap - Liquality
Third Party Custodial Escrow Service + the Cost of Mediation: Custodial Risk

In this worst case scenario, both parties send funds to the custodial escrow service and the trusted third party does not deliver. As a result, the parties lose their funds forever because cryptocurrency transactions are irreversible. This is unfortunately an all-too-common scenario in the crypto industry. Alternatives must exist to combat against intermediaries who control and silo liquidity.

Fortunately, the introduction of programmable money provides an opportunity for users to create their own financial applications like escrows. This empowers users to significantly minimize the need to trust in a third party. Programmable escrows (HTLCs) that can interact with and inform one another’s actions achieve atomicity.

Atomicity describes the binary all-or-nothing nature that defines atomic swaps: the successful execution of either a swap or refund. Atomicity is key to trust-minimized programmable money, and empowers P2P liquidity networks that are disintermediated from trusted third parties.

As such, we can program two escrows to communicate with one another, and depending on their interactions, they can either:

  1. Send funds to the intended recipients when specified conditions are met; or
  2. Refund the original sender of funds within a predetermined amount of time

Cross-chain atomic swaps leverage this dual escrow mechanism. Defining a standard protocol encumbers both sides of the swap to conduct themselves in the same way. In this example, one party deploys one escrow on one chain, and another party does the same on another chain:

Cross-chain atomic swap ETH BTC - Liquality
Atomic Swap Escrows: Successful Swap Scenario

In the success scenario above, both parties deploy escrows on their respective chains and send funds to their escrows. The escrows then, after informing one another of the proper receipts of funds, send funds to the intended recipients. In effect, the parties are able to swap in a P2P fashion without needing to trust and pay a third party.

Let’s imagine a scenario where:

  1. Only party A deploys an escrow and sends funds to it
  2. Party B fails to both deploy and send funds to their escrow within a specified expiration date
Cross-chain atomic swap ETH BTC refund - Liquality
Atomic Swap Escrows: Default Refund Scenario

In this “worst case scenario,” party A is refunded their Ether (ETH) after a predetermined amount of time. No harm, no foul.

Stay tuned for our upcoming blogpost on Hashed Timelock Contracts (HTLCs). In it, we will describe the standardized technical details behind these programmable escrows and how they achieve atomicity.

What Are Atomic Swaps?

Atomic swaps enable two or more parties to swap cryptocurrencies peer-to-peer without extending trust to a third party arbiter. Through programmatic escrows called HTLCs, they minimize the need for trusted third parties and the cost of mediation. Users and their counterparties can use atomic swaps to avoid paying unnecessary fees and minimize counterparty, settlement, and custodial risks. Atomic swaps provide an alternative to using trusted third parties like centralized exchanges, DEXs, and custody solutions when swapping cryptocurrencies OTC.

Atomic swaps exemplify what is possible through the paradigm of disintermediation and the revolution of programmable money. They enable users to:

  1. Own and deploy their own financial applications,
  2. Achieve greater financial sovereignty, and
  3. Strengthen P2P liquidity networks in the internet of money

Contributors to Liquality have launched mainnet Atomic Swaps between Bitcoin (BTC), Ether (ETH), DAI, USDC, USDT, and WBTC. Make sure to subscribe to our newsletter to receive future product updates.

If you have any comments, feedback, or questions, let us know in our Telegram community and follow us on twitter. And feel free to check out the infographic below on Atomic Swaps that summarizes the key points from the article above.

Atomic swaps infographic explained by Liquality

Share This Atomic Swaps Infographic On Your Site