upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/fuzz_script.cpp
blob: 28c84f6fdaaf86a1230f74fc92683174c8587a30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) 2026 Bitflash developers
// Distributed under the MIT/X11 software license.
//
// libFuzzer harness for raw script parsing and evaluation. It keeps the
// target deliberately small: arbitrary bytes become one CScript, then the
// parser, standard-script extractors and EvalScript all see that same input.

#include "headers_core.h"

#include <stdint.h>
#include <stddef.h>

// Stand-ins normally supplied by the GUI/headless entry objects.
map<string,string> mapAddressBook;
bool gPoolServerRunning = false;
void MainFrameRepaint() {}

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
    if (size < 1 || size > 4096)
        return 0;

    try
    {
        int nHashType = data[0];
        const unsigned char* pbegin = data + 1;
        const unsigned char* pend = data + size;
        CScript script(pbegin, pend);

        CScript::const_iterator pc = script.begin();
        opcodetype opcode;
        vector<unsigned char> vchPush;
        while (pc < script.end())
        {
            if (!script.GetOp(pc, opcode, vchPush))
                break;
        }

        script.GetSigOpCount();
        script.ToString();

        vector<unsigned char> vchPubKey;
        ExtractPubKey(script, false, vchPubKey);
        uint160 hash160;
        ExtractHash160(script, hash160);

        CTransaction tx;
        tx.vin.push_back(CTxIn(COutPoint(), CScript()));
        tx.vout.push_back(CTxOut(0, CScript()));

        vector<vector<unsigned char> > stack;
        EvalScript(script, tx, 0, nHashType, &stack);
    }
    catch (...)
    {
    }

    return 0;
}