diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index 95b25b4911..04b280d5a3 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -203,6 +203,14 @@ bool CheckSignatureEncoding(const std::vector &vchSig, unsigned i if (vchSig.size() == 0) { return true; } + + bool no_hash_byte = (flags & SCRIPT_NO_SIGHASH_BYTE) == SCRIPT_NO_SIGHASH_BYTE; + std::vector vchSigCopy(vchSig.begin(), vchSig.begin() + vchSig.size()); + // Push a dummy sighash byte to pass checks + if (no_hash_byte) { + vchSigCopy.push_back(SIGHASH_ALL); + } + if ((flags & (SCRIPT_VERIFY_DERSIG | SCRIPT_VERIFY_LOW_S | SCRIPT_VERIFY_STRICTENC)) != 0 && !IsValidSignatureEncoding(vchSig)) { return set_error(serror, SCRIPT_ERR_SIG_DER); } else if ((flags & SCRIPT_VERIFY_LOW_S) != 0 && !IsLowDERSignature(vchSig, serror)) { diff --git a/src/script/interpreter.h b/src/script/interpreter.h index 276ff9a58a..e1bd63bce9 100644 --- a/src/script/interpreter.h +++ b/src/script/interpreter.h @@ -115,6 +115,10 @@ enum // Making OP_CODESEPARATOR and FindAndDelete fail any non-segwit scripts // SCRIPT_VERIFY_CONST_SCRIPTCODE = (1U << 16), + + // Signature checking assumes no sighash byte after the DER signature + // + SCRIPT_NO_SIGHASH_BYTE = (1U << 17), }; bool CheckSignatureEncoding(const std::vector &vchSig, unsigned int flags, ScriptError* serror);