<oembed><type>rich</type><version>1.0</version><author_name>npub10f96gqrsu4qpygfgvuvzce47aavjvql703egfde0l2hua8dzpszs67ej47</author_name><author_url>https://nostr.ae/npub10f96gqrsu4qpygfgvuvzce47aavjvql703egfde0l2hua8dzpszs67ej47</author_url><provider_name>njump</provider_name><provider_url>https://nostr.ae</provider_url><html>📅 Original date posted:2023-08-14&#xA;🗒️ Summary of this message: Proposal for resumable Lightning channels using OP_CHECKSIGFROMSTACK. Allows for backup of channel state and fraud proof. Suited for private channels with Lightning service providers.&#xA;📝 Original message:&#xA;Hello list,&#xA;&#xA;Here is an idea to make lightning channels resumable from wallet seed.&#xA;I have not implemented it yet, and there might be issues I am not&#xA;seeing. Thus, I would be grateful for feedback.&#xA;&#xA;Thanks to SomberNight and Peter Todd for reviewing earlier versions of&#xA;this proposal.&#xA;&#xA;Thomas&#xA;&#xA;&#xA;-----------------------------------------------&#xA;&#xA;Resumable channels using OP_CHECKSIGFROMSTACK&#xA;=============================================&#xA;&#xA;&#xA;In order to resume the activity of a Lightning channel, one needs a&#xA;backup that contains all the information about the current channel&#xA;state. The need to perform channel backups has plagued user&#xA;experience, with many implementations reverting to static backups,&#xA;which can be used to recover funds, but not to resume channel&#xA;operations.&#xA;&#xA;Asking your channel counterparty to store your channel state has the&#xA;advantage to make backup operations atomic. However, there is no&#xA;guarantee that this is safe. Indeed, if the other party suspects that&#xA;you have lost your state (for example, because you have been offline&#xA;for a long time, or if they can see that you requested blockchain&#xA;information following a certain pattern), they can try to send you a&#xA;revoked state, and there is no way to punish them for doing that.&#xA;&#xA;Here is a proposal for a new type of channel funding transaction,&#xA;where the redeem script has an additional spending path, that accepts&#xA;a fraud proof: a proof that the channel counterparty has lied about&#xA;the current state. This proposal requires two opcodes that are&#xA;currently not available in Bitcoin: OP_CAT and OP_CHECKSIGFROMSTACK.&#xA;&#xA;Roles are asymmetric in this channel: Alice is a client, and Bob is a&#xA;server, who stores Alice&#39;s state. Thus, this proposal is mostly suited&#xA;for private channels with Lightning service providers. During channel&#xA;reestablishment, Bob will send her latest state to Alice, using an&#xA;extra field in the channel_reestablish message. Since Alice cannot&#xA;punish Bob if she has lost her state, she must not let Bob learn&#xA;whether she still has her state. Thus, Alice will never send&#xA;channel_reestablish first.&#xA;&#xA;This proposal assumes that Alice and Bob each have a clock, and that&#xA;these clocks do not drift too much relative to each other. The channel&#xA;may become unusable if clocks differ too much, as discussed below.&#xA;&#xA;&#xA;Simplified description&#xA;----------------------&#xA;&#xA;The *state* of the channel refers to everything Alice needs in order&#xA;to resume channel operations. With every new commitment, Alice sends&#xA;her current state, with her signature of that state:&#xA;&#xA;  - if Alice sends commitment_signed, the state and signature are&#xA;    included in that message.&#xA;&#xA;  - if Alice receives commitment_signed, the state and signature will&#xA;    be included in the next revoke_and_ack sent by Alice.&#xA;&#xA;With every new commitment, Bob sends a signed tuple (ctn, timestamp),&#xA;where ctn is the current commitment number (for the moment, forget&#xA;about the distinction between local and remote ctns), and timestamp is&#xA;the current time for Bob.&#xA;&#xA;  - if Bob sends commitment_signed, the signed tuple is included in&#xA;    that message.&#xA;    &#xA;  - if Bob receives commitment_signed, the signed tuple will be&#xA;    included in the next revoke_and_ack sent by Bob.&#xA;&#xA;The private key used by Bob to sign the tuples is constant over the&#xA;lifetime of the channel, and it must not be reused in other&#xA;channels. The corresponding public key will be used in the fraud proof&#xA;spending path of the redeem script.&#xA;&#xA;Alice verifies Bob&#39;s signature. She also checks that the received&#xA;timestamps are reasonable (see below) and strictly monotonic.&#xA;&#xA;With every channel_reestablish message, Bob will send two extra fields:&#xA;  - (ctn, timestamp, bob_signature)&#xA;  - (alice_state, alice_signature).&#xA;&#xA;Alice verifies that the state she received was signed by her, and that&#xA;the (ctn, timestamp) tuple was signed by Bob. She also checks that the&#xA;timestamp is reasonable.&#xA;&#xA;Fraud Proofs&#xA;------------&#xA;&#xA;Let us assume that Bob tries to send a revoked state to Alice in&#xA;channel_reestablish. The channel_reestablish received by Alice&#xA;contains a signed tuple (ctn1, t1), with t1 current timestamp.&#xA;&#xA;However, another signed tuple (ctn2, t2) has been received in the&#xA;past, with ctn1 &lt; ctn2 and t1 &gt; t2.&#xA;&#xA;If Alice has not lost her state, she will now hold two signed tuples&#xA;(ctn1, t1) and (ctn2, t2), that satisfy ctn1 &lt; ctn2 and t1 &gt; t2.&#xA;&#xA;This constitutes a fraud proof. With OP_CAT and OP_CHECKSIGFROMSTACK,&#xA;we can build a script that verifies the fraud proof, and allows Alice&#xA;to unilaterally spend the channel funding output.&#xA;&#xA;Here is an example of such a script:&#xA;&#xA;witness:&#xA;[&#xA;  alice_signature(transaction)&#xA;  bob_signature((ctn1,timestamp1))&#xA;  ctn1&#xA;  timestamp1&#xA;  bob_signature((ctn2,timestamp2))&#xA;  ctn2&#xA;  timestamp2&#xA;]&#xA;&#xA;witness_script:&#xA;  OP_PICK 1&#xA;  OP_PICK 4&#xA;  OP_LESSTHAN                 # verify ctn1 &lt; ctn2&#xA;  OP_VERIFY&#xA;  OP_PICK 0&#xA;  OP_PICK 3&#xA;  OP_GREATERTHANOREQUAL       # verify timestamp1 &gt;= timestamp2&#xA;  OP_VERIFY&#xA;  # check signatures&#xA;  OP_CAT&#xA;  OP_PUSHDATA bob_pubkey      # we may use Bob&#39;s funding_pubkey&#xA;  OP_CHECKSIGFROMSTACK&#xA;  OP_VERIFY&#xA;  OP_CAT&#xA;  OP_PUSHDATA bob_pubkey&#xA;  OP_CHECKSIGFROMSTACK&#xA;  OP_VERIFY&#xA;  OP_PUSHDATA alice_pubkey    # we may use Alice&#39;s funding_pubkey&#xA;  OP_CHECKSIGVERIFY&#xA;&#xA;&#xA;In order to keep things simple, a few details have been omitted in the&#xA;description:&#xA;&#xA;  - Bob actually needs to send both the local and the remote ctns in&#xA;    his signed tuples. A pair of tuples is a fraud proof if the order&#xA;    is violated for either local or remote ctns. Thus, the actual&#xA;    script will be more complex than what has been drafted above.&#xA;&#xA;  - Integers pushed on the Bitcoin stack are maximum 4 bytes (31 bits +&#xA;    1 bit for the sign). Since commitment numbers are 48 bits long,&#xA;    they will need to be split into two integers. Timestamps might&#xA;    require a similar decomposition. This adds further complexity to&#xA;    the redeem script.&#xA;&#xA;  - Note that Bob must strictly increase his timestamp on each&#xA;    ctn. This puts a lower bound on the precision used for timestamps.&#xA;&#xA;&#xA;Reasonable Timestamps&#xA;---------------------&#xA;&#xA;Since Alice and Bob do not have the same clock, Bob may legitimately&#xA;send a timestamp that is in Alice&#39;s past or future. Every time Alice&#xA;receives a timestamp from Bob, she compares it to her current time.&#xA;&#xA;  - If Alice receives a timestamp that is in her future, instead of&#xA;    closing the channel, she may wait it out before she accepts to&#xA;    resume operations.&#xA;&#xA;  - If Alice receives a timestamp that is too far in her past, she&#xA;    should disconnect. Indeed, Bob may be sending an old state and&#xA;    replaying old timestamps, which is not punishable. In that case,&#xA;    Alice should not automatically force close the channel, because she&#xA;    can only do that if she has not lost her state; if force-closing&#xA;    was automatic, not force-closing would reveal to Bob that she&#xA;    has lost her state.&#xA;&#xA;A delay needs to be tolerated by Alice, because Bob does not have the&#xA;same clock; that delay should be chosen so that it is always smaller&#xA;than the interval between two sessions.&#xA;&#xA;&#xA;Saving Bandwidth&#xA;----------------&#xA;&#xA;Alice&#39;s channel state does not need to be sent with every commitment,&#xA;if it is made of information that is known by both parties. In that&#xA;case, it is sufficient for Alice to send her signature of the current&#xA;state. Both Alice and Bob must be able to serialize the state, so that&#xA;Alice can verify her own signature against a serialization of the&#xA;state created by Bob. The state only needs to be sent by Bob once, in&#xA;channel_reestablish.&#xA;&#xA;For this to work, the channel state cannot include information that is&#xA;private to Alice. If the private keys used by Alice in the channel are&#xA;derived deterministically from her wallet seed, they do not need to be&#xA;part of the state. Alternatively, private keys may be included in an&#xA;encrypted blob that is included in the state. Since that encrypted&#xA;blob is constant, it only needs to be sent once by Alice, during the&#xA;channel opening negotiation. Bob will save it and add it to the state&#xA;sent in channel_reestablish.&#xA;&#xA;In addition, the state must not include any payment_hash preimage&#xA;known by Alice; thus, Alice will have to fail incoming payments for&#xA;those preimages, if she has lost her state.&#xA;&#xA;The channel state should include the compact storage of per-commitment&#xA;secrets sent by Bob.&#xA;&#xA;&#xA;Concluding remarks&#xA;------------------&#xA;&#xA;  - Obviously, this proposal assumes that Alice remembers with whom she&#xA;    has an open channel.&#xA;&#xA;  - Alice may restore her wallet from seed on a new device, while the&#xA;    initial wallet is still active. In that case, Alice must stop using&#xA;    the channels on her old device. Thus, Alice should disconnect if&#xA;    she has not lost her state and receives a state with a ctn that is&#xA;    in her future. This ensures that only one device uses the channels.&#xA;&#xA;  - Without waiting for OP_CHECKSIGFROMSTACK to be available in&#xA;    Bitcoin, it would be possible for Bob to lockup funds on another&#xA;    blockchain such as Liquid. It is also possible to create fraud&#xA;    proofs that are not used in a redeem script, but that are tied to&#xA;    Bob&#39;s public identity and reputation. In that case, Bob should sign&#xA;    with his node pubkey, and fraud proofs will need to include a short&#xA;    channel id.</html></oembed>