Introduction to Binance DEX: Part I, Atomic Swaps explained

Thomas
Dune Network
Published in
4 min readMar 26, 2020

By F.

In this series of articles, we summarize various relevant information about the Binance DEX decentralized cryptocurrency exchange, how it works, and the process of applying. In doing so, we hope to help the community with issuing and swapping tokens and make the process even smoother. This first article describes how atomic swaps work. The next will dwelve into more technical details of how atomic swaps are done on Binance DEX.

Blockchains are all about decentralization. Bitcoin was the first decentralized digital currency, i.e. controlled by no central entity: decision power was distributed proportionally to miners which meant, initially anyone with a laptop.

Besides the concentration of mining due to specialized hardware, cryptocurrency exchanges have been a major factor in the centralization of the ecosystem. Much like nowadays most email addresses are hosted at Google and Microsoft, it seems a large fraction of cryptocurrency users are giving up ownership of their coins to a few exchanges. This has made the numerous hacks of such websites extremely damaging, the most egregious example to this day remaining Mt Gox in 2014.

In the case of exchanging cryptocurrency against fiat currency, it is difficult to improve on the centralized model. However, swapping between two cryptocurrencies is elementary — as it should! — thanks to a cryptographic setup called the atomic swap.

Intro

Why the name? Atomic etymologically means “that which can not be divided in smaller parts”, and the concept comes from concurrent programming and database systems where it designates a series of operations of which either all occur, or none. In our case, suppose we wish to trade BTC for DUN: the operation will consist in two transactions, one transferring BTC, the other transferring DUN, but we never wish for one to occur without the other, in other terms we wish for the swap to be atomic.

Protocol

Suppose then Alice wants to send BTC to the White Rabbit, in exchange for DUN.

  1. Alice chooses a secret random number , and hashes it into , for example using for the well-known SHA-256 function.
  2. Alice creates on the Bitcoin blockchain a special transaction, called a hash time-locked (HTL) transfer, with the following properties:
  • If after two days no-one has claimed the transaction, it reverts all the money (in BTC) back to Alice.
  • this transaction can only be claimed by revealing , upon which it will transfer its amount to the White Rabbit: that is to say, it knows and will hash any input to check that before releasing any funds.

3. The White Rabbit, seeing this transaction, creates a quite similar
transaction on the Dune Network blockchain:

  • If after one day no-one has claimed the transaction, it reverts all the money (in DUN) to the White Rabbit.
  • this transaction can also only be claimed by producing (which is then hashed and compared to since the White Rabbit doesn’t know yet).

4. Now let’s examine what could happen from then on, and why this is
called an atomic transaction:

  • If Alice does not reveal , the White Rabbit’s transaction expires first — upon which it receives its money back. There is no point then for Alice to release and forfeit her bitcoins, and thus the swap operation is canceled.
  • if Alice reveals by releasing the White Rabbit’s transaction, then, because the Dune blockchain is public, the White Rabbit can see the value of and use it to release Alice’s transaction on the Bitcoin blockchain — which is still time-locked for at least 24 more hours, hence the White Rabbit has ample time.

Atomicity

As you may already have noticed, atomic swaps are not as “atomic” as one might expect knowing the usual definition. For example, if after the White Rabbit’s transaction expires, Alice releases by mistake, she forfeits her BTC without getting DUN in return.

Thus, as often with blockchain concepts, this “atomicity” property is conditional on agents being “rational” in the narrow economic sense, something along the lines of “if I possess information () which I can use to transfer money to myself, I will use it”. There are of course many cases in real life when this is not the case.

To make the transaction “more” atomic, one possibility is to give anyone the possibility of submitting to the smart contract locking the funds, in exchange for a reward. Creating this incentive makes it more likely that someone will act “rationally” and propagate .

One of the biggest cryptocurrency exchanges, Binance, has recently decided to launch a decentralized version of itself, Binance DEX, using atomic swaps as a building block.

Binance has its own blockchain, built on top of the Tendermint framework, and on which it maintains its own token BNB.

The Binance blockchain does not have smart contracts per se, but it provides hash time-locked transfers as a native feature. In the next article, we will first examine how things work once a token has been issued; then we will address the question of issuing your own tokens on Binance DEX. Stay duned!

Connect with us:

Discord: https://discord.gg/JBUGqFg
Telegram: https://t.me/dune_network
Medium: https://medium.com/dune-network
Twitter: https://twitter.com/dune_network
Reddit: https://www.reddit.com/r/dune_network/
Gitlab: https://gitlab.com/dune-network
Website: https://dune.network
Email: contact@dune.network

--

--