Skip to content

Conversation

@jl2012
Copy link
Contributor

@jl2012 jl2012 commented Aug 27, 2018

Currently CHECKMULTISIG recalculates the sighash every time it verifies a key-signature pair. It is not necessary because sighash for the same nHashType is always the same inside a CHECKMULTISIG. Therefore, we could reuse a sighash as long as the nHashType is not changed.

Note that in CHECKMULTISIG, the trimming of scriptCode (with CODESEPARATOR and FindAndDelete()) is done before the signature checking loop. So the scriptCode is always a constant in the same CHECKMULTISIG operation. However, this is not guaranteed across different CHECKSIG or CHECKMULTISIG so a cross-opcode sighash cache could not be done in the same way.

@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 27, 2018

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #13360 ([Policy] Reject SIGHASH_SINGLE with output out of bound by jl2012)
  • #13266 ([moveonly] privatize SignatureExtractorChecker by Empact)

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.

@practicalswift
Copy link
Contributor

@jl2012 Would it be possible to generate some benchmarks to quantify the performance effect? :-)

@gmaxwell
Copy link
Contributor

Awesome! I thought we already did that!

@DrahtBot
Copy link
Contributor

DrahtBot commented May 7, 2019

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.

Copy link
Contributor

@promag promag left a 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
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, add braces please.

@kallewoof
Copy link
Contributor

Agree with @promag; I would like to see benchmark results indicating whether this actually has any effects.

@fanquake
Copy link
Member

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.

@fanquake fanquake closed this Aug 14, 2019
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 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.

7 participants