What are Cross-chain Swaps?


Cross-chain Swaps or Inter-Chain Exchanges, are a type of P2P exchange that allows us to safely transform our cryptocurrencies or others, without intermediaries of any kind.

cross-chain swaps or atomic cross-chain swaps, are a type of currency exchange that takes place between two different cryptocurrencies that run on their own blockchain. That is, it is a mechanism that allows users to exchange different cryptocurrencies directly between two pairs.

The easiest way to see these types of changes is the fiat currency exchange of a lifetime. In such exchanges, two people (one with euros and the other with dollars) want to exchange their currencies for each other at a certain rate. For this, in fiat simply knowing the rate and doing the accounts, each of the parties can give the other the amount of coins equivalent to the change. For example, € 100 would be equivalent to about $ 121.55, using an exchange rate of $ 1.2155 per euro. Suffice it to say that this change has been direct and without any intermediary.

However, in this example we are talking about tangible things, it is money that is in the real world. The question here is: How to make such an exchange possible using cryptocurrencies whose systems work on different platforms? Well, the answer to this is cross-chain swaps and you will learn much more about them below.

Beginnings of Cross-Chain Swaps

The first whitepaper that fully explains the nature of cross-chain swaps is “Atomic Cross-Chain Swaps,” by Maurice Herlihy, from the Department of Computer Science at Brown University Providence. This document, presented during the 2018 ACM Symposium, clearly explains how an atomic cross-chain swap works, its possibilities and main challenges in creating this type of tool.

Basically, what a cross-chain swap does is; take the money from the parties and deposit it under a special schedule that guarantees that the operation can only be completed with the approval of both parties. And if any party acts maliciously, it cannot take control of our funds.

Now, the programming part has surely caught your attention at this point. Well, first of all, remember that every cryptocurrency transaction occurs thanks to the fact that these currencies respond to a programming or smart contracts that allows you to send, take and deliver control of said currencies. In Bitcoin, for example, we call this programming possible thanks to Bitcoin Script, and in Ethereum, thanks to Solidity. In general, all cryptocurrencies use this management model for their operations. By the way, if you want to know how to start programming smart contracts for Ethereum, you can check our article How to start programming in Solidity?

Now, taking into account that cryptocurrencies are programmable currencies, we can make a special programming that allows us to exchange them cross-chain with total security. This is what makes this type of exchange possible, and we will talk more about this in the next section.

Programming currencies, the key to cross-chain swaps

Now, let’s go a bit to the practical side of cross-chain swaps and for this we will take, for example, Bitcoin. As we already mentioned, in Bitcoin we have the Bitcoin Script programming language. This scripting language allows us to send and receive coins in a fully programmed way. In fact, every transaction in Bitcoin is only possible using such programming.

But there is something very interesting with the capabilities of this language, more specifically with the OP_CHECKSEQUENCEVERIFY (CSV) and OP_CHECKLOCKTIMEVERIFY (CLTV) functions. The first is a very useful operation code or OP_CODE, since it allows us to block the execution of a certain script or transaction until certain conditions are met. Thanks to this, things like the Lightning Network are possible, as well as decentralized exchanges and secure P2P exchanges. These last two are precisely those that enter the field of cross-chain swap operations. The second code, for its part, allows us to place time locks on our transactions, something that we can use to create security mechanisms for our exchanges.

Thus, if we use a wallet capable of giving us the ability to perform cross-chain swap operations, we can make use of the OP_CHECKSEQUENCEVERIFY and OP_CHECKLOCKTIMEVERIFY functions, and perform cross-chain swap operations with people who have the same capacity. And all, because our wallet will program the coins so that they can only be exchanged under a series of conditions that both parties have decided in advance and without any intermediary.

Of course, this is a very simple explanation of how everything actually happens, so below we will explain how all this actually happens.

How does a cross-chain swap work?

Now let’s assume the following scenario. On the one hand, we have Laura who wants to exchange her Bitcoin (BTC) for Monero (XMR). And on the other hand, we have Juan who wants to exchange his Monero for Bitcoin. Both have a need for exchange, and both parties have the currency they need.

Given this, Laura and Juan begin the exchange process having their purses trained for it. First, Laura creates a transaction using the opcode OP_CHECKSEQUENCEVERIFY and blocks the amount of Bitcoin to be exchanged with Juan. Said script can only be unlocked once Juan complies with the exchange conditions, issuing his equivalent transaction in Monero, and knows the secret that protects Laura’s transaction. In case something goes wrong, Laura’s transaction has a security measure that would allow her to recover the money after a while, using OP_CHECKLOCKTIMEVERIFY for this.

On his side, Juan also issues a transaction in Monero using the corresponding programming. In this case, Monero does not support OP_CHECKSEQUENCEVERIFY, but instead uses an operation called DLTC or Discrete-log Timelock Contract, a system that allows conditional payments in this currency. This operation allows Juan to issue a payment in Monero, which will only be effective if Laura meets the conditions. Like Laura, Juan has included conditions that will allow him to recover the funds in case something goes very wrong.

At this point, both parties have issued the payments, but no one has the money. At this point, it is time to check the unlocking conditions, which will allow Laura and Juan to take the money from the exchange effectively. Thus, both Laura and Juan reveal the secrets that protect their transactions. It is when you both know these secrets, when you can use them to unlock the script that holds payments. In the event that any of the parties has acted maliciously, one of the parties may use security measures for their transactions.

These security measures are time locks, and their function is to ensure that funds are inaccessible to both parties for a certain and prudent period of time. Thus, if after a while, one of the parties does not comply with the conditions, the other can simply withdraw their money from the exchange and recover it, remaining as at the beginning.

Cross-chain swaps with other cryptocurrencies

The example we have given here we have done with Bitcoinand Monero. And, although it is a fictitious example, it is close to the reality of this system. In fact, the Monero team is currently working on a cross-chain protocol to allow Bitcoin users to convert their BTC to Monero using this approach.

Of course this is not only limited to cryptocurrencies such as Bitcoin or Monero, all cryptocurrencies have this possibility, as long as they meet these two requirements:

  • They must allow blocking at the script level.
  • They must allow blocking at the time level.

Both transaction execution locks are intended to add the security necessary for these exchanges to be secure. Thus, for example, Ethereum could implement this system to allow cross-chain with other cryptocurrencies, and the same with the rest of crypto. The only limitation in all this is the one that developers can interpose by not supporting certain functions or equivalents in the blockchain and cryptocurrency.

Other alternatives

Other alternatives to cross-chain swaps are Succint Atomic Swaps (SAS), whose operation would also allow cross-chain exchange of currencies. However, this system has barely been defined and at the moment there is no complete and revised theorized operating model.

Pros and cons of cross-chain swaps

First of all, among the pros of cross-chain swaps we can mention:

  • It allows a new decentralized, secure and private functionality to exchange our currencies for others without depending on centralized or decentralized exchanges.
  • It helps us to generate a much greater dynamics of currency use. The currency exchange, for example, would allow us to expand our use of currencies at any time, and without major complications. This way we could quickly change our BTC for EOS, in case a business or establishment only accepts EOS as a form of payment.

For its cons we can mention:

  • If we use wallets that have a poor implementation of this type of protocol, we risk losing our money. The security of this system lies in the programming of very clear and safe conditions that protect us at all times.
  • They can be somewhat complex to use, especially for those who are starting out in the world of cryptocurrencies.

Leave a Comment

Your email address will not be published.

You may also like