blog posts

What is Atomic Swap?

Convert digital currencies to each other without the need for centralized intermediaries; This is a brief definition of atomic swap or “atomic exchange”. It may not be an exaggeration to say that nuclear exchanges are the missing link that the world of digital currencies needs. Simply put, users of digital currencies can buy and sell various digital currencies directly through their wallets, directly and without the need for any intermediaries (such as trust accounts or exchange offices) through atomic exchanges. In this guide, we are going to talk about how atomic swap works as well as the benefits of this method for the crypto ecosystem. Stay tuned with Digital Currency.

In July 2012, a programmer named Sergio Demian Lerner released the first draft of the “Trust-Free and Immediate Transaction Protocol” draft. The overall idea was brilliant, but the plan failed to go into detail.

The first major leap in nuclear exchanges occurred around May 2013, when Tier Nolan first presented a complete blueprint for the nuclear exchange process. Nolan is currently the main inventor of the atomic swap.

Before talking about nuclear exchanges, let’s talk about the origins and reasons for the emergence of this technology. About that despite hundreds of currency exchange large digital currencies, what need to conduct a nuclear exchange in the wallet are we?

Digital currency exchanges and the old problem of centralized intermediaries

Digital currency exchange
The bankruptcy of EmtiGax, the world’s largest bitcoin exchange, in 2014; Where is our money?

Imagine that Behzad has some bitcoins and wants to sell them in exchange for light coins. On the other hand, Majid has some light coins that he wants to exchange for bitcoins. It is often the case that both transfer their digital currencies to exchange. And buy the digital currency they want by selling it. But the simplest solution is not always the best solution! There are many problems with digital currency exchanges, some of which we will briefly review here.

Vulnerability and hacking

If we put aside the usual optimism and see the facts, centralized exchanges are always at risk of being hacked. Perhaps the most famous example of an exchange that has experienced hacking attacks is the Japanese exchange Coincheck. The hack took place in January 2018 and resulted in $ 550 million worth of coins NEM in the theft. The sad part is that after the attack, the Japanese public interest in digital currencies declined dramatically, while the country was already known for its widespread acceptance of digital currencies. All other major exchanges, including Binance and Bitfinx, have experienced one or more hacks.

Mismanagement

Bankruptcy Exchange Mt. Gox where bits Kvynhayy worth $ 500 million (in 2014) were stolen, precisely because Sv’mdyrythay Karplz Max (Max Karpeles), Director of the exchange took place. As of 2020, many users of this exchange have not returned their money.

In a centralized exchange, it is not clear what they do with your money and what it is used for.

Demand changes

Digital currency exchanges are unable to adapt to changes in demand from users; Especially when demand rises sharply. In such cases, part of the transaction will often take some time due to insufficient liquidity of the exchange (liquidity) and the exchange will be out of reach for a while. If you have traded in a small exchange, you have probably tasted the bitter taste of not having a buyer or seller for a digital currency.

Sanctions and legal problems

Because centralized exchanges are often registered in a specific country, they are always subject to government legislation and the influence of powers. For example, most of the world’s leading exchanges require their users to authenticate and refuse to provide services to Iranian users under international sanctions. Centralized exchanges are not an ideal solution for the general acceptance of digital currencies.

Despite all this, as long as we are talking about buying and selling digital currencies using Fiat currencies, we have no choice but to use centralized exchanges in the current form, but to exchange digital currencies or trade digital currencies with each other, we can He used alternative solutions that do not have the problems of centralized exchanges and at the same time are safe, this is where atomic exchanges come into play.

What are Atomic Swaps?

What is Atomic Swap?

Atomic swap, or atomic exchange, is a method of exchanging digital currencies directly from person to person; In such a way that there is no need for intermediary institutions such as exchange offices. When conducting nuclear exchanges, the control of private keys will be entirely at the users’ discretion.

The word “atomic” is an adjective derived from the word “atom” meaning “indivisible.” Greek scientists first used the word atom to refer to the smallest component of matter; Even today in programming and database sciences, the word atom is used to refer to a set of indivisible operations; Anatomic set consists of functions and operations that either all occur together or none at all. For example, suppose we want to exchange bitcoin for light coin; This operation involves two transactions: one for bitcoin transfer and the other for light coin transfer. But such an operation should never be done half-heartedly. We want both transactions to be done at the same time, or neither at all. We want the swap to be atomic.

