LCOV - code coverage report
Current view: top level - src/script - sigcache.h (source / functions) Hit Total Coverage
Test: bitcoincash_test.info Lines: 1 1 100.0 %
Date: 2018-04-13 15:12:50 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2             : // Copyright (c) 2009-2016 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             : 
      11             : #include <vector>
      12             : 
      13             : // DoS prevention: limit cache size to 32MB (over 1000000 entries on 64-bit
      14             : // systems). Due to how we count cache size, actual memory usage is slightly
      15             : // more (~32.25 MB)
      16             : static const unsigned int DEFAULT_MAX_SIG_CACHE_SIZE = 32;
      17             : // Maximum sig cache size allowed
      18             : static const int64_t MAX_MAX_SIG_CACHE_SIZE = 16384;
      19             : 
      20             : class CPubKey;
      21             : 
      22             : /**
      23             :  * We're hashing a nonce into the entries themselves, so we don't need extra
      24             :  * blinding in the set hash computation.
      25             :  *
      26             :  * This may exhibit platform endian dependent behavior but because these are
      27             :  * nonced hashes (random) and this state is only ever used locally it is safe.
      28             :  * All that matters is local consistency.
      29             :  */
      30             : class SignatureCacheHasher {
      31             : public:
      32             :     template <uint8_t hash_select>
      33             :     uint32_t operator()(const uint256 &key) const {
      34             :         static_assert(hash_select < 8,
      35             :                       "SignatureCacheHasher only has 8 hashes available.");
      36             :         uint32_t u;
      37   412289415 :         std::memcpy(&u, key.begin() + 4 * hash_select, 4);
      38             :         return u;
      39             :     }
      40             : };
      41             : 
      42             : class CachingTransactionSignatureChecker : public TransactionSignatureChecker {
      43             : private:
      44             :     bool store;
      45             : 
      46             : public:
      47             :     CachingTransactionSignatureChecker(const CTransaction *txToIn,
      48             :                                        unsigned int nInIn, const Amount amount,
      49             :                                        bool storeIn,
      50             :                                        PrecomputedTransactionData &txdataIn)
      51             :         : TransactionSignatureChecker(txToIn, nInIn, amount, txdataIn),
      52             :           store(storeIn) {}
      53             : 
      54             :     bool VerifySignature(const std::vector<uint8_t> &vchSig,
      55             :                          const CPubKey &vchPubKey,
      56             :                          const uint256 &sighash) const override;
      57             : };
      58             : 
      59             : void InitSignatureCache();
      60             : 
      61             : #endif // BITCOIN_SCRIPT_SIGCACHE_H

Generated by: LCOV version 1.12