-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Implement sighash cache in CHECKMULTISIG #14079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
@jl2012 Would it be possible to generate some benchmarks to quantify the performance effect? :-) |
|
Awesome! I thought we already did that! |
| The last travis run for this pull request was 253 days ago and is thus outdated. To trigger a fresh travis build, this pull request should be closed and re-opened. |
promag
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not necessary
Unless there's a performance penalty it doesn't matter? Or is there another reason to cache it?
| }; | ||
|
|
||
| bool SignatureExtractorChecker::CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const | ||
| bool SignatureExtractorChecker::CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion, uint256* sighash_copy, int* sighash_copy_type) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, unused parameters could be commented.
|
|
||
| uint256 sighash = SignatureHash(scriptCode, *txTo, nIn, nHashType, amount, sigversion, this->txdata); | ||
| uint256 sighash; | ||
| if (sighash_copy_type && sighash_copy && *sighash_copy_type == nHashType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, add braces please.
|
Agree with @promag; I would like to see benchmark results indicating whether this actually has any effects. |
|
Closing this as "Up for grabs". If anyone is interested in picking this up, as mentioned multiple times above, the best place to start is likely writing some benchmarks that would demonstrate any performance improvements. |
Currently
CHECKMULTISIGrecalculates the sighash every time it verifies a key-signature pair. It is not necessary because sighash for the samenHashTypeis always the same inside aCHECKMULTISIG. Therefore, we could reuse a sighash as long as thenHashTypeis not changed.Note that in
CHECKMULTISIG, the trimming ofscriptCode(withCODESEPARATORandFindAndDelete()) is done before the signature checking loop. So thescriptCodeis always a constant in the sameCHECKMULTISIGoperation. However, this is not guaranteed across differentCHECKSIGorCHECKMULTISIGso a cross-opcode sighash cache could not be done in the same way.