Atomic swap, or atomic cross-chain trading, is the exchange of one cryptocurrency to another cryptocurrency, without the need to trust a third-party. The atomic swap process is completely trustless and works by ensuring both parties fulfill the requirements of the trade, as defined in the contract. If one fails to meet the requirements, the time-locked contract will refund the other user.
Let’s explain an atomic swap with a classic example of Alice and Bob. Alice owns one komodo coin, but really wants one dash instead. Normally, Alice would have to trade her komodo coin for an intermediary coin, like bitcoin, in order to trade the bitcoin for one dash coin. If so, she will lose some money because she has to trade twice.
With atomic swap technology available, users are able to trade on a peer-to-peer basis without the need for an exchange. A time-locked contract will be used to act as the escrow between Alice and Bob. Alice puts in her one komodo coin and Bob has to send his dash coin to the contract. The contract will take care of the swap, so Alice becomes the owner of one dash and Bob of one komodo coin.
Tech details on atomic swap
As mentioned before, an atomic swap uses a hash time-locked contract. This contract basically sets up a payment channel between two blockchains. However, not every blockchain supports payment channels. To support this, a blockchain needs to implement the Lightning Network, a solution which allows to open and close those payment channels which execute off-chain transactions. After a certain amount of time, the channel will be closed and the end balances will be submitted to both blockchains.
The contracts used in these transactions are hash time-locked contracts. A hash can be defined as a fingerprint of a piece of data, created by performing mathematical functions. In order to create this kind of hash contract between blockchains, both blockchains have to support the same cryptographic hash function, such as SHA-256.
A hash time-locked contract is set up by the person who will be making the initial payment. This person has to provide a specific hash, which represents the amount of money that will be paid. To receive the payment, the recipient will have to create a cryptographic proof of payment within the specified amount of time. If the recipient meets the deadline, the swap will be executed. Otherwise, the initializer of the contract will be refunded.
Why is atomic swap technology needed?
Currently, cryptocurrency users trust centralized exchanges, like Bittrex or Poloniex, to trade their coins. If something happens with an exchange, there is no way to recover the lost coins because the owners cannot prove what amounts they owned. Centralized exchanges are more vulnerable to attacks such as hacks, inefficiencies, manipulation, and even human error. These can all result in financial loss. Atomic swaps removes the need for an exchange completely. As such, transaction fees are reduced to zero.
Another reason atomic swap technology is needed is the so-called ‘failure’ of decentralized exchanges (DEXs). A DEX is not capable of handling a large amount of trades. Some of these decentralized exchanges have become a ‘blockchain-based exchange’. This solution is not ideal, as the blockchain-based exchanges can only provide traders the ability to exchange currency within their own blockchain. This forces the traders to use a proxy token, such as BitUSD or wBTC. BitUSD is actually a decentralized dollar and is not controlled by any government or authority. Each BitUSD is backed by two fiat dollars.
Finally, atomic swaps can be executed very quickly. The cryptographic proof of payment helps to validate the payment on the blockchain, making the validation faster.
Komodo project
The Komodo team is really pushing the boundaries of atomic swap technology. They have successfully completed an atomic swap using an Electrum server. This is important as it enables users to swap a coin without having to download the whole blockchain. This brings the Komodo team one step closer to realizing their goal of building a fully functional decentralized exchange, which they will name BarterDex.
Komodo has completed some successful atomic swaps from vertcoin to komodo, and from decred to bitcoin.