Research/Bitcoin Dev Archive / lightning-dev list
SIGHASH_NOINPUT in Segregated Witness
8 messages, Feb 26 to Mar 2, 2016. Started by Bryan Bishop.
Anthony Towns (3), Bryan Bishop (2), Rusty Russell (2), Joseph Poon
From: Joseph Poon via bitcoin-dev <bitcoin-dev at lists.linuxfoundation.org> Date: Thu, Feb 25, 2016 at 7:07 PM Subject: [bitcoin-dev] SIGHASH_NOINPUT in Segregated Witness To: bitcoin-dev at lists.linuxfoundation.org
As Segregated Witness will be merged soon as a solution for transaction malleability, especially with multi-party adversarial signatures, there may be an additional use case/functionality which is helpful for Lightning Network and possibly other Bitcoin use cases. This requires a new SIGHASH flag inside Segregated Witness which does not sign the input txid/index.
Segwit is very helpful in resolving malleability in pretty much every case which matters. It is especially helpful in having solid and safe defaults for standard Bitcoin payments; it's very difficult to mess up if you are writing code in conjunction with the Bitcoin RPC API.
However, it is very useful for LN if there is a certain level of outsourcibility for transactions without this 3rd party taking on onerous costs. In LN, there is a dispute resolution period established to prevent the counterparty from attesting an incorrect channel state (represented by broadcasting a timelocked transaction). In other words, if someone in a channel broadcasts an incorrect state, the output can be redeemed by a 3rd party (but this 3rd party is not a custodian, since the output goes to the other party in the channel).
Ideally, a 3rd-party can be handed a transaction which can encompass all prior states in a compact way. For currently-designed Segregated Witness transactions, this requires storing all previous signatures, which can become very costly if individuals to thousands of channel state updates per day. This is very possible, as fees are near-zero, the value in atomizing all payments to many transactions becomes viable (reducing transaction/information costs). If individuals are doing tens of thousands of transactions per day, and one presumes something like 70-bytes of data per Commitment state in the channel, it quickly becomes infeasible to watch on behalf of many channels without material costs.
This is especially necessary because it is highly desirable to make keeping track of these channels be very cheap, as it allows for more participants to be watching on one's behalf (reducing the chance of a 3rd party fail to watch). Further, it may reduce the need to notify the 3rd party for every single channel Commitment state, instead only providing the most recent one should provide sufficient information for all prior states (since the signature will apply for any type of transaction), making the only updated information the revocation secret/preimage. Without this SIGHASH flag, every single state would need to be contacted and updated with 3rd parties. With this SIGHASH flag, one could instead delegate outsourcing when one's client goes offline with a single message several hundred bytes in size, encompassing all prior states.
Of course, while running a 24/7 full-node is encouraged, I suspect many people will not want to do so at the current time, and it needs to be functional for those who elect to be connected intermittently. This requires outsourcing or watching on one's behalf.
This would be achieved using a SIGHASH flag, termed SIGHASH_NOINPUT. It does not include as part of the signature, the outpoint being spent (txid and index), nor the amount. It however, would include the spent outpoint's script as part of the signature. Note that this is just a SIGHASH flag, and the outpoints are still being included as part of the txins (if they are mutated, the new txids can be updated by the wallet without resigning). This allows for a signature to apply to anything with that pubkey (therefore pubkeys with this flag should not be reused). For safety, this only applies in SegWit transactions, as segwit provides a sufficient malleability solution, there is no incentive to improperly use this sighash flag as a roundabout way to resolve malleability.
This helps with 3rd-party outsourcing for watching the blockchain, as one can provide a signature (and the most recent hash-chain of revocation preimages), which encompasses penalty transactions for all prior states. Functionally, this allows for opt-in wildcard inputs, but wallets which do not require these transactions do not need to be concerned with this flag; since they will never be signing with this flag, they do not need to be concerned with address re-use.
I'm interested in input and in the level of receptiveness to this. If there is interest, I'll write up a draft BIP in the next couple days.
On Thu, Feb 25, 2016 at 7:07 PM, Joseph Poon wrote:
Quoted text (4 lines)
> This would be achieved using a SIGHASH flag, termed SIGHASH_NOINPUT. It > does not include as part of the signature, the outpoint being spent > (txid and index), nor the amount. It however, would include the spent > outpoint's script as part of the signature. Note that this is just a
Well if you are bothering to draft up a BIP about that SIGHASH flag, then perhaps also consider some other SIGHASH flag types as well while you are at it?
Various proposed sighash types: http://lists.linuxfoundation.org/pipermail/bitcoin-dev/2015-August/010759.html
"Build your own nHashType" proposal draft: https://github.com/scmorse/bitcoin-misc/blob/master/sighash_proposal.md
jl2012's reply: http://lists.linuxfoundation.org/pipermail/bitcoin-dev/2015-August/010779.html
petertodd's reply about OP_CODESEPARATOR linked back to this thread regarding "Build your own nHashType": http://lists.linuxfoundation.org/pipermail/bitcoin-dev/2015-April/007771.html http://lists.linuxfoundation.org/pipermail/bitcoin-dev/2015-April/007802.html http://gnusha.org/bitcoin-wizards/2014-12-09.log
((That particular thread had other replies which can be viewed here: http://lists.linuxfoundation.org/pipermail/bitcoin-dev/2015-April/thread.html ))
Also, there was a draft implementation of SIGHASH_NOINPUT: https://github.com/Roasbeef/bitcoin/commit/4b3c3f1baf7985208ceb6887261ee150ab6e3328 https://github.com/Roasbeef/btcd/commit/67830e506fa135d5239177340918cea39909e6a4
FWIW there was some concern about replay using SIGHAHS_NOINPUT or something: http://gnusha.org/bitcoin-wizards/2015-04-07.log
- Bryan http://heybryan.org/ • ••• ••• ••••
Hi Bryan,
On Thu, Feb 25, 2016 at 07:34:24PM -0600, Bryan Bishop wrote:
Quoted text (3 lines)
> Well if you are bothering to draft up a BIP about that SIGHASH flag, > then perhaps also consider some other SIGHASH flag types as well while > you are at it?
I'll take a look at those proposals when drafting the BIP. I think for LN, there is a single clean way to achieve outsourcability, but may be compatible with other arrangements. I'm somewhat averse to proposing too much flexibility before there's clear use-cases, though. However, if others do have uses/examples for other sighash flags, I'd be very interested while drafting this BIP!
Quoted text (2 lines)
> FWIW there was some concern about replay using SIGHAHS_NOINPUT or something: > http://gnusha.org/bitcoin-wizards/2015-04-07.log
Yeah, I think the nice thing about SegWit is that you resolve malleability without worrying about replay attacks in the event of key reuse. That's why I think it's only safe to do this new sighash type inside segwit itself -- if you only wanted protection against malleability you'd use segwit, and not touch this new sighash type (you'd only use the new sighash flag if you actually need its features).
On Fri, Feb 26, 2016 at 01:32:34AM +0000, Gregory Maxwell via bitcoin-dev wrote:
Quoted text (6 lines)
> On Fri, Feb 26, 2016 at 1:07 AM, Joseph Poon via bitcoin-dev > <bitcoin-dev at lists.linuxfoundation.org> wrote: > > I'm interested in input and in the level of receptiveness to this. If > > there is interest, I'll write up a draft BIP in the next couple days. > .. I think this should probably be constructed as a new segwit script type, > and not a base feature.
+1 to both
Quoted text (1 line)
> The exact construction you're thinking of there isn't clear to me...
I think the idea is that you have three transactions:
anchor:
input: whatever
output:
- single output, spendable by 2-of-2 multisig
- [possibly others as well, whatever]
commitment:
input: anchor
outputs:
1. payment to A
2. payment to B
3. HTLC to A on R1, timeout T1
4. HTLC to A on R2, timeout T2
5. HTLC to B on R3, timeout T3
...
penalty:
inputs:
all the outputs from the commitment tx
outputs:
1. 99% as payment to me
2. 1% as outsourcing fee
As long as the key I use for spending each of commitment transactions outputs is "single use" -- ie, I don't use it for other channels or anywhere else on the blockchain, then as long as the signature commits to the outputs it's safe afaics.
(You still have to send a lot of data to the place you're outsourcing chain-monitoring to; all the R1,R2,R3 and T1,T2,T3 values are needed in order to reconstruct the redeem scripts)
Quoted text (3 lines)
> one thing that comes to mind is that I think it is imperative that we > do not deploy a without-inputs SIGHASH flag without also deploying at > least a fee-committing sighash-all.
If the fee for commitment transactions changes regularly (eg, a new commitment transaction is generated every few seconds/minutes, and the fee is chosen based on whatever estimatefee returns), I think this would cause problems -- you couldn't use a single signature to cover every revoked commitment, you'd need one for each different fee level that you'd used for the lifetime of the channel. Actually, the size of the commitment transaction will differ anyway depending on how many HTLCs are open, so even if estimatefee didn't change, the fee would still differ. So I think commiting to a fee isn't workable for the lightning use case...
Quoted text (6 lines)
> When you do write a BIP for this its imperative that the vulnerability > to replay is called out in bold blinking flaming text, along with the > necessary description of how to use it safely. The fact that without > input commitments transactions are replayable is highly surprising to > many developers... Personally, I'd even go so far as to name the flag > SIGHASH_REPLAY_VULNERABLE. :)
+1, though I'm not sure it's so much "vulnerable" to replay as it is "explicitly designed" to be replayable...
Cheers, aj
Joseph Poon via bitcoin-dev <bitcoin-dev at lists.linuxfoundation.org> writes:
Quoted text (5 lines)
> Ideally, a 3rd-party can be handed a transaction which can encompass all > prior states in a compact way. For currently-designed Segregated Witness > transactions, this requires storing all previous signatures, which can > become very costly if individuals to thousands of channel state updates > per day.
AFAICT we need more than this. Or are you using something other than the deployable lightning commit tx style?
If each HTLC output is a p2sh[1], you need the timeout and rhash for each one to build the script to redeem it. In practice, there's not much difference between sending a watcher a tx for every commit tx and sending it information for every new HTLC (roughly a factor of 2).
So we also need to put more in the scriptPubKey for this to work; either the entire redeemscript, or possibly some kind of multiple-choice P2SH where any one of the hashes will redeem the payment.
Cheers, Rusty. [1] eg. from https://github.com/ElementsProject/lightning/blob/master/doc/deployable-lightning.pdf OP_HASH160 OP_DUP # Replace top element with two copies of its hash <R-HASH> OP_EQUAL # Test if they supplied the HTLC R value OP_SWAP <COMMIT-REVOCATION-HASH> OP_EQUAL OP_ADD # Or the commitment revocation hash OP_IF # If any hash matched. <KEY-B> # Pay to B. OP_ELSE # Must be A, after HTLC has timed out. <HTLC-TIMEOUT> OP_CHECKLOCKTIMEVERIFY Ensure (absolute) time has passed. <DELAY> OP_CHECKSEQUENCEVERIFY # Delay gives B enough time to use revocation if it has it. OP_2DROP # Drop the delay and htlc-timeout from the stack. <KEY-A> # Pay to A. OP_ENDIF OP_CHECKSIG # Verify A or B's signature is correct.
Cheers, Rusty.
bitcoin-dev dropped, just lightning-dev
On Mon, Feb 29, 2016 at 10:55:53AM +1030, Rusty Russell wrote:
Quoted text (4 lines)
> If each HTLC output is a p2sh[1], you need the timeout and rhash for > each one to build the script to redeem it. In practice, there's not > much difference between sending a watcher a tx for every commit tx and > sending it information for every new HTLC (roughly a factor of 2).
There's a bigger saving if you've got a very active channel with comparatively long lived HTLCs. With pre-signed transactions you have to send:
tx 1234: input: anchor outputs: Alice balance ; Bob balance ; HTLC 1 ; HTLC 2 ; HTLC 3 ; ...
tx 1235: (HTLC 2 cleared) input: anchor outputs: Alice balance ; Bob balance ; HTLC 1 ; HTLC 3 ; HTLC 4 ; ...
tx 1235: (HTLC 4 cleared) input: anchor outputs: Alice balance ; Bob balance ; HTLC 1 ; HTLC 3 ; HTLC 5 ; ...
...
So if you do, say 30 HTLCs per minute, but each HTLC lasts for 20 seconds, then each HTLC appears in ~10 transactions, and you've correspondingly got to supply 10 signatures to your outsourced claimant for each HTLC you deal with. Comparatively, you only have to supply the R/timeout values once per HTLC.
With SIGHASH_NOINPUT you'd still have to send all the R/timeout values for each HTLC, but you'd only need to send a single signature for the channel.
Quoted text (3 lines)
> So we also need to put more in the scriptPubKey for this to work; either > the entire redeemscript, or possibly some kind of multiple-choice P2SH > where any one of the hashes will redeem the payment.
We discussed how to recover the timeout/R values recoverable last year fwiw, see the thread surrounding:
https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2015/commitment-update-steps#m-71c71b4a
I don't think there's a big problem with sending that info to a third party who's doing transaction reclaiming; it might hurt privacy a bit.
Note that with segwit, having a visible scriptPubKey so that R is trivially obvious isn't even possible anymore...
(If by "multiple-choice p2sh" you mean merkelized abstract syntax trees that would let you exchange 20+4 / 32+4 bytes of R+timeout for 32 bytes of a merkle path, which would be an improvement, but not huge. Otherwise I think you'd have to have a new double-length script hash type; which might not be friendly to UTXO? Though maybe two 160 bit hashes wouldn't be out of the question, at 40 bytes versus 32 or 64?)
Cheers, aj
Anthony Towns <aj at erisian.com.au> writes:
Quoted text (11 lines)
> bitcoin-dev dropped, just lightning-dev > > On Mon, Feb 29, 2016 at 10:55:53AM +1030, Rusty Russell wrote: >> If each HTLC output is a p2sh[1], you need the timeout and rhash for >> each one to build the script to redeem it. In practice, there's not >> much difference between sending a watcher a tx for every commit tx and >> sending it information for every new HTLC (roughly a factor of 2). > > There's a bigger saving if you've got a very active channel with > comparatively long lived HTLCs. With pre-signed transactions you have > to send:
Yes, with SIGHASH_NOINPUT you only need to send timeout/rval per new HTLC, plus new revocation preimage per new commit tx. Assuming no batching, so every second new commit tx adds a new HTLC, that's (4 + 32) / 2 + 32 = 50 bytes per commit tx.
Without SIGHASH_NOINPUT, add 64 bytes per commit tx output (2+<num-htlcs>), plus you have to generate those signatures. That's probably going to be less than 1 TCP packet, though.
I'm not convinced it's qualitatively different.
Quoted text (11 lines)
>> So we also need to put more in the scriptPubKey for this to work; either >> the entire redeemscript, or possibly some kind of multiple-choice P2SH >> where any one of the hashes will redeem the payment. > > We discussed how to recover the timeout/R values recoverable last > year fwiw, see the thread surrounding: > > https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2015/commitment-update-steps#m-71c71b4a > > I don't think there's a big problem with sending that info to a third > party who's doing transaction reclaiming; it might hurt privacy a bit.
Thanks for the reminder, re-reading... the result was that all the clever tricks don't win much; you can avoid sending/storing the 4 byte timeout.
Quoted text (9 lines)
> Note that with segwit, having a visible scriptPubKey so that R is > trivially obvious isn't even possible anymore... > > (If by "multiple-choice p2sh" you mean merkelized abstract syntax trees > that would let you exchange 20+4 / 32+4 bytes of R+timeout for 32 bytes > of a merkle path, which would be an improvement, but not huge. Otherwise > I think you'd have to have a new double-length script hash type; which > might not be friendly to UTXO? Though maybe two 160 bit hashes wouldn't > be out of the question, at 40 bytes versus 32 or 64?)
No, MAST doesn't do it for you, since you still need the hash of the unknown part. We'd need a "script is one of these hashes" form, which as you point out, bloats the UTXO set.
So not likely to be acceptable until lightning is the main bitcoin user.
Cheers, Rusty.
On Wed, Mar 02, 2016 at 11:14:51AM +1030, Rusty Russell wrote:
Quoted text (4 lines)
> Yes, with SIGHASH_NOINPUT you only need to send timeout/rval per new > HTLC, plus new revocation preimage per new commit tx. Assuming no > batching, so every second new commit tx adds a new HTLC, that's (4 + 32) > / 2 + 32 = 50 bytes per commit tx.
Assuming "batching" refers to combining multiple changes in a single commitment update, yeah. (I was thinking batching multiple commitment updates in a single packet when updating your blockchain contracter)
Quoted text (4 lines)
> Without SIGHASH_NOINPUT, add 64 bytes per commit tx output > (2+<num-htlcs>), plus you have to generate those signatures. That's > probably going to be less than 1 TCP packet, though. > I'm not convinced it's qualitatively different.
You're adding 70 bytes of signature data for every HTLC for every commitment it appears in, all of which have to be stored until the channel's closed. That's a 70% increase in storage requirements.
As it turns out, I'm confused as to what size a "TCP packet" actually is these days; is it 65kB or 1500B or somewhere in between? 1500 bytes only gives you about 14 HTLCs open on a channel simultaneously.
But maybe anyone doing high volume/rate (ie, forwarding other people's transactions, or doing many transactions per minute) should just run their own bitcoin node anyway. For low volume channels where you only do five transactions an hour, every hour, a whole six months of full transactions is only 21MB.
Yeah; I think that persuades me: "end users" can outsource just by generating a new payment tx and sending that off; high volume users can run a bitcoin node themselves and only do the signatures if/when someone actually cheats, so SIGHASH_NOINPUT isn't very useful in either case.
That only works because I don't think people running lightning on their phone will be forwarding many transactions though :)
Quoted text (5 lines)
> > I don't think there's a big problem with sending that info to a third > > party who's doing transaction reclaiming; it might hurt privacy a bit. > Thanks for the reminder, re-reading... the result was that all the > clever tricks don't win much; you can avoid sending/storing the 4 byte > timeout.
You can avoid sending the 4 byte commitment index (ie, what you need to recover your shachain seed) by encoding that in the commitment transaction's locktime, but you still need to store/send the HTLC timeouts aiui.
Quoted text (8 lines)
> > (If by "multiple-choice p2sh" you mean merkelized abstract syntax trees > > that would let you exchange 20+4 / 32+4 bytes of R+timeout for 32 bytes > > of a merkle path, which would be an improvement, but not huge. Otherwise > > I think you'd have to have a new double-length script hash type; which > > might not be friendly to UTXO? Though maybe two 160 bit hashes wouldn't > > be out of the question, at 40 bytes versus 32 or 64?) > No, MAST doesn't do it for you, since you still need the hash of the > unknown part.
Yeah, MAST just lets you trade the 32+4 bytes of R+timeout for 32 bytes of unknown-AST-hash.
Quoted text (3 lines)
> We'd need a "script is one of these hashes" form, which > as you point out, bloats the UTXO set. > So not likely to be acceptable until lightning is the main bitcoin user.
Yeah. Of course, an upside is it wouldn't bloat the UTXO set for very long -- lightning transactions should get spent pretty quickly, in case the other side's CTLV timeout expires.
Cheers, aj