Line data Source code
1 : // Copyright (c) 2009-2010 Satoshi Nakamoto 2 : // Copyright (c) 2009-2021 The Bitcoin Core developers 3 : // Distributed under the MIT software license, see the accompanying 4 : // file COPYING or http://www.opensource.org/licenses/mit-license.php. 5 : 6 : #ifndef BITCOIN_SCRIPT_SIGCACHE_H 7 : #define BITCOIN_SCRIPT_SIGCACHE_H 8 : 9 : #include <script/interpreter.h> 10 : #include <util/hasher.h> 11 : 12 : #include <vector> 13 : 14 : // DoS prevention: limit cache size to 32MB (over 1000000 entries on 64-bit 15 : // systems). Due to how we count cache size, actual memory usage is slightly 16 : // more (~32.25 MB) 17 : static const unsigned int DEFAULT_MAX_SIG_CACHE_SIZE = 32; 18 : // Maximum sig cache size allowed 19 : static const int64_t MAX_MAX_SIG_CACHE_SIZE = 16384; 20 : 21 : class CPubKey; 22 : 23 : class CachingTransactionSignatureChecker : public TransactionSignatureChecker 24 : { 25 : private: 26 : bool store; 27 : 28 : public: 29 709634 : CachingTransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CAmount& amount, PrecomputedTransactionData& txdataIn, bool storeIn=true) : TransactionSignatureChecker(txToIn, nInIn, amount, txdataIn, MissingDataBehavior::ASSERT_FAIL), store(storeIn) {} 30 : 31 : bool VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& vchPubKey, const uint256& sighash) const override; 32 : }; 33 : 34 : void InitSignatureCache(); 35 : 36 : #endif // BITCOIN_SCRIPT_SIGCACHE_H