mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-02 15:32:34 +02:00
Merge #18422: [consensus] MOVEONLY: Move single-sig checking EvalScript code to EvalChecksig
14e8cf974a
[consensus] MOVEONLY: Move single-sig checking EvalScript code to EvalChecksig (Pieter Wuille) Pull request description: This is another small refactor pulled out of the Schnorr/Taproot PR #17977. This is in preparation for adding different signature verification rules, specifically tapscript (BIP 342), which interprets opcode 0xac and 0xad as Schnorr signature verifications. ACKs for top commit: sipa: ACK14e8cf974a
, verified move-only. MarcoFalke: ACK14e8cf974a
, reviewed with "git show14e8cf974a
--color-moved=dimmed-zebra --color-moved-ws=ignore-all-space -W" 👆 fjahr: Code-review ACK14e8cf974a
, verified that it's move-only. instagibbs: code review ACK14e8cf974a
, verified move-only theStack: Code-Review ACK14e8cf974a
jonatack: ACK14e8cf974a
Tree-SHA512: af2efce9ae39d5ec01db5b9ef0ff383fe252ef5f33b3483927308ae17d91a619266cb45951f32ea1ce54807a4c0f052bcdefb47e244465d3a726393221c227b1
This commit is contained in:
commit
a9213bbe75
@ -342,6 +342,35 @@ public:
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Helper for OP_CHECKSIG and OP_CHECKSIGVERIFY
|
||||||
|
*
|
||||||
|
* A return value of false means the script fails entirely. When true is returned, the
|
||||||
|
* fSuccess variable indicates whether the signature check itself succeeded.
|
||||||
|
*/
|
||||||
|
static bool EvalChecksig(const valtype& vchSig, const valtype& vchPubKey, CScript::const_iterator pbegincodehash, CScript::const_iterator pend, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptError* serror, bool& fSuccess)
|
||||||
|
{
|
||||||
|
// Subset of script starting at the most recent codeseparator
|
||||||
|
CScript scriptCode(pbegincodehash, pend);
|
||||||
|
|
||||||
|
// Drop the signature in pre-segwit scripts but not segwit scripts
|
||||||
|
if (sigversion == SigVersion::BASE) {
|
||||||
|
int found = FindAndDelete(scriptCode, CScript() << vchSig);
|
||||||
|
if (found > 0 && (flags & SCRIPT_VERIFY_CONST_SCRIPTCODE))
|
||||||
|
return set_error(serror, SCRIPT_ERR_SIG_FINDANDDELETE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!CheckSignatureEncoding(vchSig, flags, serror) || !CheckPubKeyEncoding(vchPubKey, flags, sigversion, serror)) {
|
||||||
|
//serror is set
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
fSuccess = checker.CheckSig(vchSig, vchPubKey, scriptCode, sigversion);
|
||||||
|
|
||||||
|
if (!fSuccess && (flags & SCRIPT_VERIFY_NULLFAIL) && vchSig.size())
|
||||||
|
return set_error(serror, SCRIPT_ERR_SIG_NULLFAIL);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptError* serror)
|
bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptError* serror)
|
||||||
{
|
{
|
||||||
static const CScriptNum bnZero(0);
|
static const CScriptNum bnZero(0);
|
||||||
@ -985,25 +1014,8 @@ bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript&
|
|||||||
valtype& vchSig = stacktop(-2);
|
valtype& vchSig = stacktop(-2);
|
||||||
valtype& vchPubKey = stacktop(-1);
|
valtype& vchPubKey = stacktop(-1);
|
||||||
|
|
||||||
// Subset of script starting at the most recent codeseparator
|
bool fSuccess = true;
|
||||||
CScript scriptCode(pbegincodehash, pend);
|
if (!EvalChecksig(vchSig, vchPubKey, pbegincodehash, pend, flags, checker, sigversion, serror, fSuccess)) return false;
|
||||||
|
|
||||||
// Drop the signature in pre-segwit scripts but not segwit scripts
|
|
||||||
if (sigversion == SigVersion::BASE) {
|
|
||||||
int found = FindAndDelete(scriptCode, CScript() << vchSig);
|
|
||||||
if (found > 0 && (flags & SCRIPT_VERIFY_CONST_SCRIPTCODE))
|
|
||||||
return set_error(serror, SCRIPT_ERR_SIG_FINDANDDELETE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!CheckSignatureEncoding(vchSig, flags, serror) || !CheckPubKeyEncoding(vchPubKey, flags, sigversion, serror)) {
|
|
||||||
//serror is set
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bool fSuccess = checker.CheckSig(vchSig, vchPubKey, scriptCode, sigversion);
|
|
||||||
|
|
||||||
if (!fSuccess && (flags & SCRIPT_VERIFY_NULLFAIL) && vchSig.size())
|
|
||||||
return set_error(serror, SCRIPT_ERR_SIG_NULLFAIL);
|
|
||||||
|
|
||||||
popstack(stack);
|
popstack(stack);
|
||||||
popstack(stack);
|
popstack(stack);
|
||||||
stack.push_back(fSuccess ? vchTrue : vchFalse);
|
stack.push_back(fSuccess ? vchTrue : vchFalse);
|
||||||
|
Loading…
Reference in New Issue
Block a user