You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sigcache.h 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (c) 2009-2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2016 The Starwels developers
  3. // Distributed under the MIT software license, see the accompanying
  4. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  5. #ifndef STARWELS_SCRIPT_SIGCACHE_H
  6. #define STARWELS_SCRIPT_SIGCACHE_H
  7. #include "script/interpreter.h"
  8. #include <vector>
  9. // DoS prevention: limit cache size to 32MB (over 1000000 entries on 64-bit
  10. // systems). Due to how we count cache size, actual memory usage is slightly
  11. // more (~32.25 MB)
  12. static const unsigned int DEFAULT_MAX_SIG_CACHE_SIZE = 32;
  13. // Maximum sig cache size allowed
  14. static const int64_t MAX_MAX_SIG_CACHE_SIZE = 16384;
  15. class CPubKey;
  16. /**
  17. * We're hashing a nonce into the entries themselves, so we don't need extra
  18. * blinding in the set hash computation.
  19. *
  20. * This may exhibit platform endian dependent behavior but because these are
  21. * nonced hashes (random) and this state is only ever used locally it is safe.
  22. * All that matters is local consistency.
  23. */
  24. class SignatureCacheHasher
  25. {
  26. public:
  27. template <uint8_t hash_select>
  28. uint32_t operator()(const uint256& key) const
  29. {
  30. static_assert(hash_select <8, "SignatureCacheHasher only has 8 hashes available.");
  31. uint32_t u;
  32. std::memcpy(&u, key.begin()+4*hash_select, 4);
  33. return u;
  34. }
  35. };
  36. class CachingTransactionSignatureChecker : public TransactionSignatureChecker
  37. {
  38. private:
  39. bool store;
  40. public:
  41. CachingTransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, bool storeIn, PrecomputedTransactionData& txdataIn) : TransactionSignatureChecker(txToIn, nInIn, amountIn, txdataIn), store(storeIn) {}
  42. bool VerifySignature(const std::vector<unsigned char>& vchSig, const CPubKey& vchPubKey, const uint256& sighash) const override;
  43. };
  44. void InitSignatureCache();
  45. #endif // STARWELS_SCRIPT_SIGCACHE_H