Atomic Swaps allow you to exchange currencies between different networks without needing an intermediary. This provides more autonomy and security to users. Do you want to understand everything about atomic swaps?
With more and more solutions being created on top of Bitcoin, the question naturally arose: how to transact between layers? Thus, although some exchanges and wallets already offer swap services, these are often centralized or do not support certain protocols, such as the Lightning and Liquid networks.
Therefore, for this, there are atomic swaps, which offer more convenience for users and more security, as they do not involve third parties, as occurs in an exchange.
In this article, we will explain to you what atomic swap technology is and how it works.
Let's go there?!
How did Atomic Swap come about?
Atomic Swap is an English term that means “atomic exchange”. This idea arose in 2012, when a Bitcointalk forum user named Sérgio Demian Lerner suggested the creation of a project called P2P TradeX, which would be atomic trading between chains.
So, this was the first idea involving Atomic Swaps.
Months later, in May 2013, Demian's proposal was refined and formalized by Tier Nolan, in which his approach allowed the direct exchange of currencies on Blockchains derived from Bitcoin.
Nolan technically described how an atomic swap would work. However, the implementation of this system took time to happen. Therefore, it was only in 2017 that the first atomic exchange between Bitcoin and Litecoin took place, using the Lightning network.
What is an Atomic Swap?
An Atomic Swap is a protocol that allows the direct exchange of Bitcoin between different blockchains without the need for intermediaries.
Therefore, an Atomic Swap is a P2P atomic exchange between different chains, which does not require an intermediary. This means that, for example, if a person wants to exchange Bitcoin from the On-Chain network to Lightning, they can do so directly through an Atomic Swap.
This method allows you to exchange currencies without having to trust a broker, as P2P platforms are used in the process. Furthermore, it is possible to exchange currencies that are part of the same network or that are from different networks.
Thus, exchanges made between different Blockchains and which have different native currencies are called On-Chain atomic exchange. Exchanges carried out between networks that are branches of the main network (such as the lightning network and the Liquid network) are called off-chain atomic exchanges.
How is an atomic swap performed?
An atomic exchange is made through a process called HTLC. This process is possible thanks to two openings in the Bitcoin protocol, which are OP_CHECKTEMPLATEVERIFY (CLTV) and pay-to-script-hash (P2SH) transactions.
The CLTV command allows the output of a transaction to become unusable until some time in the future. In other words, the payment is blocked for a specific period, preventing the recipient from using it.
P2SH transactions send funds to an address that requires permission, usually a specific code, to be spent. This permission can be the signature of several keys (multisig) or a code, which works as a password.
This “lock” that requires permission is called Hashlock.
What is Hashlock?
Hashlock is a blockchain security mechanism that only releases a transaction when a pre-determined hash value is provided, ensuring that the parties involved fulfill their obligations simultaneously.
Therefore, the hashlock restricts the expenditure of a transaction, until a code is publicly revealed.
In short, what happens when you combine these two processes is that CLTV blocks the transaction for a certain period of time until the hashlock is revealed to unlock that transaction and it can finally be spent.
Therefore, the two together (CLTV and P2SH) create the resource through which atomic swaps work, which is the HTLC (hash time lock contract), that is, a hash time lock contract.
Basically, when performing an Atomic Swap, this contract is used, allowing funds transacted between users to have protection (time and password) to be finally used.
If the contract rules are not accepted and the time to redeem the transaction runs out, then the funds are not released and returned to the senders.
How does Atomic Swap work in practice?
In practice, an atomic swap works as follows:
Let's say you want to exchange Lightning Network satoshis for on-chain bitcoins with Carol. In this case, you will send the satoshis and Carol will send the bitcoins. This will be an off-chain coin exchange.
What automatically happens in the process is that when you both send funds to each other, there is a code in that transaction that needs to be revealed between the parties.
This code is what unlocks the funds so they can be redeemed. Therefore, the moment you reveal the code, you can redeem your funds, and Carol can also redeem hers by revealing the code.
If you, when revealing the code, do not redeem your funds, they will remain waiting for redemption until the deadline determined by the contract. If this period expires and you have not yet redeemed your funds, Carol will not be able to redeem hers either.
In this process, the funds are “trapped” and, when the time stipulated by the contract expires, they return to the senders, that is, to the originating address.
All of this occurs automatically through P2P platforms that offer the atomic swap service.
The process works this way because there is no third party intermediating; Thus, HTLC is a kind of smart contract that determines how everything will happen and serves as a way to protect the users involved.
Transaction between Bitcoin layers
Atomic Swaps are interesting for exchanging between Bitcoin layers, as not all wallets support the different layers.
Generally, this tool is used by users who want to send satoshis from the Lightning and Liquid networks to the on-chain network and vice versa.
But why transact between layers?
We know that Bitcoin has scaled in layers because the main network cannot carry out very fast transactions and sometimes the fees can become very expensive.
This happens because the on-chain network is not as efficient for micropayments, since the focus of this layer is decentralization and security. On-chain transactions occur, on average, every ten minutes; blocks have a size limit and this, on a day-to-day basis, ends up not being viable for small payments.
Therefore, the need to scale in layers arose, to allow more flexibility to users. It was from this that the Lightning Network and Liquid were created.
Thus, users who hold bitcoin, satoshis and L-BTC on these networks sometimes have the need to exchange these currencies between these layers, but not all wallets offer support for this in a simple way.
The commonly found solution is to use a centralized exchange to exchange between networks, but this involves a third party opening an account and entering data. Therefore, the need for atomic exchanges arose, which are carried out through P2P platforms, where no registration or KYC is required.
What is the advantage of performing an atomic swap?
Although atomic swaps have the advantages of decentralization and security, there are of course pros and cons
Let’s understand each of its advantages and disadvantages!
Pros
-
Transparency: because it does not happen in a centralized exchange, the processes are more transparent.
-
Higher level of security: there are several levels of security, after all a contract is made and in this contract there are terms that make the transaction secure between the two parties.
-
Interoperability: exchanges can be made between layers of the same currency, such as the Lightning, Liquid and On-Chain networks, but depending on they can also be made between other currency networks.
Cons
-
Although the process is interoperable, swaps between different layers only work on coins that have the HTLC feature. This somewhat limits the use of atomic swap.
-
Furthermore, the process is still under development. Despite being a feature that is already being used, it can still be improved a lot, so it may present some flaws.
Platforms available to perform atomic swaps
There are several platforms available that allow atomic swaps to be carried out, facilitating the direct and decentralized exchange of Bitcoin between different layers without the need for centralized intermediaries.
However, the best-known platform for atomic swapping with Bitcoin is Boltz.
Boltz is a P2P platform that offers atomic swaps, allowing exchanges between different Bitcoin layers such as Lightning and Liquid, and also to on-chain addresses.
Additionally, it is a non-custodial platform, which means users maintain full control over their funds during transactions.
The platform uses what is called “Submarine Swaps” to facilitate exchanges, allowing Lightning network users to acquire input capacity more easily and without depending on third parties.
If you want to know more about this platform, check out our article: what is Boltz?
Conclusion
The Atomic Swaps feature is still in its early stages, but it has great potential for growth among users, mainly because usage between Bitcoin layers is increasing, as is the need to exchange currencies between these layers.
I hope this article helped you better understand what Atomic Swap is and how it can be useful.
Take the opportunity to share this text with a friend who may also be interested in the subject.
Until next time and opt out!