Bitcoin ABC  0.29.2
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 #include <util/hasher.h>
11 
12 #include <optional>
13 #include <vector>
14 
15 // DoS prevention: limit cache size to 32MiB (over 1000000 entries on 64-bit
16 // systems). Due to how we count cache size, actual memory usage is slightly
17 // more (~32.25 MiB)
18 static constexpr size_t DEFAULT_MAX_SIG_CACHE_BYTES{32 << 20};
19 
20 class CPubKey;
21 
23 private:
24  bool store;
25 
26  bool IsCached(const std::vector<uint8_t> &vchSig, const CPubKey &vchPubKey,
27  const uint256 &sighash) const;
28 
29 public:
31  unsigned int nInIn,
32  const Amount amountIn, bool storeIn,
34  : TransactionSignatureChecker(txToIn, nInIn, amountIn, txdataIn),
35  store(storeIn) {}
36 
37  bool VerifySignature(const std::vector<uint8_t> &vchSig,
38  const CPubKey &vchPubKey,
39  const uint256 &sighash) const override;
40 
42 };
43 
44 [[nodiscard]] bool InitSignatureCache(size_t max_size_bytes);
45 
46 #endif // BITCOIN_SCRIPT_SIGCACHE_H
An encapsulated public key.
Definition: pubkey.h:31
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:192
friend class TestCachingTransactionSignatureChecker
Definition: sigcache.h:41
bool VerifySignature(const std::vector< uint8_t > &vchSig, const CPubKey &vchPubKey, const uint256 &sighash) const override
Definition: sigcache.cpp:121
bool IsCached(const std::vector< uint8_t > &vchSig, const CPubKey &vchPubKey, const uint256 &sighash) const
Definition: sigcache.cpp:114
CachingTransactionSignatureChecker(const CTransaction *txToIn, unsigned int nInIn, const Amount amountIn, bool storeIn, PrecomputedTransactionData &txdataIn)
Definition: sigcache.h:30
256-bit opaque blob.
Definition: uint256.h:129
static constexpr size_t DEFAULT_MAX_SIG_CACHE_BYTES
Definition: sigcache.h:18
bool InitSignatureCache(size_t max_size_bytes)
Definition: sigcache.cpp:84
Definition: amount.h:19
Precompute sighash midstate to avoid quadratic hashing.
Definition: transaction.h:325