Bitcoin Core  22.99.0
P2P Digital Currency
eval_script.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2020 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <pubkey.h>
6 #include <script/interpreter.h>
8 #include <test/fuzz/fuzz.h>
9 
10 #include <limits>
11 
13 {
14  static const ECCVerifyHandle verify_handle;
15 }
16 
18 {
19  FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
20  const unsigned int flags = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
21  const std::vector<uint8_t> script_bytes = [&] {
22  if (fuzzed_data_provider.remaining_bytes() != 0) {
23  return fuzzed_data_provider.ConsumeRemainingBytes<uint8_t>();
24  } else {
25  // Avoid UBSan warning:
26  // test/fuzz/FuzzedDataProvider.h:212:17: runtime error: null pointer passed as argument 1, which is declared to never be null
27  // /usr/include/string.h:43:28: note: nonnull attribute specified here
28  return std::vector<uint8_t>();
29  }
30  }();
31  const CScript script(script_bytes.begin(), script_bytes.end());
32  for (const auto sig_version : {SigVersion::BASE, SigVersion::WITNESS_V0}) {
33  std::vector<std::vector<unsigned char>> stack;
34  (void)EvalScript(stack, script, flags, BaseSignatureChecker(), sig_version, nullptr);
35  }
36 }
FUZZ_TARGET_INIT
FUZZ_TARGET_INIT(eval_script, initialize_eval_script)
Definition: eval_script.cpp:17
SigVersion::BASE
@ BASE
Bare scripts and BIP16 P2SH-wrapped redeemscripts.
flags
int flags
Definition: bitcoin-tx.cpp:513
interpreter.h
BaseSignatureChecker
Definition: interpreter.h:238
pubkey.h
initialize_eval_script
void initialize_eval_script()
Definition: eval_script.cpp:12
FuzzedDataProvider::ConsumeRemainingBytes
std::vector< T > ConsumeRemainingBytes()
Definition: FuzzedDataProvider.h:128
FuzzedDataProvider.h
SigVersion::WITNESS_V0
@ WITNESS_V0
Witness v0 (P2WPKH and P2WSH); see BIP 141.
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:405
FuzzedDataProvider::remaining_bytes
size_t remaining_bytes()
Definition: FuzzedDataProvider.h:84
ECCVerifyHandle
Users of this module must hold an ECCVerifyHandle.
Definition: pubkey.h:315
fuzz.h
FuzzedDataProvider
Definition: FuzzedDataProvider.h:31
EvalScript
bool EvalScript(std::vector< std::vector< unsigned char > > &stack, const CScript &script, unsigned int flags, const BaseSignatureChecker &checker, SigVersion sigversion, ScriptExecutionData &execdata, ScriptError *serror)
Definition: interpreter.cpp:431
FuzzedDataProvider::ConsumeIntegral
T ConsumeIntegral()
Definition: FuzzedDataProvider.h:194