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