Submarine Swap is a trustless swap between Bitcoin (L1) and Lighning (L2). I understand the process of trustless swap from BTC to LN (aka. Swap In, Loop in, or forward swap), but I would need help with the other direction.
The BTC->LN case looks like this:
- Actors: Payer, who wants to pay a LN invoice using BTC, and Provider of the swap service
- Given: a LN invoice, created by a 3rd party, which the Payer wished to pay
Steps:
- Payer initiates a request to the Provider, with the details of the invoice (amount, payment hash, timeouts, etc.) and its own pubkey.
- Provider sets up a 'vault' BTC address, controlled by a script, allowing to be spent by someone who can prove that the LN invoice has been paid (normal branch), or by the Payer after some time (timeout refund branch). Provider communicates the vault address and the BTC amount it expects to Payer.
- Payer verifies the script, and performs on-chain BTC payment to the vault address
- Provider observes the payment, waits for confirmation, verifies it. Then it proceeds to pay the LN invoice (from its LN funds).
- Once the invoice is paid, Provider transfers the BTC from the vault to an address of its control.
- End result: LN invoice is paid, Payer has less BTC, Provider has less LN-BTC but more BTC.
I'm looking for a similar solution for the reverse scenario: Payer wants to pay a recipient in BTC (L1), but it wants to pay over LN. In the 'forward' case the LN payment preimage can be used to prove that the LN payment has been completed, and it can be used as a spend condition in the vault. What secret can be used in the 'reverse' case? How can refund be implemented?
Most of the Submarine Swap descriptions mention that reverse direction also works, but I have not found a detailed description. Some wallets use reverse swap to be able to pay out LN to on-chain BTC.
Some references:
- Good description with concrete detailed example: https://medium.com/suredbits/how-do-submarine-swaps-work-907ed0d91498
- Lightning Labs Guide: https://docs.lightning.engineering/the-lightning-network/multihop-payments/understanding-submarine-swaps