The Technology Behind Jelly

Jelly
Jelly-market
Published in
4 min readNov 13, 2019

Atomic Swaps simply explained

It is time to explain Atomic Swaps on a high level and to try to make it as simple as possible in order to give a value-packed article to all the readers interested in blockchain.

As we explained in the previous article, Atomic Swaps enable two or more parties to swap cryptocurrencies peer-to-peer without trusting a third-party arbiter. Atomic Swaps’ main goal is to eliminate the middleman, while at the same time they guarantee that unpleasant scenarios like the following one won’t happen:

Let’s say that Alice and Bob want to exchange BTC for ETH. Alice sends her BTC to Bob, and then she expects Bob to send his ETH to her in order to finalize the exchange. But Bob has the option of going back on his end of the bargain once he receives the BTC, ending up with both sets of coins. Alice has become a victim of fraud because she didn’t have any guarantee that Bob will fulfill his part of the bargain.

Here comes the atomic swap which eliminates the problem of trust by ensuring that no single party ever holds both cryptocurrencies at the same time, hence such frauds are impossible to happen. To avoid fraud, atomic swaps simply lock the two transactions (once they are submitted to the blockchain), so that they can be unlocked (and executed) only when certain requirements are met. If one of the two parties steps back on his end of the bargain, the funds will be returned to the sender. So, the atomic swap will either happen or it won’t depending on whether the requirements are fulfilled, but at the end none of the two parties will lose money.

This middle state, when the transactions are locked, will prove to Alice whether Bob will send the ETH or not. The mechanism is called Hashed Time Locked Contracts (HTLCs) and it protects all participants from potential losses.

How does it work?

The Hashed Time Locked Contracts lock the transaction twice, making it extremely secure. We end up with Time Locked and Hash Locked transaction at the same time.

Time Locked Transactions

Тhe receiver has a limited amount of time to confirm on the blockchain that he has received the funds. It guarantees that the blockchain will reverse the transaction if the receiver never confirms it and the assets will be sent back to the sender.

Hash Locked Transaction

А special secret key (different from the private key) is created by the sender. Then a hash is derived from the secret key. The hash will make sure that no one can guess the secret. While the key remains secret, the hash is public, but it is a one-way process — there is no way to go back from the hash and reveal the secret key. Тhe secret key is the only piece of information that can unlock the transaction. Hence the receiver needs to get the secret key in order to get the funds. This is how it happens:

Algorithm in example:

1. Alice has BTC, Bob has ETH

2. Alice creates a secret key consisting of random letters, words or numbers.

3. A hash is created from Alice’s secret key

4. Alice submits a transaction on the Bitcoin blockchain which is sent to Bob’s address. It is locked in both terms of time (where Bob has a certain amount of time to confirm it) and in terms of security (with the hash).

5. Alice sends the hash to Bob

6. Now it is time for Bob to create his Ethereum transaction to Alice (again it is both time and hash locked, where the hash is the same as Alice’s). As a result, we have two transactions on both the Ethereum and the Bitcoin blockchains which are locked with the same hash.

7. Alice unlocks Bob’s Ethereum transaction (because she holds the secret key). By unlocking his transaction, Alice automatically reveals the secret key and it is publicly recorded on the blockchain.

8. Bob can now see the secret key and unlock the Bitcoin transaction which was aimed at him.

9. They have exchanged assets without the need to trust or know each other.

This is how Atomic Swaps work in a very simple overview. They play a crucial role in the journey towards full decentralization and will definitely improve the process of value exchange.

--

--

Jelly
Jelly-market

Peer-to-Peer trades across different blockchains