What are atomic swaps and how are they used?
Atomic swaps are a mechanism for enabling true P2P trading of crypto-assets directly via blockchain. How do atomic swaps work and what is the future of this technology?
Atomic swaps are automatic contracts for exchanging crypto-assets between blockchains. The mechanism of smart contracts completely eliminates the need for centralized third parties (exchanges or exchanges) in transactions and frees the counterparty from risk. It is one of the few truly decentralized methods of conducting crypto-asset exchanges.
Atomic swaps are automatic contracts for exchanging crypto-assets between blockchains. The mechanism of smart contracts completely eliminates the need for centralized third parties (exchanges or exchanges) in transactions and frees the counterparty from risk. It is one of the few truly decentralized methods of conducting crypto-asset exchanges.
How atomic swaps work
"Atomic" (indivisible) is the term for processes that are either executed entirely or not at all. In other words, an atomic swap has features that guarantee that both parties to the transaction meet all predetermined conditions to complete the swap. The fulfillment of the conditions is guaranteed by smart contracts. If either party fails or has technical problems, the entire transaction is completely cancelled.
Atomic swaps use hash locking and time locked smart contracts (HTLC). These contracts use a mechanism to create and compare data fingerprints, the hash function. In addition, the contract imposes a time limit - transactions are cancelled if at least one party fails to meet the terms of the transaction within a predetermined period.
For example, two parties may agree to set a two-hour time limit for an atomic swap. In this scenario, the contract would return the deposited coins to their original owners when two hours have passed and not all of the terms of the transaction have been met. The HTLC smart contract requires two cryptographic keys:
- A hash lock key (Hashlock key). This key ensures that the transaction will only be completed when both parties provide cryptographic evidence that they have met the terms of the transaction.
- Timelock key. This is a security mechanism that helps participants in a transaction set a deadline for committing an atomic swap. It ensures that the coins deposited will be returned to the participants if the swap is not completed, for whatever reason, by the deadline.
What are atomic swaps and how are they used?
How atomic swaps are executed
Suppose User A and User B agree to make an atomic swap for BTC and ETH. User B wants to swap his 1 BTC for User A's 15 ETH.
User B first needs to create a contract address to which he will send the 1 BTC. After he makes the transaction, the contract automatically generates a special key that only User B has access to. This key unlocks the money the user sent to the smart contract.
The contract uses this key to create a hashed representation or encrypted form of the key. User B then sends the hash of the key to User A. Thus, User A only has access to the hashed form of the access code used to block User B's 1 BTC. This hash serves as confirmation that User B has blocked the money in the contract, but User A cannot yet access it or withdraw it from the contract.
After receiving the hashed key, User A uses it to create his own contract address, to which he deposits his 15 ETH. After both parties have locked their money into the smart contract, User B can request to receive the 15 ETH because he has access to the password that reveals the key User A used to lock the coins into the smart contract.
In the process of unlocking User A's contract address, User B reveals his password to the other party to the transaction. User A uses it to retrieve 1 BTC and complete the transaction. Essentially, the entire atomic swap process comes down to the ability of both parties to provide cryptographic evidence of their actions.
User B had to first encrypt the key and then send it to User A. Since he had the original key, he can claim the crypto-assets that User A blocked in the smart contract with the encrypted key. However, as a condition of unlocking the crypto-assets, User B must provide User A with the original key. User A can then access the key and use it to get 1 BTC.
Why atomic swaps are needed
Atomic swaps are an important blockchain interaction mechanism because they eliminate the need for intermediaries, such as cryptocurrency exchanges, in crypto-asset transactions, allowing traders to make cross-network transactions without relying on the infrastructure of centralized trading platforms.
Because intermediaries are not involved in atomic swaps, transactions are fast, more accessible, and eliminate security incidents associated with custodial-based exchanges. Users retain control over their crypto-assets as all transactions are executed from their personal wallets.
In addition, cross-network trading via atomic swaps contributes to an interoperable cryptocurrency ecosystem. Atomic swaps make it easier to conduct transactions across multiple blockchains. In addition, atomic swaps eliminate counterparty risk - the transaction is either fully executed or not executed at all.
The development of atomic swaps
The atomic swap mechanism was first described by developer Sergio Lerner in 2012. The idea interested the community, but some swap processes were not specified. A year later, Tier Nolan developed a more robust procedure for atomic swaps. But it wasn't until four years later, when the Decred team made an atomic swap between Decred and Litecoin, that the mechanism was first successfully tested on a real blockchain. A few days later, Litecoin founder Charlie Lee tweeted that the process had been successfully replicated for the LTC and BTC swap.
The original design of the atomic swap required both sides of the transaction to load the full version of the cryptocurrency blockchain they planned to exchange onto their device. A month after Decred and Litecoin conducted their first atomic swaps, the developers of the Komodo project introduced a "lighter version" of atomic swaps, requiring only the opening of dedicated payment channels. In this case, transaction participants do not need to upload crypto-asset blockchains or wait for validators to confirm transactions.
In 2017, Zcash developers demonstrated a working version of the XCAT (cross-chain atomic trades between blockchains) tool, which can be used to swap BTC to ZEC and back. A few months later, the first atomic swap between Bitcoin Cash and Decred was conducted.
In 2019, the Qtum platform ran atomic swaps on the main Bitcoin network, and Blockstream launched atomic swaps on the Liquid sidechain. There have also been attempts to create trading platforms that support atomic swaps. In 2019, the decentralized bitcoin exchange Sparkswap was launched with support for Lightning and atomic swaps. However, a year later, the site closed due to the low number of users and low liquidity.
Perhaps the development of the DeFi industry, the community's general course towards decentralization, and the support of atomic swaps by major blockchains will give the technology a boost in the coming years. However, as of 2021, atomic swaps remain a convenient and secure, but rare, form of transaction that eliminates the need for counterparties and allows users to retain control over their cryptoassets.
Report
My comments