Bitcoin Core 28.99.0
P2P Digital Currency
script_ops.cpp
Go to the documentation of this file.
1// Copyright (c) 2020-2021 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 <script/script.h>
7#include <test/fuzz/fuzz.h>
8#include <test/fuzz/util.h>
9
10#include <cstdint>
11#include <string>
12#include <vector>
13
14FUZZ_TARGET(script_ops)
15{
16 FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
17 CScript script_mut = ConsumeScript(fuzzed_data_provider);
18 LIMITED_WHILE(fuzzed_data_provider.remaining_bytes() > 0, 1000000) {
20 fuzzed_data_provider,
21 [&] {
22 CScript s = ConsumeScript(fuzzed_data_provider);
23 script_mut = std::move(s);
24 },
25 [&] {
26 const CScript& s = ConsumeScript(fuzzed_data_provider);
27 script_mut = s;
28 },
29 [&] {
30 script_mut << fuzzed_data_provider.ConsumeIntegral<int64_t>();
31 },
32 [&] {
33 script_mut << ConsumeOpcodeType(fuzzed_data_provider);
34 },
35 [&] {
36 script_mut << ConsumeScriptNum(fuzzed_data_provider);
37 },
38 [&] {
39 script_mut << ConsumeRandomLengthByteVector(fuzzed_data_provider);
40 },
41 [&] {
42 script_mut.clear();
43 });
44 }
45 const CScript& script = script_mut;
46 (void)script.GetSigOpCount(false);
47 (void)script.GetSigOpCount(true);
48 (void)script.GetSigOpCount(script);
49 (void)script.HasValidOps();
50 (void)script.IsPayToScriptHash();
51 (void)script.IsPayToWitnessScriptHash();
52 (void)script.IsPushOnly();
53 (void)script.IsUnspendable();
54 {
56 opcodetype opcode;
57 (void)script.GetOp(pc, opcode);
58 std::vector<uint8_t> data;
59 (void)script.GetOp(pc, opcode, data);
60 (void)script.IsPushOnly(pc);
61 }
62 {
63 int version;
64 std::vector<uint8_t> program;
65 (void)script.IsWitnessProgram(version, program);
66 }
67}
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:415
void clear()
Definition: script.h:576
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
Definition: fuzz.h:22
opcodetype
Script opcodes.
Definition: script.h:74
FUZZ_TARGET(script_ops)
Definition: script_ops.cpp:14
CScript ConsumeScript(FuzzedDataProvider &fuzzed_data_provider, const bool maybe_p2wsh) noexcept
Definition: util.cpp:93
CScriptNum ConsumeScriptNum(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.h:157
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
Definition: util.h:35
std::vector< B > ConsumeRandomLengthByteVector(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept
Definition: util.h:57
opcodetype ConsumeOpcodeType(FuzzedDataProvider &fuzzed_data_provider) noexcept
Definition: util.h:140