Skip to content

Conversation

@jl2012
Copy link
Contributor

@jl2012 jl2012 commented Sep 2, 2016

Rebase of #4562 by @sipa

The effect of doing this would not be very obvious in normal use, but could have >10x improvement for a O(n^2) hashing attack

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/12/6/ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@jl2012 jl2012 force-pushed the sighashcache branch 2 times, most recently from 7dd93af to b895b96 Compare September 4, 2016 15:04
@jl2012
Copy link
Contributor Author

jl2012 commented Sep 5, 2016

fixed a bug in #4562. It requires 256 cache slots instead of just 6 for the common types, since the nHashType is part of the sighash so each one is unique.

Need more tests for witness txs.

@sipa
Copy link
Member

sipa commented Sep 5, 2016

Nice work with the tests so far!

@jl2012
Copy link
Contributor Author

jl2012 commented Sep 6, 2016

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #8667

@NicolasDorier
Copy link
Contributor

is it be possible to put the cache as a field of the TransactionChecker rather than as yet another parameter in CheckSig ?

@sipa
Copy link
Member

sipa commented Sep 6, 2016

@NicolasDorier I believe so, yes!

@sipa
Copy link
Member

sipa commented Sep 6, 2016

@NicolasDorier Actually, no. Not until we outlaw OP_CODESEPARATOR, as the script execution needs to be able to wipe the cache.

@NicolasDorier
Copy link
Contributor

@sipa you can add a ScriptCode field to SigHashCache, and add a check in CheckSig to use the cache only if the ScriptCode match.

@NicolasDorier
Copy link
Contributor

I hope nobody intend to outlaw OP_CODESEPARATOR, it is a nice way for a signer to sign a particular executed path without requiring multiple public key. May have potential cool things to do with it and MAST, as with MAST we can have lots of different branches.

@sipa
Copy link
Member

sipa commented Sep 6, 2016

@NicolasDorier Nice idea. Implemented in https://github.com/sipa/bitcoin/commits/sighashcache. (@jl2012: feel free to squash if you like it)

I don't understand what you're suggesting about OP_CODESEPARATOR. Perhaps we should discuss that on IRC instead.

@NicolasDorier
Copy link
Contributor

NicolasDorier commented Sep 6, 2016

Code Review ACK for https://github.com/sipa/bitcoin/commits/sighashcache (this PR + the commit removing the param to CheckSig)

However, I'm not sure it is really useful, in a case of O(n^2) hashing attack, having a 10x performance improvement for a 5 second block verification is not going to do huge difference.

@jl2012
Copy link
Contributor Author

jl2012 commented Sep 6, 2016

Squashed with @sipa 's patch

@NicolasDorier, the effect would be limited for a miner-initiated attack. However, for standard transaction, 10x could be a make or break difference

@sipa
Copy link
Member

sipa commented Sep 6, 2016

utACK 9e4cf76412e17efa8fdeb3e7626ccf25b578e036

@NicolasDorier
Copy link
Contributor

NicolasDorier commented Sep 6, 2016

@jl2012 as implemented now, the cache is per input. So how can it increase 10x for standard transaction ?
Right now it improve the case of one input with lots of checksig.

@sipa
Copy link
Member

sipa commented Sep 6, 2016

@NicolasDorier Please move back-on-forth discussions to IRC.

@NicolasDorier
Copy link
Contributor

utACK 9e4cf76

@jl2012
Copy link
Contributor Author

jl2012 commented Sep 8, 2016

Is this a target of 0.13.1?

@laanwj laanwj added this to the 0.13.1 milestone Sep 8, 2016
@jl2012
Copy link
Contributor Author

jl2012 commented Sep 19, 2016

I have an alternative implementation as ed71079 in #8756. It only reuse a sighash for a signature within CHECKMULTISIG. It is less risky as we don't need to worry about any unexpected behavior due to OP_CODESEPARATOR and FindAndDelete. Nonetheless, #8756 could provide the same level of sighash attack protection as #8654 combined with #8755.

@jl2012
Copy link
Contributor Author

jl2012 commented Sep 22, 2016

I think it would take more time to analysis this issue and figure out the best approach. I'm inclined not to include this in 0.13.1

@laanwj laanwj removed this from the 0.13.1 milestone Sep 22, 2016
jl2012 added a commit to jl2012/bitcoin that referenced this pull request Oct 27, 2016
This makes sure that SignatureHash is performed once only for each signature within a CHECKMULTISIG. Alternative to bitcoin#8654.
@jl2012
Copy link
Contributor Author

jl2012 commented Oct 29, 2016

Tests are updated with FindAndDelete tests. The earlier version (#4562) did not reset the cache after FindAndDelete and the new tests would have caught the bug.

However, the tests require the public key recovery code from https://github.com/petertodd/python-bitcoinlib , which may have copyright issues. Any suggestions?

@jonasschnelli jonasschnelli added this to the 0.14.0 milestone Dec 22, 2016
@morcos
Copy link
Contributor

morcos commented Jan 5, 2017

I'm interested in understanding the benchmark results a little bit more.

It seems there are huge speed ups in big CHECKMULTISIG transactions, but there appear to be a non-neglible slowdown in more regular transactions (the last test in the benchmark).

I'd be concerned that this code will on average be a slow down to block validation. Has it been benchmarked for typical blocks either during IBD or normal operation.

@jl2012
Copy link
Contributor Author

jl2012 commented Jan 5, 2017

@morcos: good question. I'll try to do some benchmarking in real operation

@morcos
Copy link
Contributor

morcos commented Jan 9, 2017

I did some benchmarking but did not see any noticeable performance difference either way for typical usage

@laanwj laanwj removed this from the 0.14.0 milestone Jan 12, 2017
@laanwj
Copy link
Member

laanwj commented Jan 12, 2017

Untagging this for 0.14 as discussed in the meeting

@TheBlueMatt
Copy link
Contributor

Needs rebase (though if you dont get to it early this week maybe just wait until post-15).

@kallewoof
Copy link
Contributor

@jl2012 Should this have the "up for grabs" label so someone can pick it up, in case you're busy elsewhere?

@jl2012
Copy link
Contributor Author

jl2012 commented Feb 26, 2018

@kallewoof This PR is quite risky (might introduce consensus bug), but not very helpful unless we have the following softforks: 1. limiting SIGHASH to 6 types; 2. disallow OP_CODESEPARATOR; 3. disallow FindAndDelete(). The first one is already a policy and the other two are proposed in #11423. However policy is not enough

@kallewoof
Copy link
Contributor

@jl2012 Got it! Maybe add [WIP] to it so we know not to review it until it's ready for merging.

@jl2012 jl2012 changed the title Reuse sighash computations across evaluation (rebase of #4562) [WIP] Reuse sighash computations across evaluation Mar 5, 2018
@jnewbery
Copy link
Contributor

jnewbery commented Apr 4, 2018

Recommend we close this PR for now. If the following events happen:

  1. limiting SIGHASH to 6 types;
  2. disallow OP_CODESEPARATOR;
  3. disallow FindAndDelete()

we can reopen.

Does that sound reasonable @jl2012 ?

@jl2012
Copy link
Contributor Author

jl2012 commented Apr 5, 2018

agree with @jnewbery

@jl2012 jl2012 closed this Apr 5, 2018
@Rspigler
Copy link
Contributor

Rspigler commented Nov 6, 2018

@fanquake shouldn't this and #8755 be added to 'Segwit' as well? (If this were merged, #8755 could be merged).

@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.