Submarine Swaps: Bridging On-Chain and Lightning
What Are Submarine Swaps?
Submarine Swaps are a specialized form of atomic swap that enables trustless exchanges between Bitcoin's on-chain transactions and Lightning Network payments. They allow users to move funds between the two systems without requiring direct channel connections.
Named "submarine" because the connection between the on-chain transaction and the Lightning payment remains hidden to outside observers, these swaps provide enhanced privacy while enabling important liquidity services for the Lightning Network ecosystem.
On-Chain to Lightning
A user who only has on-chain Bitcoin wants to pay a Lightning invoice. The swap provider receives the on-chain funds and fulfills the Lightning payment on the user's behalf.
This is sometimes called a "Loop In" operation, as it brings liquidity into the Lightning Network.
Lightning to On-Chain
A user wants to convert Lightning funds to on-chain Bitcoin. The swap provider receives the Lightning payment and sends on-chain funds to the user's specified address.
This is sometimes called a "Loop Out" operation, as it extracts liquidity from the Lightning Network back to the chain.
How Submarine Swaps Work (Technical Implementation)
At their core, Submarine Swaps rely on Hash Time-Locked Contracts (HTLCs) to ensure atomicity—either both sides of the swap complete successfully, or neither does.
On-Chain to Lightning (Loop In)
User Has Invoice: User wants to pay a Lightning invoice but only has on-chain BTC.
Contact Swap Provider: The user contacts a submarine swap provider and shares the invoice details.
HTLC Deployment: The swap provider creates an on-chain HTLC that locks funds and can only be unlocked with the same payment preimage that will unlock the Lightning payment.
User Funds HTLC: The user sends on-chain BTC to the HTLC address.
Lightning Payment: The swap provider pays the Lightning invoice, learning the preimage in the process.
Claim On-Chain Funds: The swap provider uses the preimage to claim the on-chain funds from the HTLC.
Lightning to On-Chain (Loop Out)
User Needs On-Chain: User has Lightning BTC but needs on-chain funds (e.g., to rebalance channels).
Contact Swap Provider: The user contacts a swap provider with their on-chain Bitcoin address.
On-Chain HTLC Creation: The swap provider creates an on-chain HTLC using a secret they generate.
Invoice Creation: The swap provider creates a Lightning invoice using the same hash and shares it with the user.
Lightning Payment: The user pays the Lightning invoice.
Release Secret: The swap provider reveals the preimage to claim the Lightning payment.
Claim On-Chain: With the preimage now public, the user can claim the on-chain funds from the HTLC.
Use Cases and Applications
Channel Rebalancing
Lightning node operators can rebalance their channels by moving funds in one direction on-chain while moving them in the opposite direction through Lightning channels.
Exchange Integration
Cryptocurrency exchanges can offer Lightning deposits and withdrawals without having to directly manage Lightning channels with each customer.
Instant Deposits
Services that require on-chain Bitcoin deposits can accept Lightning payments instead, offering instant confirmation without waiting for on-chain transactions.
Security and Trust Considerations
While Submarine Swaps are designed to be trustless, there are several security factors to consider:
Chain Confirmation Times
On-chain HTLCs require confirmation before they're secure, creating a time delay. Lightning payments are nearly instant, creating a timing mismatch that needs careful handling.
Fee Considerations
Swap providers typically charge fees for their services. These fees need to be factored into the swap calculations, especially during periods of high on-chain fees.
Timelock Management
HTLCs include timelocks to ensure funds can be reclaimed if the swap fails. These timeouts must be carefully set to avoid race conditions or locked funds.
Liquidity Requirements
Swap providers need sufficient liquidity both on-chain and in Lightning channels to facilitate swaps, which can limit availability during high-demand periods.