Loop In/Out
Lightning Network

Loop In/Out

Key Takeaways

  • Loop moves funds between on-chain and Lightning without custody. Using submarine swaps, you can convert on-chain Bitcoin to Lightning balance (Loop In) or Lightning balance to on-chain Bitcoin (Loop Out) without trusting a third party with your funds.
  • Atomic swaps guarantee all-or-nothing execution. The underlying HTLC mechanism ensures either the swap completes entirely or both parties get their funds back. No counterparty can steal funds mid-swap.
  • Essential for Lightning liquidity management. Node operators use Loop to rebalance channels, acquire inbound liquidity, and move funds on or off Lightning without closing channels or relying on custodial exchanges.

What Is Loop In/Out?

Loop In and Loop Out are operations that move Bitcoin between the on-chain layer and Lightning Network using submarine swaps. The terms originated from Lightning Labs' Loop service, though the underlying technique works with any submarine swap provider.

Loop Out sends funds from Lightning to an on-chain address. You pay via Lightning and receive Bitcoin on-chain. This is useful when you need on-chain funds without closing channels.

Loop In sends funds from on-chain to Lightning. You pay from an on-chain wallet and receive the equivalent amount in your Lightning channels. This adds inbound capacity from the swap provider's perspective.

Both operations use submarine swaps: atomic exchanges where one leg happens on-chain and the other on Lightning. The swap is trustless because cryptographic hash locks connect both transactions. Neither party can cheat.

How Submarine Swaps Work

Submarine swaps use the same hash time-locked contract (HTLC) mechanism that powers Lightning payments, extended to coordinate with on-chain Bitcoin transactions. The key insight is that the same hash can lock funds on both layers simultaneously.

The atomic swap pattern works like this:

  1. Shared secret creation: One party generates a random preimage and computes its SHA256 hash. This hash will lock both the on-chain and Lightning transactions.
  2. First leg locks funds: One party locks their funds using an HTLC (either on-chain or Lightning) that requires the preimage to claim.
  3. Second leg locks funds: The counterparty locks their funds on the other layer using the same hash. Now both sides have funds locked to the same secret.
  4. Preimage reveal completes swap: The party who knows the preimage claims their funds by revealing it. This revelation allows the other party to claim their side.

The beauty of this construction is atomicity. If one party reveals the preimage to claim funds, the other party automatically learns it and can claim their side. If no one reveals the preimage before timeout, both parties recover their original funds via the timelock path.

Loop Out Explained

Loop Out converts Lightning balance to on-chain Bitcoin. This is the most common use case because Lightning users frequently need to move funds on-chain without closing channels.

The Loop Out process:

  1. You initiate the swap: Specify the amount and your on-chain destination address. The swap service quotes a fee.
  2. Service creates on-chain HTLC: The service generates a preimage and creates an on-chain HTLC that pays to your address if you reveal the preimage, or returns to the service after timeout.
  3. You pay via Lightning: You pay a hodl invoice from the service. The service holds this payment pending.
  4. Service reveals preimage: Once the service sees your Lightning payment locked, they reveal the preimage to settle the Lightning invoice. This same preimage lets you claim the on-chain funds.
  5. You claim on-chain funds: Using the revealed preimage, you (or automatically, your wallet) claims the on-chain HTLC output.

The service cannot steal your funds because they only learn the preimage after locking on-chain funds to you. You cannot steal the service's funds because you only get the preimage after your Lightning payment is locked.

Loop In Explained

Loop In converts on-chain Bitcoin to Lightning balance. This increases your inbound liquidity because the swap provider pushes funds to you through existing channels.

The Loop In process (simplified):

  1. You initiate the swap: Specify the amount you want to receive on Lightning. The service provides an on-chain address.
  2. You pay on-chain: Send Bitcoin to the service's HTLC address. This locks your funds with a hash that you generated.
  3. Service pays via Lightning: Once your on-chain payment confirms, the service sends you a Lightning payment locked to the same hash.
  4. You reveal preimage: You claim the Lightning payment by revealing the preimage. This allows the service to claim your on-chain deposit.

