Bitcoin ABC  0.22.12
P2P Digital Currency
sigcache.h
Go to the documentation of this file.
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 
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  std::memcpy(&u, key.begin() + 4 * hash_select, 4);
38  return u;
39  }
40 };
41 
43 private:
44  bool store;
45 
46  bool IsCached(const std::vector<uint8_t> &vchSig, const CPubKey &vchPubKey,
47  const uint256 &sighash) const;
48 
49 public:
51  unsigned int nInIn,
52  const Amount amountIn, bool storeIn,
54  : TransactionSignatureChecker(txToIn, nInIn, amountIn, txdataIn),
55  store(storeIn) {}
56 
57  bool VerifySignature(const std::vector<uint8_t> &vchSig,
58  const CPubKey &vchPubKey,
59  const uint256 &sighash) const override;
60 
61  friend class TestCachingTransactionSignatureChecker;
62 };
63 
64 void InitSignatureCache();
65 
66 #endif // BITCOIN_SCRIPT_SIGCACHE_H
static const unsigned int DEFAULT_MAX_SIG_CACHE_SIZE
Definition: sigcache.h:16
Precompute sighash midstate to avoid quadratic hashing.
Definition: transaction.h:348
Definition: amount.h:17
void InitSignatureCache()
Definition: sigcache.cpp:71
We&#39;re hashing a nonce into the entries themselves, so we don&#39;t need extra blinding in the set hash co...
Definition: sigcache.h:30
An encapsulated public key.
Definition: pubkey.h:31
uint8_t * begin()
Definition: uint256.h:76
CachingTransactionSignatureChecker(const CTransaction *txToIn, unsigned int nInIn, const Amount amountIn, bool storeIn, PrecomputedTransactionData &txdataIn)
Definition: sigcache.h:50
256-bit opaque blob.
Definition: uint256.h:120
static const int64_t MAX_MAX_SIG_CACHE_SIZE
Definition: sigcache.h:18
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:211
uint32_t operator()(const uint256 &key) const
Definition: sigcache.h:33