As bitcoin scales in layers, it provides new solutions for developers and consumers. It also offers new and exciting challenges to close the gap between layers and abstract away complexity. One issue between lightning and the base chain is getting funds in and out of the two environments without having to open and close channels.
One way to move funds between the two is that of submarine swaps which is an atomic on-chain to off-chain swaps (and vice-versa) of bitcoin. The idea conceptualised by Lightning Labs CTO Olaoluwa Osuntokun and Lightning Labs Infrastructure Lead Alex Bosworth is designed to facilitate the transfer from on-chain BTC to an off-chain Lightning Network (LN) channel.
Currently, this is not directly possible without submarine swaps and requires an additional step where a user has to transfer LN funds to their on-chain Bitcoin wallet.
Described as “on-chain ramps to the LN,” submarine swaps have several profound use cases and potential implications. Unlike atomic swaps — where LN needs to be enabled on both networks participating in an exchange — submarine swaps only need one side to be lightning enabled.
What are submarine swaps?
Submarine swaps allow a user to convert on-chain to off-chain funds or in reverse. They are based on a specific type of Bitcoin smart contract called Hash Time-Locked Contracts, HTLCs for short. Since HTLCs can include both on-chain and off-chain transactions.
HTLC’s can also be used to chain payments and is the main construct that enables money transfer over the Lightning Network. HTLCs can also be leveraged between an on-chain sender and an off-chain receiver, and vice versa, and these are submarine swaps.
The submarine swap smart contract is called a swap provider. It can be managed by a third-party service but is a smart contract on the blockchain.
Submarines can be used to:
- Trustlessly pay a swap provider in one network to perform a payment onto the other network
- Trustlessly pay a swap provider in one network to get coins onto the other network
- Trustlessly pay a swap provider to rebalance our lightning channels
Why the need for submarine swaps?
The primary problem that submarine swaps address is that transactions between on-chain Bitcoin addresses and off-chain LN addresses are not directly compatible. You cannot easily send a lightning transaction to someone who doesn’t use lightning or vice versa. This separation of layers creates a transaction barrier between the Bitcoin blockchain and the off-chain LN.
An additional limitation of the current LN implementation is that setting up an LN channel requires an on-chain transaction (and subsequent fee) and a prefilled amount of BTC sent to the channel.
Once that supply of BTC in the channel runs out, there is no method to refill the channel, and another channel needs to be opened to continue use. Although essentially unlimited transactions can be sent within an LN channel as long as there is enough BTC in the channel.
Manging channels cost more on-chain transaction fees and complexity making it inconvenient and inefficient to open multiple channels repeatedly.
How submarine swaps solve the problem
Submarine swaps solve this problem by allowing LN channels to be refilled through an on-chain transfer from the Bitcoin blockchain to the off-chain LN channel. Submarine swaps are inspired by atomic swaps, so they work with similar functionality.
Submarine and atomic swaps utilise a trustless intermediary for transferring tokens between blockchains or intra-chain (i.e., Bitcoin on-chain to off-chain LN).
Submarine swaps leverage hash-time locked contracts where the receiver of a transaction needs to acknowledge receiving the payment before a specific deadline by providing cryptographic proof of payment. If not, the receiver forfeits the ability to claim the tokens, and they are returned to the payer.
How do submarine swaps work?
Submarine swaps allow users and wallet providers to send funds to the lightning network from the bitcoin base chain or from the base chain to the lightning network without using a third party service. A Bitcoin smart contract provides a path where users can fund their lightning wallets or bitcoin wallets seamlessly.
Submerging complexity of bitcoin layers
Submarine swaps are another tool in the growing arsenal for wallet providers and savvy bitcoin users to trustlessly transfer tokens. They provide a bridge between on-chain transactions and off-chain LN channels vital to the future scalability of the bitcoin blockchain and other side chains and the birth of genuinely decentralised exchanges.
Submarine swaps provide the building blocks for a utopian future of interchangeable assets across trust-minimised networks.