Changeset View
Changeset View
Standalone View
Standalone View
src/script/interpreter.cpp
Show First 20 Lines • Show All 936 Lines • ▼ Show 20 Lines | try { | ||||
bool fSuccess = false; | bool fSuccess = false; | ||||
if (vchSig.size()) { | if (vchSig.size()) { | ||||
valtype vchHash(32); | valtype vchHash(32); | ||||
CSHA256() | CSHA256() | ||||
.Write(vchMessage.data(), vchMessage.size()) | .Write(vchMessage.data(), vchMessage.size()) | ||||
.Finalize(vchHash.data()); | .Finalize(vchHash.data()); | ||||
fSuccess = checker.VerifySignature( | fSuccess = checker.VerifySignature( | ||||
vchSig, CPubKey(vchPubKey), uint256(vchHash)); | vchSig, CPubKey(vchPubKey), uint256(vchHash), | ||||
flags); | |||||
} | } | ||||
if (!fSuccess && (flags & SCRIPT_VERIFY_NULLFAIL) && | if (!fSuccess && (flags & SCRIPT_VERIFY_NULLFAIL) && | ||||
vchSig.size()) { | vchSig.size()) { | ||||
return set_error(serror, SCRIPT_ERR_SIG_NULLFAIL); | return set_error(serror, SCRIPT_ERR_SIG_NULLFAIL); | ||||
} | } | ||||
popstack(stack); | popstack(stack); | ||||
▲ Show 20 Lines • Show All 505 Lines • ▼ Show 20 Lines | uint256 SignatureHash(const CScript &scriptCode, const CTransaction &txTo, | ||||
// Serialize and hash | // Serialize and hash | ||||
CHashWriter ss(SER_GETHASH, 0); | CHashWriter ss(SER_GETHASH, 0); | ||||
ss << txTmp << sigHashType; | ss << txTmp << sigHashType; | ||||
return ss.GetHash(); | return ss.GetHash(); | ||||
} | } | ||||
bool BaseSignatureChecker::VerifySignature(const std::vector<uint8_t> &vchSig, | bool BaseSignatureChecker::VerifySignature(const std::vector<uint8_t> &vchSig, | ||||
const CPubKey &pubkey, | const CPubKey &pubkey, | ||||
const uint256 &sighash) const { | const uint256 &sighash, | ||||
uint32_t flags) const { | |||||
/** | |||||
* This function is memoized by sigcache.cpp. If there are dependencies on | |||||
* flags, either explicit or implicit, they should be noted in sigcache.cpp | |||||
* by making sure said flags are omitted from INVARIANT_FLAGS. | |||||
*/ | |||||
deadalnix: Remove. This is incorrect in the general case, but even if every single use of this was… | |||||
markblundebergAuthorUnsubmitted Done Inline Actionshmm, ok markblundeberg: hmm, ok | |||||
return pubkey.VerifyECDSA(sighash, vchSig); | return pubkey.VerifyECDSA(sighash, vchSig); | ||||
} | } | ||||
bool TransactionSignatureChecker::CheckSig( | bool TransactionSignatureChecker::CheckSig( | ||||
const std::vector<uint8_t> &vchSigIn, const std::vector<uint8_t> &vchPubKey, | const std::vector<uint8_t> &vchSigIn, const std::vector<uint8_t> &vchPubKey, | ||||
const CScript &scriptCode, uint32_t flags) const { | const CScript &scriptCode, uint32_t flags) const { | ||||
CPubKey pubkey(vchPubKey); | CPubKey pubkey(vchPubKey); | ||||
if (!pubkey.IsValid()) { | if (!pubkey.IsValid()) { | ||||
return false; | return false; | ||||
} | } | ||||
// Hash type is one byte tacked on to the end of the signature | // Hash type is one byte tacked on to the end of the signature | ||||
std::vector<uint8_t> vchSig(vchSigIn); | std::vector<uint8_t> vchSig(vchSigIn); | ||||
if (vchSig.empty()) { | if (vchSig.empty()) { | ||||
return false; | return false; | ||||
} | } | ||||
SigHashType sigHashType = GetHashType(vchSig); | SigHashType sigHashType = GetHashType(vchSig); | ||||
vchSig.pop_back(); | vchSig.pop_back(); | ||||
uint256 sighash = SignatureHash(scriptCode, *txTo, nIn, sigHashType, amount, | uint256 sighash = SignatureHash(scriptCode, *txTo, nIn, sigHashType, amount, | ||||
this->txdata, flags); | this->txdata, flags); | ||||
if (!VerifySignature(vchSig, pubkey, sighash)) { | if (!VerifySignature(vchSig, pubkey, sighash, flags)) { | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool TransactionSignatureChecker::CheckLockTime( | bool TransactionSignatureChecker::CheckLockTime( | ||||
const CScriptNum &nLockTime) const { | const CScriptNum &nLockTime) const { | ||||
▲ Show 20 Lines • Show All 166 Lines • Show Last 20 Lines |
Remove. This is incorrect in the general case, but even if every single use of this was memoized, adding this comment comes in direct violation of liskov's substitution principle.
https://en.wikipedia.org/wiki/Liskov_substitution_principle
It is simply not the role of this piece of code to know if it is memoized or not. It's role it to check a signature.