Atomic Swaps — Taking out the Middleman (Part 1)

Atomic Swaps — Taking out the Middleman (Part 1)

Why go around when you can go through?

You’ve probably heard of the Suez Canal. Before the artificial waterway’s creation, European ships bringing textiles and spices from India had to navigate the infamous Cape Route — a 40-something day trip covering some 10,000-plus nautical miles. The canal’s opening provided a shortcut that trimmed more than 5000 miles and 10–12 days off the journey and ushered in a new era of maritime shipping. Less time at sea, less deaths from scurvy, less pirates, malnutrition, and hull-mangling storms. Progress.

And so here we find ourselves in 2021. Total crypto market capitalization has exceeded $2 trillion. PayPal is launching a crypto checkout service. Lindsay Lohan is shilling Tron and Elon Musk is taking Dogecoin “literally” to the moon. Our ascendancy is complete. Crypto is mainstream. But, even today, getting your hands on certain crypto assets can be a bit of an epic journey. Take buying Zano, for instance.

Let’s assume you’ve recently learned about the blacklisting of crypto addresses assumed or proven to be involved in criminal activity. It concerns you that such a thing is even possible and you worry it’s something that could be abused and prevent these traceable cryptocurrencies from functioning like “real” money (i.e. with Fungibility) in the future. Further research leads you to Zano and its future leading-edge privacy protocol, and you decide you want to invest. Well, first you need to buy/swap a coin to BTC or USDC. Then you need to sign up to one of the centralized exchanges (CEXs) Zano is traded on. You might have to go through a KYC validation process. Then you’ll need to send your coins to the exchange and wait however long it takes for the deposit to be confirmed. And all that just to get to the point where you’re ready to buy the Zano itself.

Not only is it a fairly lengthy process, it’s one that involves an uncomfortable amount of trust, requiring you to hand over identity documents, contact information and crypto-assets to a (potentially anonymous) third party. And just as the cargo of those ships navigating the Cape Route made them juicy targets for marauding pirates, so too do the concentrations of coins on exchanges make them irresistible to hackers and social engineers.

Aside from that, there’s the fees: one for each trade you execute, then another to withdraw your assets (usually significantly more than the transaction fee itself). So using a CEX can be slow, costly and compromising. It works, but it’s not ideal, and in this new, decentralized age, it feels like a pretty old-fashioned way of doing things. It’d be nice to have a shortcut — a faster, more secure mode of exchange.

All of the above, and the increasingly uneasy relationship between exchanges, privacy projects and regulators, are forcing said projects to look for new ways to provide liquidity. From the Ethereum ecosystem came DeFi — a wide range of mechanisms and algorithms that, among other things, expand the possibilities for providing liquidity. Cryptocurrencies that have their own native blockchain can solve this problem in at least two ways: wrapped coins and atomic swaps. We in the Zano project are working in both directions, and in this article we‘ll talk about our implementation of atomic swaps, which has already been launched in testnet. We are also officially announcing a new build, which in 1 month will bring hard fork #3 to the Zano network (main net), and enable atomic swaps.

The idea of Atomic Swaps

We will define atomic swaps as an operation in which two cryptocurrencies, each with its own native blockchain, have the technical ability to create secure exchange operations between network users, while not using trusted third parties and not having to trust one another. For example, Zano and Bitcoin have atomic swaps support, so users can safely exchange Zano for BTC without middlemen, inconvenience and third party risk. The operation is called “atomic”, because it can’t stop half-way through the process. It either happens completely, with both parties receiving the agreed upon number of coins, or it does not happen at all.

HTLC

The atomic swap mechanism is based on the so-called HTLC (Hash-Time Locked Contract). This contract can be roughly translated into human language as follows:

If within timeframe T a secret code is received, then transfer N amount of coins to recipient’s address A.

If time T passes without receiving the secret code, then transfer the money back to sender’s address B (refund).

Cross-chain Atomic Swaps

Let’s describe the process of a cross-chain atomic swap between two parties in detail. Alice has ZANO, and Bob has BTC. They agree to exchange a particular amount of BTC for a particular amount of ZANO. Both parties have wallets in both the Bitcoin network and the Zano network.

It starts with Alice generating a random secret. This secret will be the cornerstone of the whole process, so it is important to understand that only Alice knows it. She then calculates a hash (a long string of numbers and letters) of the secret, which is used to lock the Zano which are addressed to Bob. Bob won’t be able to get the coins without knowing Alice’s secret code. It’s like a zip file you can’t open without a password.

Phase 1

Once Bob sees that Alice has created an HTLC in the Zano network — with the agreed upon number of coins and lock-time — he creates his own Bitcoin HTLC transaction for Alice inside the Bitcoin network and, importantly, locks the transaction with the same hash code Alice used (the one derived from her secret).

Phase 2

Alice makes sure that Bob’s HTLC to her has the number of BTC they agreed upon and executes a “redeem” transaction to “unlock” the BTC in the HTLC. This is essentially the “atomic” moment of the whole process: before it, the deal can be canceled with everyone keeping their coins, but after it the deal will be “irreversible” in the technical sense.

Unlike Bob, Alice knows the secret that is needed to unlock and redeem the BTC, which she does.

Phase 3

By broadcasting this redeem transaction, Alice reveals her secret (as it is explicitly included in the transaction as proof that she knows it). The moment Bob notices this transaction, he extracts the secret and uses it to redeem his Zano.

Phase 4

Now the swap is complete and Alice and Bob are left with the agreed upon amounts of BTC and ZANO respectively. At no point in the process is it possible for one party to go through with their side of the contract while the other does not — the “Atomic” nature of the swap precludes it. If either of the parties changes their minds before Alice broadcasts the redeem transaction, they can simply wait until the contract expires (and the coins automatically returned). It is important to keep in mind that the timelock on Bob’s side, who does not know the secret, must be set to expire before Alice’s timelock. If not, then Alice might redeem her coins after her Zano HTLC to Bob has expired, leaving Bob with no coins.

Conclusion

Although we’ve used Bitcoin in the above examples, Atomic Swaps can be done between Zano and any other coin that uses the SHA-256 hashing algorithm in Hash Time Lock Contracts (HTLC). They provide a more secure and direct route between the ecosystems of Zano, Bitcoin, Bitcoin Cash, Decred, Litecoin, Qtum and others. And the list of compatible assets will only grow.

At the moment these are low-level tools, but they lay the foundations for far greater future interoperability. We’re already seeing platforms being built around Atomic Swap functionality (like AtomicDex) that provide a more accessible and user-friendly experience. Soon these will provide true decentralized alternatives to increasingly regulation-bound centralized exchanges and their limited trading pairs. As the tools are further refined, we can envision a future in which you are free to make fast, low-fee, frictionless and trustless trades between a constellation of hyperconnected crypto assets, each with its own specialized strengths and use cases. And for those who want to transact privately, there will be Zano.

Atomic Swaps means easier access. Easier access means greater liquidity, and liquidity, like fungibility, is something that every good currency should have.

Atomic Swaps. Liquidity. Progress.

Read about the more technical details of Zano’s Atomic Swaps in Part 2 of the article.

New Release and Network Hard Fork (#3)

With this article we are announcing a new release, which will deploy a hard fork to activate Atomic Swaps at block 1082577 (estimated date June 1st). We kindly ask everyone to update your Zano client to the latest version, to avoid future network issues. All non-upgraded clients will be unable to work with the network after the hard fork occurs.