Bitcoin Core  0.20.99
P2P Digital Currency
sigcache.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2018 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 <span.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 
32 {
33 public:
34  template <uint8_t hash_select>
35  uint32_t operator()(const uint256& key) const
36  {
37  static_assert(hash_select <8, "SignatureCacheHasher only has 8 hashes available.");
38  uint32_t u;
39  std::memcpy(&u, key.begin()+4*hash_select, 4);
40  return u;
41  }
42 };
43 
45 {
46 private:
47  bool store;
48 
49 public:
50  CachingTransactionSignatureChecker(const CTransaction* txToIn, unsigned int nInIn, const CAmount& amountIn, bool storeIn, PrecomputedTransactionData& txdataIn) : TransactionSignatureChecker(txToIn, nInIn, amountIn, txdataIn), store(storeIn) {}
51 
52  bool VerifyECDSASignature(const std::vector<unsigned char>& vchSig, const CPubKey& vchPubKey, const uint256& sighash) const override;
53  bool VerifySchnorrSignature(Span<const unsigned char> sig, const XOnlyPubKey& pubkey, const uint256& sighash) const override;
54 };
55 
56 void InitSignatureCache();
57 
58 #endif // BITCOIN_SCRIPT_SIGCACHE_H
static const unsigned int DEFAULT_MAX_SIG_CACHE_SIZE
Definition: sigcache.h:17
void InitSignatureCache()
Definition: sigcache.cpp:91
unsigned char * begin()
Definition: uint256.h:58
CachingTransactionSignatureChecker(const CTransaction *txToIn, unsigned int nInIn, const CAmount &amountIn, bool storeIn, PrecomputedTransactionData &txdataIn)
Definition: sigcache.h:50
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:31
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
An encapsulated public key.
Definition: pubkey.h:31
256-bit opaque blob.
Definition: uint256.h:124
static const int64_t MAX_MAX_SIG_CACHE_SIZE
Definition: sigcache.h:19
void * memcpy(void *a, const void *b, size_t c)
A Span is an object that can refer to a contiguous sequence of objects.
Definition: span.h:82
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:259
uint32_t operator()(const uint256 &key) const
Definition: sigcache.h:35