Research/Bitcoin Dev Archive / lightning-dev list
We don't need R-Value, how OP_CODESEPARATOR saves the day
7 messages, Mar 7 to 10, 2016. Started by Nicolas Dorier.
Nicolas Dorier (3), Fabrice Drouin (2), Joseph Poon (2)
I managed to adapt the payment channel script to use less space.
This version is winning around 32 bytes in the scriptpubkey (for the R value) as well as 70 bytes in the signature when Alice close the channel.
Alice closing the channel: http://n.bitcoin.ninja/checkscript?savedScript=51225750-f245-45b5-a86c-6ca1e87dcafb
Bob using revocation: http://n.bitcoin.ninja/checkscript?savedScript=c4d7ebaa-5a79-4c03-ab55-c499854f1e94
This amount to 100 bytes saved between the anchor transaction + commitment broadcasted.
Hi, I may have misunderstood something, but with this scheme instead of R + shachain/elkrem, then how do nodes react when old commit tx are published ? It seems that they would have to store lots of signatures ?
On 7 March 2016 at 08:28, Nicolas Dorier <nicolas.dorier at gmail.com> wrote:
Quoted text (19 lines)
> I managed to adapt the payment channel script to use less space. > > This version is winning around 32 bytes in the scriptpubkey (for the R > value) as well as 70 bytes in the signature when Alice close the channel. > > Alice closing the channel: > http://n.bitcoin.ninja/checkscript?savedScript=51225750-f245-45b5-a86c-6ca1e87dcafb > > Bob using revocation: > http://n.bitcoin.ninja/checkscript?savedScript=c4d7ebaa-5a79-4c03-ab55-c499854f1e94 > > This amount to 100 bytes saved between the anchor transaction + commitment > broadcasted. > > _______________________________________________ > Lightning-dev mailing list > Lightning-dev at lists.linuxfoundation.org > https://www.learnbitcoin.com/archive/lists/lightning-dev >
Ok, got my answer from the thread you started on deterministic R values and which I had missed :)
On 7 March 2016 at 20:09, Fabrice Drouin <fabrice.drouin at acinq.fr> wrote:
Quoted text (27 lines)
> Hi, > I may have misunderstood something, but with this scheme instead of R > + shachain/elkrem, then how do nodes react when old commit tx are > published ? It seems that they would have to store lots of signatures > ? > > > On 7 March 2016 at 08:28, Nicolas Dorier <nicolas.dorier at gmail.com> wrote: >> I managed to adapt the payment channel script to use less space. >> >> This version is winning around 32 bytes in the scriptpubkey (for the R >> value) as well as 70 bytes in the signature when Alice close the channel. >> >> Alice closing the channel: >> http://n.bitcoin.ninja/checkscript?savedScript=51225750-f245-45b5-a86c-6ca1e87dcafb >> >> Bob using revocation: >> http://n.bitcoin.ninja/checkscript?savedScript=c4d7ebaa-5a79-4c03-ab55-c499854f1e94 >> >> This amount to 100 bytes saved between the anchor transaction + commitment >> broadcasted. >> >> _______________________________________________ >> Lightning-dev mailing list >> Lightning-dev at lists.linuxfoundation.org >> https://www.learnbitcoin.com/archive/lists/lightning-dev >>
Hi Nicolas,
Yes, I do think exploring using signatures as a method of revocation is interesting! For revoking Commitments, I believe if you did disclosure of the private-key as a method of revocation, then it's possible to achieve this compactness without using OP_CODESEPARATOR.
Side note: It's necessary to disclose temporary private keys (instead of signatures) under this mechanism, since it's possible to compactly store the keys by making it derived from a tree or chain of hash functions.
A compact revocable example for Bob to broadcast could be: <PubkeyAlice> OP_CHECKSIG OP_NOTIF <CSVDelay> OP_DROP OP_CSV OP_ENDIF <PubkeyBob> OP_CHECKSIG
On the other hand, if Alice broadcasted it, her script could be: <PubkeyBob> OP_CHECKSIG OP_NOTIF <CSVDelay> OP_DROP OP_CSV OP_ENDIF <PubkeyAlice> OP_CHECKSIG
Alice successful redemption of her broadcast would be: (after one week) <AliceSig> <0>
Bob's penalty transaction on Alice's broadcast would be: <AliceSig> <BobSig>
If Alice did not broadcast the correct Commitment, Bob can take the money immediately because she disclosed her private key when creating the new Commitment transaction, so Bob has both PrivkeyBob and PrivkeyAlice. If Alice correctly broadcast the most recent Commitment, Bob does not have PrivkeyAlice so he cannot take the funds, but Alice does not have PrivkeyBob so she has to wait for the CSV delay.
If the goal is to save space, it saves a little in the timeout/non-penalty case, but the transactions are larger for penalty cases (although they may be less frequent).
It's also possible to make it just a multisig output with the child transaction spending from it pre-signed as well using nSequence, but that requires more storage and more on-chain transactions (while saving in the script output size), this design is not necessary for this particular instance if there's OP_CSV.
As a side note, OP_CODESEPARATOR may become useful if there is SIGHASH_NOINPUT inside segregated witness in the future, by being able to have one signature be able to apply towards multiple types of transactions (e.g. different redeemScript/scriptPubKey r-values or pubkeys).
Yes they do,
But I did not thought you had a way not to store one R value per commitment. If you store one R Value per commitment, then the solution with OP_CODESEPARATOR is strictly better as it saves space on blockchain.
So indeed if old commit tx are published, they need to fetch the signatures.
Nicolas,
On Tue, Mar 8, 2016 at 4:09 AM, Fabrice Drouin <fabrice.drouin at acinq.fr> wrote:
Quoted text (31 lines)
> Hi, > I may have misunderstood something, but with this scheme instead of R > + shachain/elkrem, then how do nodes react when old commit tx are > published ? It seems that they would have to store lots of signatures > ? > > > On 7 March 2016 at 08:28, Nicolas Dorier <nicolas.dorier at gmail.com> wrote: > > I managed to adapt the payment channel script to use less space. > > > > This version is winning around 32 bytes in the scriptpubkey (for the R > > value) as well as 70 bytes in the signature when Alice close the channel. > > > > Alice closing the channel: > > > http://n.bitcoin.ninja/checkscript?savedScript=51225750-f245-45b5-a86c-6ca1e87dcafb > > > > Bob using revocation: > > > http://n.bitcoin.ninja/checkscript?savedScript=c4d7ebaa-5a79-4c03-ab55-c499854f1e94 > > > > This amount to 100 bytes saved between the anchor transaction + > commitment > > broadcasted. > > > > _______________________________________________ > > Lightning-dev mailing list > > Lightning-dev at lists.linuxfoundation.org > > https://www.learnbitcoin.com/archive/lists/lightning-dev > > >
I am catching up with the latest dev of lightning. I thought you wanted SIGHASH_NOPINPUT in order to fix the problem of storage requirement.
I have not thought about using private key on HD. However, I think the index (also used for derivation) of the commitment would need to be stored in the transaction. So if Bob notice old commitment, he does not have to bruteforce what was the key he used.
I re-read slowly your post on bitcoin-dev about SIGHASH_NOINPUT, and noticed the problem it was to fix was for third party monitoring.
But that the linear storage of the channel participant was a problem already solved. I'm synching. :)
On Tue, Mar 8, 2016 at 11:56 AM, Joseph Poon <joseph at lightning.network> wrote:
Quoted text (60 lines)
> Hi Nicolas, > > Yes, I do think exploring using signatures as a method of revocation is > interesting! For revoking Commitments, I believe if you did disclosure > of the private-key as a method of revocation, then it's possible to > achieve this compactness without using OP_CODESEPARATOR. > > Side note: It's necessary to disclose temporary private keys (instead of > signatures) under this mechanism, since it's possible to compactly store > the keys by making it derived from a tree or chain of hash functions. > > A compact revocable example for Bob to broadcast could be: > <PubkeyAlice> OP_CHECKSIG > OP_NOTIF > <CSVDelay> OP_DROP OP_CSV > OP_ENDIF > <PubkeyBob> > OP_CHECKSIG > > On the other hand, if Alice broadcasted it, her script could be: > <PubkeyBob> OP_CHECKSIG > OP_NOTIF > <CSVDelay> OP_DROP OP_CSV > OP_ENDIF > <PubkeyAlice> > OP_CHECKSIG > > Alice successful redemption of her broadcast would be: > (after one week) > <AliceSig> <0> > > Bob's penalty transaction on Alice's broadcast would be: > <AliceSig> <BobSig> > > If Alice did not broadcast the correct Commitment, Bob can take the > money immediately because she disclosed her private key when creating > the new Commitment transaction, so Bob has both PrivkeyBob and > PrivkeyAlice. If Alice correctly broadcast the most recent Commitment, > Bob does not have PrivkeyAlice so he cannot take the funds, but Alice > does not have PrivkeyBob so she has to wait for the CSV delay. > > If the goal is to save space, it saves a little in the > timeout/non-penalty case, but the transactions are larger for penalty > cases (although they may be less frequent). > > It's also possible to make it just a multisig output with the child > transaction spending from it pre-signed as well using nSequence, but > that requires more storage and more on-chain transactions (while saving > in the script output size), this design is not necessary for this > particular instance if there's OP_CSV. > > As a side note, OP_CODESEPARATOR may become useful if there is > SIGHASH_NOINPUT inside segregated witness in the future, by being able > to have one signature be able to apply towards multiple types of > transactions (e.g. different redeemScript/scriptPubKey r-values or > pubkeys). > > -- > Joseph Poon >
Hi Nicolas,
On Tue, Mar 08, 2016 at 01:44:05PM +0900, Nicolas Dorier wrote:
Quoted text (6 lines)
> I am catching up with the latest dev of lightning. I thought you > wanted SIGHASH_NOPINPUT in order to fix the problem of storage > requirement. > [...] > I re-read slowly your post on bitcoin-dev about SIGHASH_NOINPUT, and > noticed the problem it was to fix was for third party monitoring.
Yes, SIGHASH_NOINPUT is for the storage requirement. I was talking about an implementation detail for using OP_CODESEPARATOR to ensure that the signature is valid for multiple types of script outputs.
As a side point, I think to clarify to the rest of the list what Nicolas has discovered for those who are skimming since I find novel/unusual use of OP_CODESEPARATOR interesting, I believe Nicolas was talking about noticing that an aspect of OP_CODESEPARATOR is you can use it to enforce branch execution. For LN, however, the script can be made compact without OP_CODESEPARATOR.
E.g. if part of the script looked like (ignore optimizations for a sec!)
<alicePubkey> #used for OP_CHECKSIG OP_IF [some kind of conditions, e.g. OP_CLTV, OP_HASH160, etc.] OP_CODESEPARATOR OP_CHECKSIG OP_ELSE [OTHER conditions, e.g. OP_CLTV, OP_HASH160, etc.] OP_CODESEPARATOR OP_CHECKSIG OP_END
In this situation, a single pubkey can enforce execution of a particular codepath. The codeseparator can enforce whether the first IF path is executed or the ELSE statement, since a signature can only be valid for one of the two paths. This is achieved since codeseperator selects which part of the script to sign, which is a very interesting result.
While this doesn't allow you do things you weren't able to before, this does offer potential space savings. It's possible to enforce code execution with slightly larger scripts without using OP_CODESEPARATOR by using two different pubkeys or by moving the conditions to be a nested OP_IF statement.
This type of construction is interesting because there can be multi-party multi-signature situations where a party only wants to sign off on particular conditions are guaranteed to be executed, especially if there is some interactive communication and out-of-band conditions for signing.