Loop In is particularly valuable for receiving payments. After a Loop In, you have fresh inbound capacity from the service's node, enabling others to pay you through that channel.

Use Cases

Channel Liquidity Management

Running a Lightning node requires managing channel liquidity. As you route payments or spend, your local balance shifts. Eventually, channels become depleted (all funds on one side) and need rebalancing.

Loop Out lets you drain Lightning balance to on-chain without closing channels. This frees up inbound capacity on those channels. Loop In does the reverse: convert on-chain funds to Lightning capacity without opening new channels.

Merchant Offramp

Merchants accepting Lightning payments need to convert to fiat or on-chain Bitcoin eventually. Loop Out provides a non-custodial path from Lightning to on-chain, where funds can then move to an exchange for fiat conversion.

This is cleaner than closing channels, which would require reopening them later and paying on-chain fees twice.

Inbound Liquidity Acquisition

New Lightning nodes struggle to receive payments because they lack inbound liquidity. Opening channels only creates outbound capacity. Loop In solves this: pay on-chain, receive Lightning balance pushed to you, gaining inbound capacity from the swap provider's perspective.

Non-Custodial Exchange

Users wanting to move between layers without trusting an exchange can use submarine swaps. Loop In/Out services provide this trustlessly. Popular in privacy-conscious communities where avoiding KYC exchanges is important.

Cold Storage Integration

Loop Out enables moving Lightning funds to cold storage without channel closure. A merchant could Loop Out weekly earnings to a hardware wallet address, keeping hot wallet exposure limited while maintaining channel relationships.

Services and Implementations

Lightning Loop

Lightning Labs operates Loop, the most established submarine swap service. Integrated into LND and many Lightning wallets, Loop offers both Loop In and Loop Out with competitive fees. The service is non-custodial but centralized: Lightning Labs operates the swap server.

Boltz Exchange

Boltz provides submarine swaps with a focus on privacy and decentralization. Boltz requires no accounts, supports Tor, and runs open-source swap infrastructure. They also support swaps between Bitcoin and Liquid Network.

Deezy

Deezy offers instant swaps between on-chain and Lightning, including integration with their node-in-a-box solution. Known for fast execution and node operator tools.

Self-Hosted Options

The Boltz backend is open source, allowing anyone to run their own submarine swap service. This is useful for businesses wanting to offer swaps to customers without relying on third-party services.

Trust Model and Security

Trustless Execution

Submarine swaps are cryptographically trustless. The HTLC construction ensures neither party can steal funds. However, the swap service could refuse to complete swaps (griefing) or go offline mid-swap. In these cases, funds return to the original owner via timelock.

Timing Considerations

On-chain confirmation times create timing vulnerabilities. If a Loop Out takes hours to confirm on-chain (high fee environment), the Lightning HTLC may approach timeout. Services manage this by adjusting fees and timeouts based on mempool conditions.

Fee Economics

Submarine swaps involve on-chain fees (paid by one party), Lightning routing fees, and service fees. Total costs depend on on-chain congestion, swap size, and service pricing. During high-fee periods, small swaps become uneconomical.

Privacy Considerations

Centralized swap services see your on-chain addresses and Lightning invoices. They could correlate these for chain analysis. Privacy-focused users prefer services like Boltz that require no accounts and support Tor.

FAQ

Loop Out moves funds from Lightning to on-chain. You spend Lightning balance and receive Bitcoin at an on-chain address. Loop In is the reverse: you send on-chain Bitcoin and receive the equivalent amount in your Lightning channels. Loop Out is more common because merchants and users often need to exit Lightning to on-chain.

Integrate Lightning the Easy Way

The simplest, cheapest, and fastest way to add Lightning payments to your app with the Spark SDK.

View SDK Docs →