<img src="https://d5nxst8fruw4z.cloudfront.net/atrk.gif?account=qmvEl1aAFUE06C" style="display:none" height="1" width="1" alt="" />
BTC $18955.00

Atomic Swaps: How the Lightning Network Extends to Altcoins

It is well-known that Bitcoin’s upcoming lightning network promises instant confirmations and low fees. What is not as well-known is that this highly anticipated scaling layer is actually not limited to Bitcoin. The very same peer-to-peer protocol can potentially be extended to, and made interoperable with, many altcoins. This could allow for trustless altcoin payment processors, decentralized altcoin exchanges and perhaps even cheaper bitcoin-to-bitcoin payments and more.

Atomic Swaps

Interoperability between Bitcoin and altcoins is not new. So-called atomic swaps (or atomic cross-chain trading) were first described by Tier Nolan back in 2013.

Let’s say Alice has 200 litecoins, but prefers 1 bitcoin. And Bob has 1 bitcoin, but prefers 200 litecoins. So Alice and Bob agree to trade. But neither Alice nor Bob trust each other, so neither wants to be the first to send over the coins. The other may not return the favor.

That’s why Alice and Bob set up an atomic swap.

Atomic swaps utilize a clever trick known as a hash time-locked contract, which in turn leverages the potential of multisignature addresses and time-locks. All this is enabled by the basic scripting language found in Bitcoin and most altcoins, including Litecoin.

In short, Alice and Bob submit transactions to both blockchains: one on Bitcoin and one on Litecoin. The Bitcoin transaction sends 1 bitcoin from Bob to Alice, but Alice can only claim this bitcoin if she reveals a secret number only she knows. The Litecoin transaction sends 200 litecoins from Alice to Bob, but requires the same secret number on both chains.

When Alice claims her bitcoin, she reveals her secret number on the Bitcoin blockchain. And with that same secret number, Bob can, in turn, claim his 200 litecoins.

Even though the transactions are on completely different blockchains, they are effectively linked. Bob just needs to monitor the Bitcoin blockchain to see if Alice claimed her bitcoin so that he can claim his litecoins.

All this works today. But it is a bit of a hassle. Alice and Bob need to find each other to set up the atomic swap, which then requires several transactions on multiple blockchains.

This can be improved.

(Note: there are some extra steps to ensure that Alice actually does claim her bitcoin within a limited amount of time so that Bob can also claim his litecoins in a timely manner. The specifics are beyond the scope of this article; however, for details on how hash time-locked contracts work, see Understanding the Lightning Network, Part 2: Creating the Network.)

Lightning Network(s)

The lightning network is specifically designed for Bitcoin. But altcoins that are forked from Bitcoin’s codebase — like Litecoin, Dogecoin or Zcash — are typically capable of hosting lightning networks as well. Other altcoins, as long as they include similar or more extensive scripting capabilities (like Ethereum or Ethereum Classic), enable similar solutions.

Like atomic swaps, the lightning network utilizes hash time-locked contracts. Where atomic swaps effectively link blockchains, the lightning network links payment channels. This way, if both Alice and Bob have a payment channel open with Carol, they can transact through Carol, without needing to trust Carol.

And exactly because the underlying mechanics are the same, it’s no stretch to merge the lightning network with atomic swaps. This process makes different lightning networks interoperable across blockchains.

This means that a peer that opens channels on both blockchains could serve as a payment processor, an altcoin exchange and more.

Let’s say, for example, that Alice wants to buy a computer from Bob, for which Bob charges 1 bitcoin, but Alice only owns litecoins. Luckily, Carol has a Litecoin channel open with Alice, and a Bitcoin channel open with Bob. So Alice can now send 200 litecoins to Carol, for Carol to send 1 bitcoin to Bob. Since this is all linked with hash time-locked contracts, Carol effectively acts as a trustless payment processor.

And if Alice and Bob both have a Bitcoin payment channel as well as a Litecoin channel with Carol, they can also swap funds. Alice can send 200 litecoins to Carol, which Carol forwards to Bob. Bob then sends 1 bitcoin to Carol in exchange, which Carol now forwards to Alice. And again, all this is still linked with hash time-locked contracts, so now Carol effectively acts as a trustless altcoin exchange.

Lastly, alternative lightning networks may even improve Bitcoin’s lightning network in some ways. For example, a bitcoin-to-bitcoin payment could be routed through Litecoin peers, if that happens to be the cheapest route. Or, users operating on multiple coins could rebalance their channels. If Alice has 400 litecoins but no bitcoins in her channel with Bob, she may want to exchange 200 litecoins to fund her Bitcoin channel.

Challenges

Some challenges do remain in order to realize most of this scenario.

One is denial of service (DoS) protection. While the mechanics of the lightning network ensure that no peers can steal funds, intermediaries can block or stall the payment process. To solve this, channels with non-cooperating peers must be closed. This form of punishment should make DoS attacks expensive, as non-cooperating peers need to keep opening channels.

But to verify that the channel was closed and the attacker punished, each peer along a payment chain must be able to monitor all participants. Even if only two peers along a chain of six use Litecoin, all six peers should be able to recognize a Litecoin transaction in case the channel is closed.

And of course, lightning networks must first be rolled out. This, in most cases, requires a malleability fix, at least for optimal performance. Segregated Witness — the malleability fix proposed by the Bitcoin Core development team — currently awaits activation on both the Bitcoin network and on several altcoins, including Litecoin.

But Segregated Witness has not activated yet, and whether it ever will depends on miners — both on Bitcoin as well as on altcoins.

Thanks to Amiko Pay developer Corné Plooy and Litecoin inventor Charlie Lee for input. Lee also wrote about the potential of linking Bitcoin and Litecoin lightning networks here.

For specifics on how the lightning network works, see Bitcoin Magazine’s three-part series.

Aaron van Wirdum retouched

Newsletter

The biggest stories in bitcoin delivered weekly
to your inbox

Thank you! Please check your inbox to confirm your subscription.

Store

Call for Writers

We are always looking for talented writers to join our team. If you have an article you'd like to have published to our audience please reach out to

editor@bitcoinmagazine.com