Monero Atomic Swaps Explained

0
388
Monero Atomic Swaps Explained

Monero Atomic Swaps Explained

Monero atomic swaps can't come too soon for most of us. We've all heard of cryptocurrency exchanges running off with people’s investments are not uncommon, and they can indeed be off-putting. Just recently, a South African crypto investment firm turned out to be a scam. Two sibling founders reportedly vanished with $3.6 billion worth of Bitcoins, totaling 69,000 coins, during the currency’s peak in April. This bitcoin heist is just the latest in a series of similar scams in which investors have lost a lot of money.

While the firm is not outrightly an exchange, it operated under the principle of trust, which governs both small and large exchanges. Traders trusted the company with securing their investments, similar to how trading on exchanges works. Here, sellers surrender their cryptocurrency coins to the exchange, trusting their funds will be safe. Of course, such platforms have instituted safety measures to protect their customers, but one cannot be too sure. This is why it is advisable for cryptocurrency traders to store their coins in their individual wallets.

But this creates a secondary problem: it simply translates to additional charges every time one intends to trade part of their portfolio, not to mention the time spent waiting for every transaction to be completed. So, what if there was a way to prevent all these issues? Well, there is an emerging solution: the concept of the atomic swap. This article will detail what atomic swaps are and then take a deep dive into Monero atomic swaps.

What is an Atomic Swap?

An atomic swap is a secure and safe mode of exchange that allows traders, who are essentially strangers, to exchange their cryptocurrencies without using a third-party service provider, more conventionally known as a cryptocurrency exchange. It can take place between two different blockchains (off-chain), i.e., away from the main blockchain, such as by exchanging private keys to a wallet, in lieu of simply transferring the coins.

To guarantee security, an atomic swap relies on a smart contract or, more technically, a Hashed Time Lock Contract (HTLC). The smart contract is a code that controls the execution of every transaction. It contains the terms of an agreement between the seller and buyer. This guarantees trust, thereby eliminating the need for an oversight authority or enforcement technology.

To put it into perspective, think of the smart contract arrangement as two virtual, ‘transparent’ safes. One containing trader A’s cryptocurrency, say, Bitcoin, and the other containing trader B’s cryptocurrency, Litecoin. It goes without saying that a safe should have a key or passcode, so, in the case of an HTLC, the key/passcode is a mathematical function known as a preimage, which is hashed (locked) to promote safety. The smart contract releases both cryptocurrencies only if the hashed preimage matches for both traders.

Bitcoin Litecoin Swap

Bitcoin Litecoin Swap

But how do all these aspects link together? Once a trader initiates a transaction, an atomic swap is opened. The trader then creates an HTLC address and deposits their cryptocurrency therein. After this step, the preimage (the key/passcode in our explanation above) is created and then locked through the use of a hash. These steps generate a virtual safe, which is sent to the second party.

Being ‘transparent,’ the second trader can verify the contents of the safe. Upon ascertaining that the amount is as desired, they’ll deposit their coins in a new HTLC address, creating a second virtual safe. However, the new address has the same lock-key combination (hashed preimage) as it is made using the same hash. Once the first party receives the safe from the second trader, they’ll unlock it using the hashed preimage, after which the second trader opens theirs.

Notably, HTLC is time-based. Thus, the smart contract must be completed within a given time frame, after which the cryptocurrencies are returned to the traders’ own wallets.

Origin of Atomic Swaps

Interestingly, atomic swaps are revolutionizing crypto trading by making the exchange of coins secure and eliminating third parties that may have malicious intentions even though they are relatively new. They emerged in 2017 when Decred Project completed the first cross-chain swap of its decentralized crypto, Decred, and Litecoin. Previously, cryptocurrency coins could only be traded through exchange platforms.

Although atomic swaps came into existence in 2017, the idea was much older. In a 2013 post on Bitcoin Talk, Tier Nolan wrote down the principles that would ultimately govern atomic swaps. His vision, which took several years to be effected, was to complete cryptocurrency trades across different blockchains.

What is Monero Atomic Swap?

Monero Cryptocurrency

Before discussing Monero atomic swap, let’s first explore Monero (XMR). Launched in 2014, XMR has made a name as the most private cryptocurrency, a status that is also attached to its increasing popularity. Its heightened privacy is occasioned by the fact that it is based on an opaque blockchain. It anonymizes every transaction detail, from the sender’s identity and the amount sent to the buyer’s information. This is because it uses stealth addresses that conceal the participants’ real addresses, as well as ring signatures.

The properties that give Monero a degree of privacy and anonymity in the cryptocurrency world make it sort of a bane for atomic swaps. XMR is unique when compared to Bitcoin-like cryptos, which can be swapped using the procedure described earlier because in addition to their focus on anonymity, the Monero blockchain does not have HTLCs.

Thus, while transacting Bitcoin-like cryptocurrencies using the atomic swap approach, for example, the transactions are time-locked. This means that if one party fails to complete their end of the deal, the transaction collapses, and the coins return to their rightful owner. However, the XMR is built on anonymity, thereby indicating that the rightful owner is not outrightly known. This creates a conundrum because if XMR coins were to be exchanged with Bitcoin using the principle of atomic swaps but the transaction fails to complete, the coins would be lost forever. This scenario prompted a rethink, which resulted in the Monero atomic swap.

