upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/fuzz_script.cpp
diff options
context:
space:
mode:
authorNsable-sh <nsable-sh@noreply.git.bitflash.network>2026-08-07 10:55:54 -0300
committerBitflash <admin@bitflash.network>2026-08-07 11:05:09 -0300
commit4de5cca7e7a0a7104dae8d414add33f6e9562e4a (patch)
treebf8528ea6f3d7c977e8b2ccd4c4e36e135464b4f /src/fuzz_script.cpp
parent44004e350ba7a8e7e67338c8f7eb2589fbbf0a3c (diff)
fuzz: add script parser harness (#5)
Diffstat (limited to 'src/fuzz_script.cpp')
-rw-r--r--src/fuzz_script.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/fuzz_script.cpp b/src/fuzz_script.cpp
new file mode 100644
index 0000000..28c84f6
--- /dev/null
+++ b/src/fuzz_script.cpp
@@ -0,0 +1,59 @@
1// Copyright (c) 2026 Bitflash developers
2// Distributed under the MIT/X11 software license.
3//
4// libFuzzer harness for raw script parsing and evaluation. It keeps the
5// target deliberately small: arbitrary bytes become one CScript, then the
6// parser, standard-script extractors and EvalScript all see that same input.
7
8#include "headers_core.h"
9
10#include <stdint.h>
11#include <stddef.h>
12
13// Stand-ins normally supplied by the GUI/headless entry objects.
14map<string,string> mapAddressBook;
15bool gPoolServerRunning = false;
16void MainFrameRepaint() {}
17
18extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
19{
20 if (size < 1 || size > 4096)
21 return 0;
22
23 try
24 {
25 int nHashType = data[0];
26 const unsigned char* pbegin = data + 1;
27 const unsigned char* pend = data + size;
28 CScript script(pbegin, pend);
29
30 CScript::const_iterator pc = script.begin();
31 opcodetype opcode;
32 vector<unsigned char> vchPush;
33 while (pc < script.end())
34 {
35 if (!script.GetOp(pc, opcode, vchPush))
36 break;
37 }
38
39 script.GetSigOpCount();
40 script.ToString();
41
42 vector<unsigned char> vchPubKey;
43 ExtractPubKey(script, false, vchPubKey);
44 uint160 hash160;
45 ExtractHash160(script, hash160);
46
47 CTransaction tx;
48 tx.vin.push_back(CTxIn(COutPoint(), CScript()));
49 tx.vout.push_back(CTxOut(0, CScript()));
50
51 vector<vector<unsigned char> > stack;
52 EvalScript(script, tx, 0, nHashType, &stack);
53 }
54 catch (...)
55 {
56 }
57
58 return 0;
59}