On September 20, 2017, the first successful implementation of the atomic swap between Decred and Litecoin took place.

Atomic swaps can be applied directly between separate china blocks (with different coins). This feature over decentralized exchanges is an important advantage. As in most decentralized exchanges, individuals can only exchange tokens based on a particular blockchain. For example, on the Uniswap platform, which is the largest decentralized exchange, it is now only possible to exchange tokens based on Ethereum, you can not directly convert bitcoins to Ethereum. But with atomic swaps, bridges can be created between blocks of different layers. For this reason, atomic exchanges are also known as cross-chain trading.

You can read more about how nuclear exchanges work but in simple terms. These exchanges use technology similar to the smart contract (like a regular contract but with an executive guarantee). In the following example, you will get acquainted with the general process of atomic swap:

  • Person A wants to turn bitcoin into an Ethereum.
  • B wants to convert Ethereum to Bitcoin.
  • A moves the bitcoin to an address and the bitcoin is locked.
  • B transfers the Ethereum to an address, bitcoin is released to him and Ethereum is released to person B.

Many companies are currently trying to build wallets and platforms based on atomic swaps, but due to the limitations you read about at the end of this article, no significant product has been released yet.

How Do Atomic Exchanges Work?

Let’s start with a simple explanation; When two people want to participate in an atomic swap, they use a common private key. The exchange of the desired digital currencies will take place only if the key provided by both people matches each other. With this mechanism, if another person infiltrates this exchange, he will not be able to take over the traded coins; Because he is unaware of the common private key between the two parties to the transaction.

By now you have learned the general concept; Let’s see how this process works in practice. To perform this whole process, something called Hashed Timelock Contracts, or HTLC for short, is used. If you are with Lightning Network familiar with Bitcoin, you probably know how HTLC works. The following is a brief description of encrypted timed contracts.

What are encrypted timed contracts?

What is Atomic Swap?

Encrypted timed contracts are a special type of payment channel. Payment channels are off-chain state channels that are set up to settle payments.

Status channels are a type of two-way communication channel that enables individuals to move operations that normally occur on the blockchain outside the blockchain. Thus, it can be said that status channels dramatically reduce the time required to complete transactions; Because if you use off-channel channels, there is no need for intermediaries (such as miners) to validate and approve transactions.

This process is exactly what happens in the payment channels of the Bitcoin Lightning Network. As you know, one of the challenges for Bitcoin to become a payment tool is the slow speed of registering transactions on the Chinese blockchain, which is called the scalability problem. Lightning Network’s initiative to solve this problem is that people set up a two-way payment channel for their daily payments (for example, buying a cup of coffee daily) so that payments can be made out of the chain on this channel.

With each payment, the new balance of the two parties to the transaction is updated in the status channel, and finally, when two users want to end their exchanges, by closing the channel. they send a transaction to the China block and the latest balance status of each in the China block. will be recorded.

After this brief reminder, let’s return to our main discussion; What are the requirements for setting up an Afshin canal?

  • Part of the China Blockchain status is locked through multi-signature transactions or some kind of smart contract (agreed upon by the participants).
  • Participants interact with each other by signing transactions among themselves without sending transactions to network miners.
  • Finally, the set of transactions made in the form of a transaction is sent to the network and added to the China block.

Status channels can be closed at a specific time specified by the participants in the transaction. The closing time of the channel can be determined in one of two ways:

  • Determining the time limit; For example, participants can agree to create a channel that closes after two hours.
  • Determining transfer restrictions; This means that the closing time of the channel is determined by setting a ceiling on the total value of transactions. For example, participants agree to close the channel whenever the total value of transactions reaches $ 100.

Encrypted timed contracts, or HTLCs, are one of the most common uses for payment channels. But what exactly is HTLC?

HTLCs are payment channels that use “time locks” and “encryption locks”. HTLC is a contract that allows users to create a payment channel in which they can transfer their assets before it closes. These payments are verified and finalized by providing cryptographic proofs.

To simplify the concept of HTLC, we consider it as an escrow account. In the traditional definition. A trust account is an intermediary account between two parties to a transaction that receives money from the buyer and notifies the seller to send the goods to the buyer. If the goods reach the buyer and the buyer confirms the authenticity of the goods, the trust account will transfer the money to the seller. Also, in case of delay in sending the goods, or non-compliance with the terms of the transaction, the goods will be returned to the seller and the money will be returned to the buyer.