<oembed><type>rich</type><version>1.0</version><author_name>npub19helcfnqgk2jrwzjex2aflq6jwfc8zd9uzzkwlgwhve7lykv23mq5zkvn4</author_name><author_url>https://nostr.ae/npub19helcfnqgk2jrwzjex2aflq6jwfc8zd9uzzkwlgwhve7lykv23mq5zkvn4</author_url><provider_name>njump</provider_name><provider_url>https://nostr.ae</provider_url><html>📅 Original date posted:2023-01-04&#xA;🗒️ Summary of this message: A proposal for a faster way to move funds from an on-chain address to the Lightning Network using regular swaps, which simplifies the process and reduces trust requirements.&#xA;📝 Original message:&#xA;Hi Z,&#xA;&#xA;&gt; * Submarine swap/peerswap: Requires confirmation before the swap service&#xA;&gt; will send out the HTLC on Lightning.&#xA;&#xA;I might be missing something, but I don&#39;t see how this is different from a&#xA;normal on-chain to off-chain swap (calling this Loop In for short in the&#xA;remainder of the email).&#xA;&#xA;Given some static swap server params (server key, user key, preimage), a&#xA;user can derive a tapscript tree and use that to make addresses that any 3rd&#xA;party can send to. Services like Loop return a few addrs (including P2TR!)&#xA;the client can use depending on their wallet sophistication [1] (in this&#xA;case the command is: `loop in --amt=X --external\, external means a 3rd&#xA;party will send to the addr). After a 3rd party sends to the script, the&#xA;swap can be completed at anytime as soon as the client is online (assuming&#xA;swap server is always there).&#xA;&#xA;In the scenario above, the newly created outputs to our swap addr need to be&#xA;confirmed before the swap server will initiate the swap. As you mention,&#xA;this could even be zero conf assuming all sides take w/e precautions they&#39;re&#xA;comfortable with. If the swap server goes away for w/e reason, a long&#xA;timeout in the swap can let the user sweep the funds via some other&#xA;means eventually. This doesn&#39;t need to be a direct swap either, and it can&#xA;flow multi-hop like any other swap.&#xA;&#xA;In your scheme you say that:&#xA;&#xA;&gt; If so, then the &#34;timer for confirmation&#34; starts as soon as the wallet&#xA;&gt; receives on the blockchain, not as soon as the wallet decides to move&#xA;&gt; funds from blockchain to Lightning.&#xA;&#xA;Which seems to be the exact same as the flow I described above. For our&#xA;newer musig2-enabled swaps, the top level keyspend can be spent by both&#xA;parties, so you also emulate the ability for Alice to move the funds on&#xA;chain anywhere else w/ the server&#39;s cooperation.&#xA;&#xA;Using regular swaps also simplified the &#34;Bob Security&#34; section a lot, as Bob&#xA;sends out an HTLC w/ the corresponding swap hash (he watches the chain for&#xA;the scripts, then initiates the swap once they&#39;re seen).&#xA;&#xA;[1]: https://lightning.engineering/api-docs/api/loop/swap-client/loop-in&#xA;&#xA;-- Laolu&#xA;&#xA;On Tue, Jan 3, 2023 at 5:58 AM ZmnSCPxj via Lightning-dev &lt;&#xA;lightning-dev at lists.linuxfoundation.org&gt; wrote:&#xA;&#xA;&gt; Subject: Swap-in-Potentiam: Moving Onchain Funds &#34;Instantly&#34; To Lightning&#xA;&gt;&#xA;&gt; by Jesse Posner, ZmnSCPxj&#xA;&gt;&#xA;&gt; Introduction&#xA;&gt; ============&#xA;&gt;&#xA;&gt; Moving funds from an onchain-only address to Lightning Network is slow,&#xA;&gt; especially if you desire trust-minimization (which removes solutions&#xA;&gt; relying on 0-conf).&#xA;&gt;&#xA;&gt; Basically, to reduce trust requirements in all onchain transactions,&#xA;&gt; onchain receivers *MUST* ensure confirmation of the onchain transaction&#xA;&gt; that creates their UTXO.&#xA;&gt; In practice, the minimum should be at least 3 blocks, since reorgs of&#xA;&gt; up to 2 blocks are common occurences, but even 1 confirmation can&#xA;&gt; take an inordinately long time in the real world due to the random&#xA;&gt; nature of mining.&#xA;&gt;&#xA;&gt; This is particularly acute for mobile phone use-cases.&#xA;&gt; As mobile phones run on a battery, mobile phone OSs often greatly&#xA;&gt; restrict CPU and other resource consumption when an app is not&#xA;&gt; currently open by the user.&#xA;&gt;&#xA;&gt; Now consider this user story, for a wallet app that supports both&#xA;&gt; Bitcoin blockchain and Lightning Network operations:&#xA;&gt;&#xA;&gt; * The user wants to be paid over the Bitcoin blockchain.&#xA;&gt; * The user gets an address from their wallet and provides it to&#xA;&gt;   some other party to receive their payment.&#xA;&gt; * The user closes their wallet app, which causes the mobile phone&#xA;&gt;   OS to kill all its threads.&#xA;&gt; * The other party sends their payment over blockchain while the&#xA;&gt;   user is asleep.&#xA;&gt; * The blockchain transaction confirms and time passes.&#xA;&gt; * The user wakes up and checks their favorite blockchain explorer,&#xA;&gt;   and sees they received funds on their wallet address.&#xA;&gt; * The user opens their wallet app and decides they need a coffee,&#xA;&gt;   so they buy coffee over Lightning.&#xA;&gt;&#xA;&gt; For current solutions to move funds from the blockchain layer to&#xA;&gt; Lightning, however, the above user story would need to complete&#xA;&gt; over a long time, possibly measurable in dozens of minutes or&#xA;&gt; even hours in the worst case, due to the need for confirmation:&#xA;&gt;&#xA;&gt; * Channel open: Requires confirmation, many nodes require 6 or&#xA;&gt;   more confirmations.&#xA;&gt; * Submarine swap/peerswap: Requires confirmation before the swap&#xA;&gt;   service will send out the HTLC on Lightning.&#xA;&gt; * Splice-in: Channel remains operational, but until the splice&#xA;&gt;   transaction confirms, the channel operates in &#34;dual mode&#34;&#xA;&gt;   where both pre-splice and post-splice state is valid, and&#xA;&gt;   that means only the lower amount of the pre-splice and&#xA;&gt;   post-splice can be used in the mean time.&#xA;&gt;   For splice-in, the pre-splice amount will be lower, thus&#xA;&gt;   the amount being spliced in will not be credited until&#xA;&gt;   the splice transaction is confirmed.&#xA;&gt;&#xA;&gt; In this writeup, we present a novel protocol, swap-in-potentiam,&#xA;&gt; that can be used for immediate transfer from the blockchain&#xA;&gt; layer to the Lightning layer, in the above user story.&#xA;&gt;&#xA;&gt; Advantages And Limitations&#xA;&gt; --------------------------&#xA;&gt;&#xA;&gt; To whet your appetite, here are the advantages:&#xA;&gt;&#xA;&gt; * Immediate transfer of already-confirmed-received onchain&#xA;&gt;   funds to Lightning.&#xA;&gt; * Onchain funds can also be transferred to another onchain&#xA;&gt;   address (subject to normal onchain confirmation rules).&#xA;&gt;   * This can be &#34;immediate&#34; if sending to a receiver that&#xA;&gt;     accepts the risk of 0-conf onchain transactions.&#xA;&gt; * Minimized trust requirement.&#xA;&gt;&#xA;&gt; The disadvantages, to help convince you that yes, this is&#xA;&gt; technology and not magic beans (and to not oversell this&#xA;&gt; tech, Bitcoin media reporting often tend to oversell&#xA;&gt; new technologies because the disadvantages are often&#xA;&gt; hidden away behind technical minutae):&#xA;&gt;&#xA;&gt; * Requires a cooperating LSP.&#xA;&gt;   If LSP is down or refuses to cooperate, onchain funds&#xA;&gt;   are locked for some time.&#xA;&gt;   This has a timeout (so if the LSP never comes online&#xA;&gt;   again, you just wait out the timeout) and the timeout&#xA;&gt;   starts from when the receiving UTXO is confirmed in a&#xA;&gt;   blocks, so it will not cause loss of funds, only loss&#xA;&gt;   of opportunity (i.e. &#34;involuntary HODLing&#34;).&#xA;&gt; * If you have multiple LSPs, when you generate an address&#xA;&gt;   you *have to* select one of them at that point, you&#xA;&gt;   *cannot* commit to multiple LSPs and select one of them&#xA;&gt;   later when your phone wakes up again.&#xA;&gt;   This exacerbates the above disadvantage, since you have&#xA;&gt;   to select one of your LSPs and hope that when your&#xA;&gt;   phone wakes up the LSP you selected is also up and&#xA;&gt;   cooperative.&#xA;&gt; * The onchain-received funds have to be confirmed first,&#xA;&gt;   otherwise we still need to wait for confirmation of the&#xA;&gt;   onchain-received funds.&#xA;&gt;   This is generally true for many blockchain-only wallets&#xA;&gt;   anyway and is thus not a worsening, but is also not an&#xA;&gt;   improvement.&#xA;&gt; * If the timeout is too near, actions must be performed&#xA;&gt;   onchain that require confirmation.&#xA;&gt;&#xA;&gt; Swap-in-Potentiam&#xA;&gt; =================&#xA;&gt;&#xA;&gt; All onchain fund movements, as noted, require confirmation.&#xA;&gt; These include onchain fund movements to the Lightning network.&#xA;&gt;&#xA;&gt; If the onchain address that the wallet provides was controlled&#xA;&gt; solely by that wallet, then any action that requires cooperation&#xA;&gt; with a Lightning Network participant --- channel open, swap, or&#xA;&gt; splice --- would require an onchain transaction that commits to&#xA;&gt; that specific Lightning Network participant.&#xA;&gt; Only when the new onchain transaction is confirmed, can that&#xA;&gt; Lightning participant rely on the transaction output without&#xA;&gt; having to trust the initiator.&#xA;&gt;&#xA;&gt; From there, we can consider: what if the wallet provides an&#xA;&gt; address that *already* commits to that specific Lightning Network&#xA;&gt; participant?&#xA;&gt;&#xA;&gt; If so, then the &#34;timer for confirmation&#34; starts as soon as&#xA;&gt; the wallet receives on the blockchain, not as soon as the wallet&#xA;&gt; decides to move funds from blockchain to Lightning.&#xA;&gt;&#xA;&gt; This is a significant difference for a mobile wallet: the mobile&#xA;&gt; environment does not support the mobile wallet being online for&#xA;&gt; long.&#xA;&gt; Thus, the mobile wallet may not have any CPU to make the decision&#xA;&gt; to move funds from blockchain to Lightning, until the actual user&#xA;&gt; explicitly opens the mobile wallet app.&#xA;&gt;&#xA;&gt; It has already been generally accepted that due to the limitations&#xA;&gt; of the mobile phone environment, a mobile phone wallet with&#xA;&gt; Lightning support would need some LSP anyway.&#xA;&gt; Thus, a mobile wallet that can receive on the blockchain layer&#xA;&gt; and then send on the Lightning layer can commit to a specific,&#xA;&gt; different, Lightning participant: the LSP it has channels with.&#xA;&gt;&#xA;&gt; Thus, the mobile wallet can provide an address that commits to&#xA;&gt; one particular Lightning Network participant: its LSP.&#xA;&gt;&#xA;&gt; The mobile wallet can then initiate a single-hop swap with the&#xA;&gt; LSP when the mobile wallet app is in the foreground and has CPU&#xA;&gt; to think with.&#xA;&gt; If it received funds into the address that have already been&#xA;&gt; confirmed, then it can do this single-hop swap immediately with&#xA;&gt; its LSP.&#xA;&gt; The LSP can immediately resolve this swap, crediting funds to&#xA;&gt; channel, while atomically ensuring it has sole claim to the&#xA;&gt; onchain UTXO.&#xA;&gt;&#xA;&gt; The Contract&#xA;&gt; ------------&#xA;&gt;&#xA;&gt; The contract has two participants: Alice the funds owner, and&#xA;&gt; Bob its potential swap partner.&#xA;&gt;&#xA;&gt; Once *any* funds have been confirmed received into an address&#xA;&gt; committing to this contract, Alice owns the funds and can&#xA;&gt; dispose of them as it likes (with cooperation from Bob).&#xA;&gt; The source of the funds need not be Alice, it could be a third&#xA;&gt; party that has an obligation to pay Alice onchain.&#xA;&gt;&#xA;&gt; The contract has only 2 branches:&#xA;&gt;&#xA;&gt; * Onchain/channel branch: Alice and Bob.&#xA;&gt; * Timelock branch: Alice plus a relative timelock (`OP_CSV`)&#xA;&gt;   measurable in weeks.&#xA;&gt;&#xA;&gt; Astute readers will realize that the above is really a variant&#xA;&gt; of [CLTV-style unidirectional time-limited channels][1],&#xA;&gt; themselves a variant of Spilman-style channels:&#xA;&gt;&#xA;&gt; * Uses an explicit opcode to simplify channel setup (no need&#xA;&gt;   to pre-sign a timeout transaction between Alice and Bob,&#xA;&gt;   can just send funds directly to the address).&#xA;&gt; * Uses a relative locktime instead of an absolute one to&#xA;&gt;   allow funding of the channel address (= receive onchain&#xA;&gt;   funds ready to spend over Lightning) at any time.&#xA;&gt;&#xA;&gt; The use-cases this enables are:&#xA;&gt;&#xA;&gt; * If Alice wants to pay to another onchain address, and Bob&#xA;&gt;   is also online and cooperative, Alice can ask Bob to help&#xA;&gt;   sign the Onchain/channel branch to move the funds in any&#xA;&gt;   arbitrary onchain manner.&#xA;&gt; * If Alice wants to pay to a Lightning invoice / keysend, and&#xA;&gt;   has insufficient Lightning outgoing capacity (but has&#xA;&gt;   sufficient *total* capacity), it can swap with Bob, by&#xA;&gt;   offerring a transaction that spends via the Onchain/channel&#xA;&gt;   branch and instantiates a fresh onchain HTLC that Bob can&#xA;&gt;   then forward over Lightning.&#xA;&gt;   As soon as Alice offers its signature of that transaction,&#xA;&gt;   Bob can immediately offer an in-Lightning HTLC to Alice on&#xA;&gt;   their channel, and then Alice can immediately resolve it&#xA;&gt;   (thus immediately getting its funds into Lightning).&#xA;&gt; * If Bob is offline or uncooperative, Alice can unilterally&#xA;&gt;   recover its funds after the timeout in the Timelock&#xA;&gt;   branch.&#xA;&gt;&#xA;&gt; Trust is required only to the extent that Alice trusts Bob to&#xA;&gt; be cooperative so that Alice can dispose of its funds immediately.&#xA;&gt; In case Bob turns out to be non-trustworthy, Alice can recover&#xA;&gt; its funds via the timelock branch after the timeout period.&#xA;&gt; There is no scope for Bob to steal funds (indeed, it is easier&#xA;&gt; for Bob to steal Lightning funds than to steal swap-in-potentiam&#xA;&gt; funds).&#xA;&gt;&#xA;&gt; The intent here is that the mobile wallet is Alice, while the&#xA;&gt; LSP is Bob.&#xA;&gt;&#xA;&gt; ### Bob Security&#xA;&gt;&#xA;&gt; Bob *MUST* ensure that, for each UTXO, it is either asked to&#xA;&gt; sign an arbitrary onchain transaction (i.e the first use-case&#xA;&gt; above) *OR* it gets offered an onchain HTLC from that UTXO.&#xA;&gt; Once Alice has asked Bob to cooperate in either case for a&#xA;&gt; particular UTXO, Bob *MUST* ensure that it does not sign the other&#xA;&gt; case (and Bob *MUST* refuse to cooperate in the other case once&#xA;&gt; one case has been requested).&#xA;&gt;&#xA;&gt; In addition, Bob *MUST* ensure that, if it is used in the&#xA;&gt; &#34;channel&#34; case (i.e. the second use-case above), the timeout of&#xA;&gt; the Timelock branch is far enough in the future that it is likely&#xA;&gt; that spends using the Onchain/channel branch have confirmed by&#xA;&gt; then.&#xA;&gt;&#xA;&gt; With both invariants enforced by Bob, Bob can ensure that, if&#xA;&gt; Alice requests a swap using the Onchain/channel branch, only Bob&#xA;&gt; can spend the UTXO (at least before the timeout), and thus can&#xA;&gt; safely offer a Lightning HTLC to Alice immediately without any&#xA;&gt; additional waiting for onchain confirmations.&#xA;&gt;&#xA;&gt; As Bob needs to know the UTXO in the first use-case above, this&#xA;&gt; requirement prevents the use of blind signing techniques when&#xA;&gt; implementing the first use-case.&#xA;&gt; Basically, when being asked to sign, Bob must generate the entire&#xA;&gt; `SIGHASH` from data that Alice provides, so that Bob is able to&#xA;&gt; keep track of UTXOs it is signing for.&#xA;&gt;&#xA;&gt; ### Remote Swap&#xA;&gt;&#xA;&gt; While Bob is generally considered &#34;the&#34; LSP of the mobile wallet&#xA;&gt; Alice, nothing in the Lightning protocol actually requires that&#xA;&gt; Bob be a direct peer of Alice.&#xA;&gt; The only real requirement is that Bob is able to send funds to&#xA;&gt; Alice over Lightning in exchange for possession of the equivalent&#xA;&gt; onchain funds.&#xA;&gt;&#xA;&gt; Against this, we should note that the mobile wallet is already&#xA;&gt; dependent on one or more LSPs anyway, so it may as well just use&#xA;&gt; its direct peer LSPs instead of a remote node.&#xA;&gt;&#xA;&gt; ### Address Derivation&#xA;&gt;&#xA;&gt; Swap-in-potentiam addresses can be derived from a root public or&#xA;&gt; private key.&#xA;&gt;&#xA;&gt; We only need one keypair each from Alice and Bob.&#xA;&gt; Alice can use standard derivation paths for its keypair.&#xA;&gt;&#xA;&gt; As Bob is intended to be an LSP, we can just use its Lightning&#xA;&gt; node ID as the public key.&#xA;&gt; Bob needs to be in possession of the corresponding private key&#xA;&gt; anyway in order to set up BOLT 8 encrypted transports.&#xA;&gt;&#xA;&gt; As LSPs are part of the public network, Alice can simply try to&#xA;&gt; scan for all published nodes that advertise support for&#xA;&gt; swap-in-potentiam.&#xA;&gt; Alternately if the wallet has a short list of fixed LSPs it&#xA;&gt; will use, it can simply refer to that list.&#xA;&gt;&#xA;&gt; Thus:&#xA;&gt;&#xA;&gt; * Alice uses a derived keypair.&#xA;&gt; * Bob uses a fixed keypair (its Lightning node ID).&#xA;&gt;&#xA;&gt; The above is sufficient to derive swap-in-potentiam addresses&#xA;&gt; from an `xprv` or `xpub` root key.&#xA;&gt;&#xA;&gt; Swap-in-potentiam For LSPs&#xA;&gt; ==========================&#xA;&gt;&#xA;&gt; While the original design of swap-in-potentiam has the mobile&#xA;&gt; wallet in the &#34;Alice&#34; role and its LSP in the &#34;Bob&#34; role, it&#xA;&gt; turns out that LSPs can provide special service to improve&#xA;&gt; receiving mobile wallets.&#xA;&gt;&#xA;&gt; Suppose that the LSP keeps track of statistics, and thus has&#xA;&gt; an idea of which of its mobile wallet clients are likely to&#xA;&gt; be net receivers.&#xA;&gt;&#xA;&gt; Net receivers will often have low inbound capacity (since the&#xA;&gt; inbound capacity has been used up during previous LN receives).&#xA;&gt;&#xA;&gt; During times of low onchain fees, an LSP can check which of its&#xA;&gt; offline mobile wallet clients have low inbound capacity, and are&#xA;&gt; likely to come online in the future to receive.&#xA;&gt; In those cases, the LSP can commit funds to a swap-in-potentiam&#xA;&gt; with the mobile client, with the LSP as &#34;Alice&#34; and the mobile&#xA;&gt; client as &#34;Bob&#34;.&#xA;&gt; This at least lets the LSP set up half of a swap during a time of&#xA;&gt; low fees.&#xA;&gt;&#xA;&gt; If the transfer to swap-in-potentiam addresses is confirmed by&#xA;&gt; the time the mobile wallet client comes online, the LSP can&#xA;&gt; immediately initiate a swap, giving inbound capacity towards the&#xA;&gt; mobile client.&#xA;&gt; This swap can be immediately resolved, and allows the mobile&#xA;&gt; wallet client to immediately receive funds over Lightning.&#xA;&gt;&#xA;&gt; In particular, if &#34;offline receive&#34; as designed by TheBlueMatt&#xA;&gt; is implemented, then the LSP already has indication of a pending&#xA;&gt; payment towards an offline mobile wallet client.&#xA;&gt; The LSP can check if the offline mobile wallet client has&#xA;&gt; insufficient incoming capacity to receive the funds, and if so,&#xA;&gt; arrange to fund a swap-in-potentiam with that client.&#xA;&gt; Then, when the mobile wallet client comes online, the LSP can&#xA;&gt; initiate the swap with them, and once the swap completes (and&#xA;&gt; thus the mobile wallet client has sufficient incoming capacity)&#xA;&gt; the LSP can contact the sender LSP to complete the payment.&#xA;&gt;&#xA;&gt; In particular, this use-case allows for *immediate* receives as&#xA;&gt; soon as the mobile wallet client gets foregrounded and has CPU&#xA;&gt; time, **without** requiring 0-conf trusted transactions and&#xA;&gt; thus without requiring any kind of semi-custodial trust, even&#xA;&gt; if the mobile wallet client had insufficient incoming capacity.&#xA;&gt; A channel still has to be set up beforehand (without 0-conf, if&#xA;&gt; trusting funds to the LSP is undesirable).&#xA;&gt;&#xA;&gt; Implementation Sketch&#xA;&gt; =====================&#xA;&gt;&#xA;&gt; The intent is to use Taproot with Schnorr signatures, but&#xA;&gt; **without** using the keyspend path (at least initially).&#xA;&gt;&#xA;&gt; The plan currently is to use a `MuSig(A, B)` as the internal&#xA;&gt; pubkey, but with the branches still explicitly laid out as&#xA;&gt; tapleaves.&#xA;&gt; That is, there are two tapleaf SCRIPTs corresponding to the&#xA;&gt; two branches described above:&#xA;&gt;&#xA;&gt; * `&lt;A&gt; OP_CHECKSIGVERIFY &lt;B&gt; OP_CHECKSIG`&#xA;&gt; * `&lt;timelock&gt; OP_CHECKSEQUENCEVERIFY OP_DROP &lt;A&gt; OP_CHECKSIG`&#xA;&gt;&#xA;&gt; Using an explicit 2-of-2 branch rather than a MuSig allows&#xA;&gt; for a simple protocol at least for initial deployment:&#xA;&gt; we can have Alice send the signature using `A` in a single&#xA;&gt; half-round without having to engage in a 2-round MuSig2 signing&#xA;&gt; ritual.&#xA;&gt;&#xA;&gt; We intend to use Taproot since the mobile wallet client&#xA;&gt; may need to use a 2-of-3 or 2-of-2 signing scheme, similar&#xA;&gt; to Blockstream Green.&#xA;&gt; This allows either Alice or Bob in the contract to secretly&#xA;&gt; be a FROST 2-of-3 or MuSig 2-of-2 (or any FROST k-of-n or&#xA;&gt; MuSig n-of-n).&#xA;&gt; This is also another reason for avoiding a 2-of-2 MuSig&#xA;&gt; keyspend path between Alice and Bob, as there is (to our&#xA;&gt; knowledge) no publicly-reviewed security proof that&#xA;&gt; FROST-in-MuSig and MuSig-in-MuSig are safe (or the&#xA;&gt; corresponding variants using MuSig2 for the signing&#xA;&gt; ritual).&#xA;&gt;&#xA;&gt; Later, when we are more confident of the use of MuSig2 and&#xA;&gt; FROST inside a MuSig2, and with using MuSig2 with possibly&#xA;&gt; untrusted outsiders (who might exploit any mis-implementation&#xA;&gt; of the MuSig2 signing protocol if we are not careful with&#xA;&gt; designing it), we can seamlessly upgrade the protocol&#xA;&gt; to use the keyspend path later, to save witness bytes.&#xA;&gt;&#xA;&gt; For the Onchain use-case (i.e. Alice wants to spend the UTXO&#xA;&gt; to an onchain address), the protocol betweeen Alice and Bob&#xA;&gt; would be:&#xA;&gt;&#xA;&gt; * `request_arbitrary_signature` Alice-&gt;Bob: Requests Bob&#xA;&gt;   to sign a PSBT spending a swap-in-potentiam address&#xA;&gt;   using the Onchain branch.&#xA;&gt; * `response_arbitrary_signature` Bob-&gt;Alice: Response to&#xA;&gt;   the above, returning the requested signature.&#xA;&gt; * `reject_arbitrary_signature` Bob-&gt;Alice: Sent in&#xA;&gt;   response to `request_arbitary_signature` if Bob refuses&#xA;&gt;   to cooperate (e.g. the UTXO being spent has already&#xA;&gt;   been accepted by Bob in a Channel use-case below).&#xA;&gt;&#xA;&gt; For the Channel use-case (i.e. Alice wants to spend the UTXO&#xA;&gt; to a Lightning receiver), we operate the swap-in-potentiam&#xA;&gt; UTXO(s) as a Spilman-like channel over two states:&#xA;&gt;&#xA;&gt; * HTLC-offering: Offering an amount `N` HTLC from Alice to&#xA;&gt;   Bob, with any remaining amount to a change address to&#xA;&gt;   Alice.&#xA;&gt; * Resolved: Giving the amount `N` outright to Bob, with any&#xA;&gt;   remaining amount to a change address to Alice.&#xA;&gt;&#xA;&gt; The intention is that the channel is initially put into&#xA;&gt; the HTLC-offerring state.&#xA;&gt; Then Bob offers a corresponding in-Lightning HTLC to Alice&#xA;&gt; over their channel.&#xA;&gt; When Alice resolves the in-Lightning HTLC, it can then&#xA;&gt; send a new signature for the Resolved state.&#xA;&gt; Once the channel is in a Resolved state, Bob *SHOULD* sign&#xA;&gt; the last state and broadcast it on the blockchain, thereby&#xA;&gt; closing the Spilman-like channel.&#xA;&gt;&#xA;&gt; The protocol messages for the Channel use-case are:&#xA;&gt;&#xA;&gt; * `request_swap_in` Alice-&gt;Bob: Tell Bob the UTXOs with&#xA;&gt;   the same swap-in-potentiam address to spend, how&#xA;&gt;   much to put into the Alice-&gt;Bob channel direction,&#xA;&gt;   what channel to move into, and (optionally) a change&#xA;&gt;   address for Alice.&#xA;&gt; * `reject_swap_in` Bob-&gt;Alice: Sent in response to&#xA;&gt;   `request_swap_in` if Bob refuses to cooperate (e.g.&#xA;&gt;   one of the UTXOs on offer was already signed with&#xA;&gt;   `response_arbitrary_signature`, or Bob cannot legally&#xA;&gt;   accept control of funds from one or more of the UTXOs&#xA;&gt;   offerred).&#xA;&gt; * `accept_swap_in` Bob-&gt;Alice: Sent in response to&#xA;&gt;   `request_swap_in`, containing the Bob-side address to&#xA;&gt;   send funds to later once the state is Resolved.&#xA;&gt; * `swap_in_signed` Alice-&gt;Bob: Response to&#xA;&gt;   `accept_swap_in`, containing the Alice-side signature&#xA;&gt;   for the HTLC-offering state transaction.&#xA;&gt;   Once Bob receives this, Bob can safely construct a&#xA;&gt;   new on-Lightning HTLC using BOLT1&#xA;&gt;   `update_offer_htlc`.&#xA;&gt; * `swap_in_resolved` Alice-&gt;Bob: Sent after Alice has&#xA;&gt;   acquired the funds via `update_fulfill_htlc` of the&#xA;&gt;   corresponding on-Lightning HTLC, containing the&#xA;&gt;   Alice-side signature for the Resolved state&#xA;&gt;   transaction.&#xA;&gt;   The Resolved state transaction spends to the Bob-side&#xA;&gt;   address given in `accept_swap_in`, and any change to&#xA;&gt;   the Alice-side change address in `request_swap_in`.&#xA;&gt;&#xA;&gt; The plan is to reserve only one odd BOLT1 message ID,&#xA;&gt; and to embed the actual swap-in-potentiam message ID&#xA;&gt; as the first 2 bytes of the BOLT1 message, to reduce&#xA;&gt; pollution of the limited BOLT1 message ID space and to&#xA;&gt; allow more flexibility for swap-in-potentiam to expand&#xA;&gt; to new messages inside its own message ID space.&#xA;&gt;&#xA;&gt; For a richer future protocol, we will want to consider&#xA;&gt; how a swap-in can be combined with a splice-in.&#xA;&gt; This is useful if the current total capacity of the&#xA;&gt; channel is lower than the available onchain funds.&#xA;&gt; The swap-in can be credited immediately (and is limited&#xA;&gt; to the current total capacity) while additional funds&#xA;&gt; can be added to the channel via splice-in (which is&#xA;&gt; credited only once the splice-in is confirmed).&#xA;&gt;&#xA;&gt; As-is, a similar result can be obtained using openv1,&#xA;&gt; wherein a swap-in is combined with a channel open,&#xA;&gt; with the swap-in immediately credited while the channel&#xA;&gt; open is awaiting confirmation:&#xA;&gt;&#xA;&gt; * Alice and Bob currently have one or more existing&#xA;&gt;   channels, and Alice has a UTXO in a swap-in-potentiam&#xA;&gt;   address whose value exceeds the incoming capacity of&#xA;&gt;   the existing channel(s).&#xA;&gt; * Alice-&gt;Bob `open_channel`.&#xA;&gt; * Bob-&gt;Alice `accept_channel`.&#xA;&gt; * Alice-&gt;Bob `request_swap_in` with the &#34;change address&#34;&#xA;&gt;   being the funding address of the channel.&#xA;&gt; * Bob-&gt;Alice `accept_swap_in` provides the TXID of the&#xA;&gt;   funding transaction (Alice now knows the &#34;change&#xA;&gt;   address&#34; and the Bob final Resolved address, letting it&#xA;&gt;   know the final Resolved state transaction TXID).&#xA;&gt; * Alice-&gt;Bob `funding_created` with the TXID.&#xA;&gt; * Bob-&gt;Alice `funding_signed`.&#xA;&gt; * Alice-&gt;Bob `swap_in_signed` to provide the signature&#xA;&gt;   spending the swap-in-potentiam address to Bob.&#xA;&gt; * Bob then constructs an HTLC over the existing channel,&#xA;&gt;   which Alice claims, revealing the preimage.&#xA;&gt; * Alice-&gt;Bob `swap_in_resolved`.&#xA;&gt; * Bob then broadcasts the Resolved state transaction,&#xA;&gt;   which is also the funding transaction of the new channel.&#xA;&gt; * Both Alice and Bob await confirmation of the transaction&#xA;&gt;   in order to use the new channel.&#xA;&gt;   Alice can still use the existing channel, which has been&#xA;&gt;   topped-up with fresh outgoing capacity by the swap-in.&#xA;&gt;&#xA;&gt; (The above is not safe, as Bob can complete the protocol&#xA;&gt; by using the HTLC-offerring state transaction; this can&#xA;&gt; be fixed by having Alice open *2* channels with the same&#xA;&gt; amount, one with the HTLC-offering state transaction as&#xA;&gt; the funding tx, the other with the Resolved state&#xA;&gt; transaction as the funding tx, and later `error`ing the&#xA;&gt; channel corresponding to the transaction that is not&#xA;&gt; confirmed; this is left as an exercise to the reader,&#xA;&gt; though note that it requires two different change addresses&#xA;&gt; for Alice for both HTLC-offerring and Resolved states,&#xA;&gt; which can be arranged for the protocol)&#xA;&gt;&#xA;&gt; --&#xA;&gt;&#xA;&gt; [1]:&#xA;&gt; https://en.bitcoin.it/wiki/Payment_channels#CLTV-style_payment_channels&#xA;&gt;&#xA;&gt; _______________________________________________&#xA;&gt; Lightning-dev mailing list&#xA;&gt; Lightning-dev at lists.linuxfoundation.org&#xA;&gt; https://lists.linuxfoundation.org/mailman/listinfo/lightning-dev&#xA;&gt;&#xA;-------------- next part --------------&#xA;An HTML attachment was scrubbed...&#xA;URL: &lt;http://lists.linuxfoundation.org/pipermail/lightning-dev/attachments/20230103/5b5b2cad/attachment-0001.html&gt;</html></oembed>