Overview
This is a case study on Lightning Loop, a submarine swap implementation.
Lightning Loop is a non-custodial service for moving funds between Bitcoin's Lightning Network (off-chain) and the Bitcoin blockchain (on-chain). All swaps use Hash Time-Locked Contracts (HTLCs) to ensure atomic execution - either both parties succeed or both fail.
Roles
- Client: Loop daemon (
loopd) connected to user's lnd node (Open source, include loop cli and loopd: https://github.com/lightninglabs/loop)
- Server: Loop server operated by Lightning Labs (Close source)
Standard Loop Out (Off-chain → On-chain)
Move funds from Lightning channels to an on-chain address.
Protocol Flow
- Client generates swap preimage
s and computes hash H(s)
- Client requests quote from Server with desired amount and
H(s)
- Server returns:
- Server's public key
pk_server
- Prepayment invoice (small fee, unrestricted)
- Swap invoice (Lightning) with payment hash
H(s)
- CLTV expiry height for HTLC
- Client pays prepayment invoice (small fee to server)
- Client pays swap invoice (off-chain Lightning, locked to
H(s))
- Server creates on-chain P2WSH HTLC:
- Success path: Unlocked by
s + signature from pk_client
- Timeout path: Unlocked by
pk_server signature after CLTV expiry
- Server publishes HTLC transaction on-chain
- Client sweeps on-chain HTLC using preimage
s (reveals it on-chain)
- Server sees preimage on-chain, settles swap invoice using
s
Security Properties
- Client safety: Only pays after receiving server's commitment (invoices), knowing swap can proceed