<oembed><type>rich</type><version>1.0</version><author_name>npub1aslmpzentw224n3s6yccru4dq2qdlx7rfudfnqevfck637cjt6esswfqmx</author_name><author_url>https://nostr.ae/npub1aslmpzentw224n3s6yccru4dq2qdlx7rfudfnqevfck637cjt6esswfqmx</author_url><provider_name>njump</provider_name><provider_url>https://nostr.ae</provider_url><html>📅 Original date posted:2021-09-21&#xA;📝 Original message:&#xA;Problem&#xA;&#xA;One of the qualities of lightning is that it can provide light-weight,&#xA;no-login payments with minimal friction. Games, paywalls, podcasts, etc can&#xA;immediately present a QR code that is ready for scan and pay.&#xA;&#xA;Optimistically presenting payment requests does lead to many of those&#xA;payment requests going unused. A user visits a news site and decides not to&#xA;buy the article. The conventional approach is to create a lightning invoice&#xA;on a node and store the invoice together with order details in a database.&#xA;If the order then goes unfulfilled, cleaning processes remove the data from&#xA;the node and database again.&#xA;&#xA;The problem with this setup is that it needs protection against unbounded&#xA;generation of payment requests. There are solutions for that such as rate&#xA;limiting, but wouldn&#39;t it be nice if invoices can be generated without the&#xA;need to keep any state at all?&#xA;&#xA;Stateless invoices&#xA;&#xA;What would happen if a lightning invoice is only generated and stored&#xA;nowhere on the recipient side? To the user, it won&#39;t make a difference.&#xA;They would still scan and pay the invoice. When the payment arrives at the&#xA;recipient though, two problems arise:&#xA;&#xA;1. Recipient doesn&#39;t know whom or what the payment is for.&#xA;&#xA;This can be solved by attaching additional custom tlv records to the htlc.&#xA;On the wire, this is all arranged for. The only missing piece is the&#xA;ability to specify additional data for that custom tlv record in a bolt11&#xA;invoice. One way would be to define a new tagged field for this in which&#xA;the recipient can encode the order details.&#xA;&#xA;An alternative is to use the existing invoice description field and simply&#xA;always pass that along with the htlc as a custom tlv record.&#xA;&#xA;A second alternative that already works today is to use part (for example&#xA;16 out of 32 bytes) of the payment_secret (aka payment address) to encode&#xA;the order details in. This assumes that the secret is still secret enough&#xA;with reduced entropy. Also there may not be enough space for every&#xA;application.&#xA;&#xA;2. Recipient doesn&#39;t know the preimage that is needed to settle the htlc(s).&#xA;&#xA;One option is to use a keysend payment or AMP payment. In that case, the&#xA;sender includes the preimage with the htlc. Unfortunately this doesn&#39;t&#xA;provide the sender with a proof of payment that they&#39;d get with a regular&#xA;lightning payment.&#xA;&#xA;An alternative solution is to use a deterministic preimage based on a&#xA;(recipient node key-derived) secret, the payment secret and other relevant&#xA;properties. This allows the recipient to derive the same preimage twice:&#xA;Once when the lightning invoice is generated and again when a payment&#xA;arrives.&#xA;&#xA;It could be something like this:&#xA;&#xA;payment_secret = random&#xA;preimage = H(node_secret | payment_secret | payment_amount |&#xA;encoded_order_details)&#xA;invoice_hash = H(preimage)&#xA;&#xA;The sender sends an htlc locked to invoice_hash for payment_amount and&#xA;passes along payment_secret and encoded_order_details in a custom tlv&#xA;record.&#xA;&#xA;When the recipient receives the htlc, they reconstruct the preimage&#xA;according to the formula above. At this point, all data is available to do&#xA;so. When H(preimage) indeed matches the htlc hash, they can settle the&#xA;payment knowing that this is an order that they committed to earlier.&#xA;Settling could be implemented as a just-in-time inserted invoice to keep&#xA;the diff small.&#xA;&#xA;The preimage is returned to the sender and serves as a proof of payment.&#xA;&#xA;Resilience&#xA;&#xA;To me it seems that stateless invoices can be a relatively simple way to&#xA;improve the resiliency of systems that deal with lightning invoices.&#xA;Unlimited amounts of invoices can be generated without worrying about&#xA;storage or memory, no matter if the requests are due to popularity of a&#xA;service or a deliberate dos attack.&#xA;&#xA;Interested to hear your thoughts.&#xA;-------------- next part --------------&#xA;An HTML attachment was scrubbed...&#xA;URL: &lt;http://lists.linuxfoundation.org/pipermail/lightning-dev/attachments/20210921/788f449b/attachment-0001.html&gt;</html></oembed>