Monero Atomic Swap

The Monero atomic swap is a revolutionary cross-chain exchange between the Bitcoin and Monero blockchains, which, as detailed, have different characteristics.

How Bitcoin-Monero Atomic Swap Works

Differences between BTC and XMR

To deal with the problem described above, Joël Gugger developed a protocol that relies on a cryptocurrency concept known as digital signatures. This was because both Monero and Bitcoin use digital signatures. However, while Bitcoin-like cryptocurrencies use the Elliptic Curve Digital Signature Algorithm (ECDSA) to create them, Monero uses the Concise Linkable Spontaneous Anonymous Group (CLSAG).

Usually, these algorithms generate the public key by multiplying a secret random number corresponding to the private key by a known base value on an elliptic curve. This arrangement enables a private key’s owner to share the matching public key in addition to offering a digital signature that proves ownership of the private key and, when data is involved, an agreement with the information.

This process can be performed repetitively, as many times as possible, except in special cases. One such notable case is used in Monero atomic swaps.

Monero Atomic Swap

Monero Atomic Swap

Simplified Bitcoin-Monero Atomic Swap

The Bitcoin-Monero atomic swap process is quite technical and is also still being refined. For this reason, we’ll simplify it. Firstly, though, the traders must install software or program that supports the swap. Now, say Trader A owns XMR and wishes to exchange them with Trader B, who owns BTC, for their BTC, the two parties would follow the following steps:

  1. Traders A and B both exchange information such as their respective public addresses, amounts to be traded, and procedures. Part of the procedure declarations include instituting deadlines: the normal time limit within which the atomic swap is to be completed and the deadline for reclaiming the amount if the transaction is not finalized.
  2. A and B create random keys and then share them with each other. These keys allow both parties to view the XMR coins to be sent.
  3. A and B each create a random but secret key that, when combined, generate the Monero private spend key.
  4. Limited information from trader B’s secret key is shared with A, creating a Monero address.
  5. A and B create and sign a Bitcoin refund script that can either send BTC back to B or allow A to claim the BTC but only after the reclaim deadline has passed. Naturally, signing creates a signature that can be published by one party if the other tries any form of mischief – thus, it acts as a safeguard. The script simplifies the claim/reclaim process as it performs these tasks without requiring the input of the other party. For instance, if the planned atomic swap fails, trader A uses their Monero private share key, revealed through combining a zero-knowledge proof and adaptor signature, to claim the BTC. (Also known as a scriptless script, an adaptor signature is a way of executing off-chain smart contracts using Schnorr’s digital signature.)
  6. B creates a swaplock script, funds it with the BTC amount they wish to swap, and subsequently publishes it to the Bitcoin blockchain. The script allows A to claim the Bitcoins (if a signature is provided using the blockchain’s 2-of-2 multi-sig). Alternatively, if the normal time limit stipulated in step 1 elapses, the script initiates the refund process, as described in step 5. Notably, the refund and swaplock scripts work collaboratively to ensure that neither A nor B can claim the Bitcoins before the swap is completed.
  7. Upon seeing the published swaplock script, A transfers the Monero, thereby ceding control of their XMR to the private spend key created in step 3. In so doing, A effectively publishes a Monero transaction.
  8. Given that the view keys created in step 2 enable both parties to see the published Monero transaction, B provides the signature (described in step 6) upon verifying the transaction, allowing A to claim the BTC. This claim is possible thanks to the workings of the 2-of-2 multi-sig.
  9. A claims and transfers the BTC to their private address, automatically revealing their Monero private share key.
  10. B uses the disclosed key to claim the XMR.

Benefits and Disadvantages of Monero Atomic Swaps

Benefits

While still under development, the benefits of Bitcoin-Monero atomic swaps can still be quantified:

  1. They will transform the Monero ecosystem by limiting restrictions placed on XMR and making this cryptocurrency as available as Bitcoin.
  2. Being transparent, Bitcoin’s blockchain exposes the movement of BTCs to everyone, even in cases where the sender wishes to remain anonymous. Fortunately, by using Monero atomic swaps, such users will enjoy the anonymity attached to the use of Monero.
  3. They will enable owners of other cryptocurrencies to reclaim their coins if the other party fails to honor their end of the deal.

Disadvantages

Indeed, Monero atomic swaps are bound to revolutionize cryptocurrency trading. That said, they have a few limitations, including:

  1. The BTC owner has to remain online from the time they fund the swap until the reclaim deadline elapses. This means that traders whose internet connection or power is unstable stand the risk of losing their BTC.
  2. It exposes XMR owners wishing to swap them for BTC to undue risk, especially when the BTC owners acquired their coins through illegal means. This, therefore, calls for additional due diligence by XMR owners.

Conclusion

Monero atomic swaps are bound to be revolutionary once the supporting infrastructure is deployed. They will definitely expand the XMR ecosystem, making it harder for various parties and regulatory bodies to impose restrictions. For now, though, it is still under development.