12.08.2020

An Atomic Swaps Guide That Will Have You in Ecstasy (Plus Some Hash)

We all read about automation in the news. Here and there a story emerges about some robot-made pizza vans circulating streets, or e-shop delivery boys becoming R2D2s. Well, it may take time while machines fully replace human per se but when it comes to web sites and programs, there are solutions on the surface already that can make thing like Wall Street and brokerage obsolete.

Explaining AS in two paragraphs

To sum it up, atomic swaps (the name invented by crypto trading founding fathers) are a step to decentralized crypto exchanges (DEXes). DEXes, in turn, are crypto trading systems with no central counterparty, i.e. when the net of blockchain itself does the trades. This may sound relatively fantastic but this technology can eliminate professional intermediaries. In essence, atomic swap is a process of direct exchange (or conversion/replacement) of one token or coin, or tokenized asset for another, safe and secure, and fully automated.

Atomic swaps-explained

The idea is based on two features of blockchain: smart contracts which include many functions including escrow and hashing. Smart contracts, as you remember, are automated programs that are executed once required conditions are met. Hashing shows “coded projection” on the initial sequence (like, password, or key) without disclosing the sequence inself.

So, the buyer locks a given amount of his or her token, and locks it in a smart contract, hashing the locking key. The seller uses hash to lock his side of the deal. To unlock the asset sold, the buyer must enter the initial key, thus letting the seller know it. Voila, both sides of the deal are free!

You may think that atomic swaps resemble a Google or iOS App but those are not some platform or paid program. This is a blockchain-run technology. The real beauty is, this exchange/trade between involved parties can happen in a trustless manner without depending on any third centralized party or an escrow manager plus there is no default risk on either side.

Now let’s look into that deeper

Atomic swap technology, otherwise called atomic cross-trading, has the potential of completely revolutionizing the money transfer system in the crypto world. Atomic swaps will enable people to directly send value, exchange assets or trade with one another from one’s wallet to any other wallet.

atomicswap

The need for that emerged from fears and risks that some of the earliest crypto exchanges possessed. Hacks of centralized depositories could lead to users losing their funds. Those thefts took place due to multiple reasons: in some cases technology wasn’t that well developed as necessary, in some tech teams of those exchanges were weaker than hackers, and several occasions indicated nonchalance of the management. And the concept of a trustless, peer-to-peer cryptocurrency became a popular topic. In July 2012, the first draft of a trustless exchange protocol (meaning no trust was required) was created.

Arguments for developing those protocols were mainly in a lack of trust to centralized or people run exchanges. Before atomic swaps creation and development began, people already had an option of deposing their funds on a crypto exchange and solving all their needs for converting tokens via trading there. However, multiple hacks of trustless exchanges with compromised security led the community to think of a plan B which resulted in the atomic swap as a substitute for cryptocurrency exchange principle.

List of problems that created a need for atomic swaps:

  • hack vulnerability;
  • mismanagement risks;
  • specifically, scam/theft;
  • limited volumes;
  • government regulation sensitive.

Same applies to non-escrow peer to peer channels. However, while engaging in an atomic swap, the trade will either happen and both parties will receive their respective coins or the trade will not be successful. In other words, there is no middle ground involved in executing the atomically swapped trade.

Atomic swaps as a piece of technology

Again, atomic swap definition is a peer-to-peer switch of cryptocurrencies from one party to another, without going through a third party service like a crypto exchange. During this entire process, the users regardless of their qualification and technological advancement have full control and ownership of their private keys at any given moment. This means even if your counterparty has some hostile intentions, none can be implemented and you may remain calm. The first known “trade” like this took place on September 20, 2017 when Decred and Litecoin did the first successful implementation of the transaction.

Atomic swaps as a piece of technology

They can either be directly executed between separate blockchains with different native coins, or, they can also be executed via off-chain channels that are offshoots of the main blockchain.

In order to execute this, something known as Hashed Timelock Contracts (HTLCs) are used. The abbreviation may look scary but this is just a term to explain something one can understand natively.

It is a class of payments that use hashlocks and timelocks to require that the receiver of a payment either acknowledge receiving the payment prior to a deadline by generating cryptographic proof of payment or forfeit the ability to claim the payment, returning it to the payer. Effectively, they are a special form of payment channels.

Payment channels are basically off-chain state channels which deal with payments, i.e. a two-way communication channel between participants which enable them to conduct interactions, which would normally occur on the system, off the net. Using them decreases transaction time exponentially since you are no longer dependent on a third party like a miner to valid your transaction. More on that can be found out in lightning network manuals.

Solutions of that type work as follows: a segment of the blockchain state is locked via multi-signature or some sort of smart contract, which is agreed upon by a set of participants. The participants interact with each other by signing transactions among each other without submitting anything to the miners. The entire transaction set is then added to the blockchain.

A beginner’s guide to cryptographic hash function

For some reason, all trade relations in crypto are explained with Alice being owner of some Bitcoin and Bob willing to sell some LTC, atomic swap protocol not being an exception. In fact, this is kind of confusing as creates a bias that only similar blockchain (e.g. forks) can operate atomic swaps. This is not true. A team of cryptocurrency startup developers has open-sourced technology that enables trustless trading between the Bitcoin and Ethereum blockchains in 2017.

So, for every pair of people this works in a similar way: John owns Litecoin and Mary has some Bitcoin Cash (or Ethereum Classic, for example). They want to swap the coins with each other. The two of them then open up a payment channel. The contract address is like a multi-lock safe on the blockchain network that takes care of both of their funds.

Cryptographic hash function

After creating the address, John deposits his LTC. Mary does the same. Instead of exchanging a secret code, they use a cryptographic function. General procedure is the same for on-chain atomic swaps which take place online and off-chain aka not immediate atomic exchanges.

John aka the buyer creates a password. Instead of sending it, he shares a cryptographic hash of the password with Mary. She uses the hash as a base to cypher her part of the deal. Then, in simple terms, John enters the password, it gets hashed, and both safe boxes open simultaneously, the first one with the password, and the other one with the hash.

On-chain and off-chain swaps don’t differ much. For an on-chain atomic swap, both currencies must support HTLC and have the same hashing algorithm. Off-chain swap, on the other hand, allows you to do atomic swaps off the blockchain. These limitations are huge barriers to mainstream adoption but you need not worry because the cryptosphere industry is well aware of all these limitations.

Atomic cross-chain swaps are distributed coordination tasks where multiple parties exchange assets across multiple blockchains, for example, trading Bitcoin for Ether. However, the general atomic swap instruction remains as we described it earlier. 

So, not to draw a parallel but yes, the mysterious world of digital assets has already created something the may be a glimpse of sci-fi book where you don’t go to some random trader or broker sitting at the desk but rather see some AI tool matching a pair for your, and then just helping to arrange a P2P deal that you in fact do on your own.

Share

One Comment

  1. The Respirator Shop Reply

    Exceptional read, Positive site, where diyou
    u come up with all the info on this posting? I have read some of the articles on your site now,
    and I love your style.
    King regards,
    Thomassen Dencker

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.