<oembed><type>rich</type><version>1.0</version><author_name>npub1g5zswf6y48f7fy90jf3tlcuwdmjn8znhzaa4vkmtxaeskca8hpss23ms3l</author_name><author_url>https://nostr.ae/npub1g5zswf6y48f7fy90jf3tlcuwdmjn8znhzaa4vkmtxaeskca8hpss23ms3l</author_url><provider_name>njump</provider_name><provider_url>https://nostr.ae</provider_url><html>📅 Original date posted:2019-12-17&#xA;📝 Original message:&#xA;Good morning t-bast,&#xA;&#xA;&gt; Good morning list,&#xA;&gt;&#xA;&gt; As everyone who has ever used a Lightning wallet is well aware, the onboarding process could be&#xA;&gt; made smoother. With Phoenix [1], we&#39;ve been experimenting with pay-to-open [2].&#xA;&gt;&#xA;&gt; That works well in practice and provides a great UX for newcomers, but it requires temporary trust&#xA;&gt; between the user and our node (until the funding tx confirms).&#xA;&gt;&#xA;&gt; That trust relationship appears in two places:&#xA;&gt;&#xA;&gt; a. The user releases the preimage, then we fund the channel [2]&#xA;&gt; b. The user trusts that we won&#39;t double-spend the funding transaction&#xA;&gt;&#xA;&gt; We currently need (a) because we can&#39;t ensure that the user will reveal the preimage once we&#39;ve&#xA;&gt; funded the channel.&#xA;&gt;&#xA;&gt; It&#39;s (somewhat) easy to fix that once Bitcoin supports Schnorr.&#xA;&gt; Let&#39;s assume that we&#39;re using PTLCs (where the secret is a private key) and MuSig for channel&#xA;&gt; funding transactions.&#xA;&gt; When Alice receives a PTLC to forward to Bob, if she doesn&#39;t have a channel to Bob and Bob supports&#xA;&gt; pay-to-open, she can initiate a tweaked channel opening flow. She can use tlv extensions in the&#xA;&gt; `open_channel` message to tell Bob that this channel is linked to a PTLC with point `X=x*G`.&#xA;&gt; Bob will tweak the MuSig nonce with `X` and provide Alice with a partial signature for that nonce.&#xA;&gt; When Bob then provides the adaptor signature to finalize the funding transaction, it reveals `x` to&#xA;&gt; Alice who can now fulfill the PTLC downstream.&#xA;&gt;&#xA;&gt; Note that in this simple version, Alice knows the nonce tweak beforehand. This may (or may not,&#xA;&gt; that will need to be investigated thoroughly) be a security issue.&#xA;&gt; Even if it turns out to be an issue, I&#39;m pretty sure we can find a secure protocol that will allow&#xA;&gt; this atomicity (let&#39;s just add another round of communication, that&#39;s usually how we fix broken&#xA;&gt; cryptographic protocols).&#xA;&#xA;This can be assured today with HTLC-like constructions, similar to what we use in HTLC-success / HTLC-timeout in BOLT 3.&#xA;&#xA;Channel opening *instead* goes this way:&#xA;&#xA;* Alice receives a payment request to Bob with a specific payment hash.&#xA;* Alice creates a transaction from its onchain funds, paying out to an HTLC-like construction with logic `(hash_preimage &amp;&amp; A &amp;&amp; B) || (timelock &amp;&amp; A)`.&#xA;  * Call this the pre-funding transaction.&#xA;  * Alice does **not** sign and broadcast this *yet*!&#xA;  * The timelock could reuse the same timelock as indicated in the final hop to the incoming payment.&#xA;* Alice gives the txid of the pre-funding to Bob.&#xA;* Alice and Bob create a transaction that spends the above output to the logic `A &amp;&amp; B`.&#xA;  * Call this the funding transaction.&#xA;* Alice and Bob create commitment transactions spending the above funding transaction as per usual flow, and exchange signatures, completing up to `funding_signed`.&#xA;  * Have it `push_msat` the payment amount to Bob minus the fee to open.&#xA;* Alice and Bob exchange signatures for funding transaction, spending using the hashlock branch of the pre-funding transaction HTLC.&#xA;* Alice signs and broadcasts the pre-funding transaction.&#xA;* Once the pre-funding is sufficiently confirmed as per Bob security parameter, Bob then broadcasts the funding transaction.&#xA;  * To do so, Bob has to add the preimage to the witness stack in order to make-valid the funding transaction.&#xA;* Alice sees the preimage from the broadcasted funding transaction and can now continue claiming the incoming HTLC.&#xA;&#xA;&gt;&#xA;&gt; I&#39;m more concerned about fixing (b). As long as the funding transaction is unconfirmed, there&#39;s a&#xA;&gt; risk of double-spending by the funder. I&#39;m shamelessly trying to use this mailing list&#39;s brainpower&#xA;&gt; to figure out possible solutions for that. Does someone have ideas that could help? Can we setup&#xA;&gt; the incentives so that it&#39;s never rational for the funder to double-spend?&#xA;&#xA;Above procedure probably fixes this as well?&#xA;It sets things up so that the funder cannot double-spend the funds that will eventually get into the channel after it is capable of receiving the preimage.&#xA;Funder can double-spend, but then is unable to learn the preimage and cannot steal the payment (and is indistinguishable from any other payment failure).&#xA;&#xA;The above procedure makes Alice vulnerable to Bob aborting after the pre-funding is confirmed, thus onchain fees are paid by Alice to pay for the pre-funding and the timelock branch.&#xA;This can be fixed by forcing Bob to provide funds to the pre-funding, which get returned to the channel on Bob side, and having the timelock branch be `(A &amp;&amp; B &amp;&amp; timelock)` and pre-signing a backout that returns the funds back to Alice and Bob, with Bob paying all onchain fee, but I believe the desired use-case here is when Bob has absolutely 0 millisatoshi...?&#xA;&#xA;Regards,&#xA;ZmnSCPxj</html></oembed>