Principles of operation and application features of atomic swap

    This article highlights issues related to the relevance of the atomic exchange of different coins among themselves without the participation of intermediaries. We have tried to describe the features of the work of this exchange and the requirements for digital currencies to maintain this functionality. In addition, they discussed current issues of designing and launching decentralized exchanges based on atomic swap, as well as disadvantages and risks of their use.

    By definition, a cryptocurrency owner works with his coins without the participation of a trusted third party, that is, trustless. It is quite natural that users want to exchange these currencies on the same principle. Existing centralized exchanges cannot meet these requirements. This is evidenced by the numerous restrictions on the part of the exchanges themselves and the frequent incidents of their hacking.

    How is the exchange at the central site? Alice registers at the stock exchange and places an order for the purchase of a certain amount of coins of a certain cryptocurrency. Bob, who is already registered on this exchange, sees the order and, if he is satisfied with the price, agrees to it. The balances of the accounts on this exchange at Bob and Alice are changing. After that, they can withdraw this money to their wallets.

    In this situation, both Alice and Bob trust the exchange. More precisely, they trust the owners of the exchange that they will not take the money and not disappear with them. In a sense, users must trust the engineers who designed and developed the stock exchange, and other professionals who provide reliable protection against hackers and scammers.

    Currency idea and requirements


    The idea of ​​atomic metabolism was proposed as an alternative. Atomic swap is an exchange that is either inseparable or not at all. This approach allows you to make an exchange, even if users do not trust each other. In addition, the participant will not lose a coin, even if the opponent purposefully wants to deceive him.

    Atomic swap is an idea with great potential and can be implemented in different ways and for completely different digital currencies. Therefore, in this article we will limit ourselves to the specifics of the atomic swap operation for such cryptocurrencies such as Bitcoin and Ether.

    In order for a digital currency to successfully support an atomic swap, it must satisfy some fundamental requirements.

    The main one is the ability to create a smart contract with the possibility of a time delay. In addition, to make a transaction between two different accounting systems, it is necessary that both of them can use the same cryptographic hash function in specifying the conditions of spending coins (for example, SHA-256). This is necessary so that the contract is executed correctly when the user provides the result of the hash function. Moreover, for the successful implementation of the atomic swap, a communication channel is necessary, since users must off-chain discuss the terms of exchange.

    Principle of operation


    Atomic swap uses the so-called time-limited lock (HTLC). In fact, these are contracts that are supported by the digital currency accounting system itself. A pair of special contracts ensures that if the coins of one currency change their owner, then the coins of the second currency also. And if one of the parties to the contract does not confirm the transfer on time, the coins will be returned back to the original owners. Thus, coins of both currencies are blocked until all conditions are fulfilled and confirmed. Either the exchange of coins will be executed atomically, or will be rejected completely.

    image

    Consider this process in a more detailed scheme. Imagine two digital currencies that blockchain technology applies to account for: α and β. There are two members: Alice (A) and Bob (B). First, Alice creates a new address in the α blockchain and transfers it to Bob. Bob also creates a new address, but on the blockchain of currency β, and sends it to Alice.

    image

    Alice initiates a transaction with a smart contract, in which she blocks her coins, which she wants to exchange with Bob. Bob verifies this smart contract (conducts a manual or automated audit), creates his smart contract based on Alice’s contract and transfers it to her. In turn, Alice verifies Bob’s smart contract on the β blockchain and, if everything is correct, publishes her secret hash value on the β blockchain when unlocking coins that were blocked by Bob. Using this hash value, Bob can unlock the coins that Alice blocked α in the blockchain. Thus, the exchange is made. Until the first publication of the hash values, all participants remain with their coins, and after the participants can freely access the opponent's coins. That is why the exchange can be considered trustless.

    Confirmation time


    To accomplish a trustless atomic swap exchange, you only need 4 transactions, 2 in each blockchain, as well as off-chain communication between subjects to transfer the text of a smart contract. Therefore, the time to make an exchange using an atomic swap can take from 1 hour to the time specified in the smart contract of the subjects in a time delay.

    Currencies that support atomic swap


    Currencies that currently support atomic swap include:

    1. Bitcoin and its fork: Litecoin, Monacoin, Zcoin, Viacoin, etc.
    2. Ethereum and similar projects whose smart contracts are written in programming languages ​​and executed in virtual machines.

    It should be noted that there is still no single standard for atomic swap. Everyone who currently uses atomic swap uses cryptography and smart contracts without a single standard.

    Decentralized Exchange


    Based on atomic swap, you can build decentralized exchanges that allow you to work with several accounting systems, with your own blockchain for each. But when designing such decentralized exchanges, it must be remembered that anyone should be able to leave their offer to buy or sell. Therefore, you must first have a protocol that allows you to create an orderbook in a decentralized manner.

    As for the guarantees of orders, there are features. In the case of centralized exchanges, the entire balance is at the exchange. Therefore, despite the fact that the user can at any time cancel his order, until such time as it is not canceled, the exchange will fulfill this order in any case. For decentralized exchanges, fines are required for breach of obligations. So far, such an approach to solving this problem is the best of those available at the time of 2018.

    disadvantages


    In the decentralized exchanges, it is not yet possible to implement the so-called dark pools - a special orderbook in which no one sees orders. This approach is used in centralized exchanges to hide proposals for the exchange of large sums, since they can manipulate the market. To implement dark pools in a decentralized exchange, it is necessary to use sophisticated cryptography.

    In addition, transactions with fiat currencies will not be available on decentralized exchanges. Fiat currencies do not have an accounting system where they could register a smart contract. Therefore, it is not possible to make an atomic swap between fiat and digital currencies.

    Panic Sell problem


    With the massive use of atomic swap, there is a problem that is difficult to solve. Assume that there is an accounting system within which a very high transaction processing fee is charged, and the transactions themselves are confirmed for a very long time. Users start selling this currency because it has low bandwidth and create orders on a decentralized exchange, but these orders, when executed, create smart contracts in the same blockchain as the currency they are trying to sell. Thus, the network is loaded even more, the pending transactions form an even greater queue and users want to sell this currency even more, placing more orders and increasing the transaction queue.

    image

    As an analogy, we can give an example from nuclear physics. With the decay of one nucleus of the uranium isotope 235, it usually emits from 1 to 8 free neutrons. Each neutron formed during the decay can cause the decay of the neighboring uranium nucleus, this phenomenon is called the chain fission reaction of the nucleus. Actually, this is the principle of the atomic bomb explosion. Moreover, the problem of extinguishing nuclear explosions has not yet been resolved properly. Of course, the problem of Panic Sell in decentralized exchanges based on atomic swap is not so significant compared to the problem of atomic bombs, but this analogy very clearly reflects the essence of the avalanche-like spread of the panic process in the market.

    The risks of using atomic swap


    Due to the lack of a third party, there are risks with using atomic swap. If the user has not conducted an audit of the contract that his opponent sent him, there is a chance that the opponent may steal the money of the first user. In addition, if after the execution of the smart contract the first user took the money, and the opponent did not execute the redeem script in time, the opponent may lose his money.

    findings


    Assessing the work of the atomic swap, it can be concluded that the idea is promising for creating a technology for the exchange of digital assets on a trustless basis. It takes more time and practical experience before it becomes possible to unequivocally state exactly how the atomic swap idea should be implemented. However, today there are decentralized exchanges that use atomic swap: BarterDEX on the platform of Komodo, Altcoin, as well as the project 0x. The fact that there is a demand for such an exchange technology indicates the needs of a modern digital economy.

    Also popular now: