diff --git a/src/core_write.cpp b/src/core_write.cpp --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -117,7 +117,7 @@ // Multisig scripts due to the restrictions on the pubkey // formats (see IsCompressedOrUncompressedPubKey) being // incongruous with the checks in - // CheckTransactionSignatureEncoding. + // CheckTransactionECDSASignatureEncoding. uint32_t flags = SCRIPT_VERIFY_STRICTENC; if (vch.back() & SIGHASH_FORKID) { // If the transaction is using SIGHASH_FORKID, we need @@ -125,8 +125,8 @@ // TODO: Remove after the Hard Fork. flags |= SCRIPT_ENABLE_SIGHASH_FORKID; } - if (CheckTransactionSignatureEncoding(vch, flags, - nullptr)) { + if (CheckTransactionECDSASignatureEncoding(vch, flags, + nullptr)) { const uint8_t chSigHashType = vch.back(); if (mapSigHashTypes.count(chSigHashType)) { strSigHashDecode = diff --git a/src/pubkey.h b/src/pubkey.h --- a/src/pubkey.h +++ b/src/pubkey.h @@ -124,7 +124,7 @@ /* * Check syntactic correctness. * - * Note that this is consensus critical as CheckSig() calls it! + * Note that this is consensus critical as CheckSigECDSA() calls it! */ bool IsValid() const { return size() > 0; } diff --git a/src/script/interpreter.h b/src/script/interpreter.h --- a/src/script/interpreter.h +++ b/src/script/interpreter.h @@ -29,13 +29,14 @@ class BaseSignatureChecker { public: - virtual bool VerifySignature(const std::vector &vchSig, - const CPubKey &vchPubKey, - const uint256 &sighash) const; - - virtual bool CheckSig(const std::vector &scriptSig, - const std::vector &vchPubKey, - const CScript &scriptCode, uint32_t flags) const { + virtual bool VerifySignatureECDSA(const std::vector &vchSig, + const CPubKey &vchPubKey, + const uint256 &sighash) const; + + virtual bool CheckSigECDSA(const std::vector &scriptSig, + const std::vector &vchPubKey, + const CScript &scriptCode, + uint32_t flags) const { return false; } @@ -67,10 +68,10 @@ : txTo(txToIn), nIn(nInIn), amount(amountIn), txdata(&txdataIn) {} // The overriden functions are now final. - bool CheckSig(const std::vector &scriptSig, - const std::vector &vchPubKey, - const CScript &scriptCode, - uint32_t flags) const final override; + bool CheckSigECDSA(const std::vector &scriptSig, + const std::vector &vchPubKey, + const CScript &scriptCode, + uint32_t flags) const final override; bool CheckLockTime(const CScriptNum &nLockTime) const final override; bool CheckSequence(const CScriptNum &nSequence) const final override; }; diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -876,8 +876,8 @@ valtype &vchSig = stacktop(-2); valtype &vchPubKey = stacktop(-1); - if (!CheckTransactionSignatureEncoding(vchSig, flags, - serror) || + if (!CheckTransactionECDSASignatureEncoding( + vchSig, flags, serror) || !CheckPubKeyEncoding(vchPubKey, flags, serror)) { // serror is set return false; @@ -890,8 +890,8 @@ // Remove signature for pre-fork scripts CleanupScriptCode(scriptCode, vchSig, flags); - bool fSuccess = checker.CheckSig(vchSig, vchPubKey, - scriptCode, flags); + bool fSuccess = checker.CheckSigECDSA( + vchSig, vchPubKey, scriptCode, flags); if (!fSuccess && (flags & SCRIPT_VERIFY_NULLFAIL) && vchSig.size()) { @@ -928,8 +928,8 @@ valtype &vchMessage = stacktop(-2); valtype &vchPubKey = stacktop(-1); - if (!CheckDataSignatureEncoding(vchSig, flags, - serror) || + if (!CheckDataECDSASignatureEncoding(vchSig, flags, + serror) || !CheckPubKeyEncoding(vchPubKey, flags, serror)) { // serror is set return false; @@ -941,7 +941,7 @@ CSHA256() .Write(vchMessage.data(), vchMessage.size()) .Finalize(vchHash.data()); - fSuccess = checker.VerifySignature( + fSuccess = checker.VerifySignatureECDSA( vchSig, CPubKey(vchPubKey), uint256(vchHash)); } @@ -1028,7 +1028,7 @@ // pubkey/signature evaluation distinguishable by // CHECKMULTISIG NOT if the STRICTENC flag is set. // See the script_(in)valid tests for details. - if (!CheckTransactionSignatureEncoding( + if (!CheckTransactionECDSASignatureEncoding( vchSig, flags, serror) || !CheckPubKeyEncoding(vchPubKey, flags, serror)) { @@ -1037,8 +1037,8 @@ } // Check signature - bool fOk = checker.CheckSig(vchSig, vchPubKey, - scriptCode, flags); + bool fOk = checker.CheckSigECDSA(vchSig, vchPubKey, + scriptCode, flags); if (fOk) { isig++; @@ -1462,13 +1462,13 @@ return ss.GetHash(); } -bool BaseSignatureChecker::VerifySignature(const std::vector &vchSig, - const CPubKey &pubkey, - const uint256 &sighash) const { +bool BaseSignatureChecker::VerifySignatureECDSA( + const std::vector &vchSig, const CPubKey &pubkey, + const uint256 &sighash) const { return pubkey.Verify(sighash, vchSig); } -bool TransactionSignatureChecker::CheckSig( +bool TransactionSignatureChecker::CheckSigECDSA( const std::vector &vchSigIn, const std::vector &vchPubKey, const CScript &scriptCode, uint32_t flags) const { CPubKey pubkey(vchPubKey); @@ -1487,7 +1487,7 @@ uint256 sighash = SignatureHash(scriptCode, *txTo, nIn, sigHashType, amount, this->txdata, flags); - if (!VerifySignature(vchSig, pubkey, sighash)) { + if (!VerifySignatureECDSA(vchSig, pubkey, sighash)) { return false; } diff --git a/src/script/sigcache.h b/src/script/sigcache.h --- a/src/script/sigcache.h +++ b/src/script/sigcache.h @@ -51,9 +51,9 @@ : TransactionSignatureChecker(txToIn, nInIn, amountIn, txdataIn), store(storeIn) {} - bool VerifySignature(const std::vector &vchSig, - const CPubKey &vchPubKey, - const uint256 &sighash) const override; + bool VerifySignatureECDSA(const std::vector &vchSig, + const CPubKey &vchPubKey, + const uint256 &sighash) const override; }; void InitSignatureCache(); diff --git a/src/script/sigcache.cpp b/src/script/sigcache.cpp --- a/src/script/sigcache.cpp +++ b/src/script/sigcache.cpp @@ -57,10 +57,10 @@ /** * In previous versions of this code, signatureCache was a local static variable - * in CachingTransactionSignatureChecker::VerifySignature. We initialize - * signatureCache outside of VerifySignature to avoid the atomic operation per - * call overhead associated with local static variables even though - * signatureCache could be made local to VerifySignature. + * in CachingTransactionSignatureChecker::VerifySignatureECDSA(). We initialize + * signatureCache outside of VerifySignatureECDSA() to avoid the atomic + * operation per call overhead associated with local static variables even + * though signatureCache could be made local to VerifySignatureECDSA(). */ static CSignatureCache signatureCache; } // namespace @@ -80,7 +80,7 @@ (nElems * sizeof(uint256)) >> 20, nMaxCacheSize >> 20, nElems); } -bool CachingTransactionSignatureChecker::VerifySignature( +bool CachingTransactionSignatureChecker::VerifySignatureECDSA( const std::vector &vchSig, const CPubKey &pubkey, const uint256 &sighash) const { uint256 entry; @@ -88,8 +88,8 @@ if (signatureCache.Get(entry, !store)) { return true; } - if (!TransactionSignatureChecker::VerifySignature(vchSig, pubkey, - sighash)) { + if (!TransactionSignatureChecker::VerifySignatureECDSA(vchSig, pubkey, + sighash)) { return false; } if (store) { diff --git a/src/script/sigencoding.h b/src/script/sigencoding.h --- a/src/script/sigencoding.h +++ b/src/script/sigencoding.h @@ -28,20 +28,21 @@ } // namespace /** - * Check that the signature provided on some data is properly encoded. + * Check that the ECDSA signature provided on some data is properly encoded. * Signatures passed to OP_CHECKDATASIG and its verify variant must be checked * using this function. */ -bool CheckDataSignatureEncoding(const valtype &vchSig, uint32_t flags, - ScriptError *serror); +bool CheckDataECDSASignatureEncoding(const valtype &vchSig, uint32_t flags, + ScriptError *serror); /** - * Check that the signature provided to authentify a transaction is properly - * encoded. Signatures passed to OP_CHECKSIG, OP_CHECKMULTISIG and their verify - * variants must be checked using this function. + * Check that the ECDSA signature provided to authentify a transaction is + * properly encoded. Signatures passed to OP_CHECKSIG, OP_CHECKMULTISIG and + * their verify variants must be checked using this function. */ -bool CheckTransactionSignatureEncoding(const valtype &vchSig, uint32_t flags, - ScriptError *serror); +bool CheckTransactionECDSASignatureEncoding(const valtype &vchSig, + uint32_t flags, + ScriptError *serror); /** * Check that a public key is encoded properly. diff --git a/src/script/sigencoding.cpp b/src/script/sigencoding.cpp --- a/src/script/sigencoding.cpp +++ b/src/script/sigencoding.cpp @@ -168,8 +168,8 @@ return true; } -bool CheckDataSignatureEncoding(const valtype &vchSig, uint32_t flags, - ScriptError *serror) { +bool CheckDataECDSASignatureEncoding(const valtype &vchSig, uint32_t flags, + ScriptError *serror) { // Empty signature. Not strictly DER encoded, but allowed to provide a // compact way to provide an invalid signature for use with CHECK(MULTI)SIG if (vchSig.size() == 0) { @@ -180,8 +180,9 @@ vchSig | boost::adaptors::sliced(0, vchSig.size()), flags, serror); } -bool CheckTransactionSignatureEncoding(const valtype &vchSig, uint32_t flags, - ScriptError *serror) { +bool CheckTransactionECDSASignatureEncoding(const valtype &vchSig, + uint32_t flags, + ScriptError *serror) { // Empty signature. Not strictly DER encoded, but allowed to provide a // compact way to provide an invalid signature for use with CHECK(MULTI)SIG if (vchSig.size() == 0) { diff --git a/src/script/sign.cpp b/src/script/sign.cpp --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -239,8 +239,8 @@ continue; } - if (checker.CheckSig(sig, pubkey, scriptPubKey, - STANDARD_SCRIPT_VERIFY_FLAGS)) { + if (checker.CheckSigECDSA(sig, pubkey, scriptPubKey, + STANDARD_SCRIPT_VERIFY_FLAGS)) { sigs[pubkey] = sig; break; } @@ -358,9 +358,10 @@ public: DummySignatureChecker() {} - bool CheckSig(const std::vector &scriptSig, - const std::vector &vchPubKey, - const CScript &scriptCode, uint32_t flags) const override { + bool CheckSigECDSA(const std::vector &scriptSig, + const std::vector &vchPubKey, + const CScript &scriptCode, + uint32_t flags) const override { return true; } }; diff --git a/src/test/sigencoding_tests.cpp b/src/test/sigencoding_tests.cpp --- a/src/test/sigencoding_tests.cpp +++ b/src/test/sigencoding_tests.cpp @@ -19,7 +19,7 @@ static void CheckSignatureEncodingWithSigHashType(const valtype &vchSig, uint32_t flags) { ScriptError err = SCRIPT_ERR_OK; - BOOST_CHECK(CheckDataSignatureEncoding(vchSig, flags, &err)); + BOOST_CHECK(CheckDataECDSASignatureEncoding(vchSig, flags, &err)); const bool hasForkId = (flags & SCRIPT_ENABLE_SIGHASH_FORKID) != 0; const bool hasStrictEnc = (flags & SCRIPT_VERIFY_STRICTENC) != 0; @@ -38,7 +38,8 @@ // Check the signature with the proper forkid flag. SigHashType sigHash = baseSigHash.withForkId(hasForkId); valtype validSig = SignatureWithHashType(vchSig, sigHash); - BOOST_CHECK(CheckTransactionSignatureEncoding(validSig, flags, &err)); + BOOST_CHECK( + CheckTransactionECDSASignatureEncoding(validSig, flags, &err)); // If we have strict encoding, we prevent the use of undefined flags. std::array undefSigHashes{ @@ -47,9 +48,9 @@ for (SigHashType undefSigHash : undefSigHashes) { valtype undefSighash = SignatureWithHashType(vchSig, undefSigHash); - BOOST_CHECK_EQUAL( - CheckTransactionSignatureEncoding(undefSighash, flags, &err), - !hasStrictEnc); + BOOST_CHECK_EQUAL(CheckTransactionECDSASignatureEncoding( + undefSighash, flags, &err), + !hasStrictEnc); if (hasStrictEnc) { BOOST_CHECK_EQUAL(err, SCRIPT_ERR_SIG_HASHTYPE); } @@ -60,7 +61,7 @@ valtype invalidSig = SignatureWithHashType(vchSig, invalidSigHash); BOOST_CHECK_EQUAL( - CheckTransactionSignatureEncoding(invalidSig, flags, &err), + CheckTransactionECDSASignatureEncoding(invalidSig, flags, &err), !hasStrictEnc); if (hasStrictEnc) { BOOST_CHECK_EQUAL(err, hasForkId ? SCRIPT_ERR_MUST_USE_FORKID @@ -162,15 +163,16 @@ ScriptError err = SCRIPT_ERR_OK; // Empty sig is always valid. - BOOST_CHECK(CheckDataSignatureEncoding({}, flags, &err)); - BOOST_CHECK(CheckTransactionSignatureEncoding({}, flags, &err)); + BOOST_CHECK(CheckDataECDSASignatureEncoding({}, flags, &err)); + BOOST_CHECK(CheckTransactionECDSASignatureEncoding({}, flags, &err)); // Signature are valid as long as the forkid flag is correct. CheckSignatureEncodingWithSigHashType(minimalSig, flags); if (flags & SCRIPT_VERIFY_LOW_S) { // If we do enforce low S, then high S sigs are rejected. - BOOST_CHECK(!CheckDataSignatureEncoding(highSSig, flags, &err)); + BOOST_CHECK( + !CheckDataECDSASignatureEncoding(highSSig, flags, &err)); BOOST_CHECK_EQUAL(err, SCRIPT_ERR_SIG_HIGH_S); } else { // If we do not enforce low S, then high S sigs are accepted. @@ -183,11 +185,12 @@ // If we get any of the dersig flags, the non canonical dersig // signature fails. BOOST_CHECK( - !CheckDataSignatureEncoding(nonDERSig, flags, &err)); + !CheckDataECDSASignatureEncoding(nonDERSig, flags, &err)); BOOST_CHECK_EQUAL(err, SCRIPT_ERR_SIG_DER); } else { // If we do not check, then it is accepted. - BOOST_CHECK(CheckDataSignatureEncoding(nonDERSig, flags, &err)); + BOOST_CHECK( + CheckDataECDSASignatureEncoding(nonDERSig, flags, &err)); } } @@ -197,11 +200,12 @@ // If we get any of the dersig flags, the high S but non dersig // signature fails. BOOST_CHECK( - !CheckDataSignatureEncoding(nonDERSig, flags, &err)); + !CheckDataECDSASignatureEncoding(nonDERSig, flags, &err)); BOOST_CHECK_EQUAL(err, SCRIPT_ERR_SIG_DER); } else { // If we do not check, then it is accepted. - BOOST_CHECK(CheckDataSignatureEncoding(nonDERSig, flags, &err)); + BOOST_CHECK( + CheckDataECDSASignatureEncoding(nonDERSig, flags, &err)); } } }