Coverage Report

Created: 2025-06-10 13:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/bitcoin/src/script/script.cpp
Line
Count
Source
1
// Copyright (c) 2009-2010 Satoshi Nakamoto
2
// Copyright (c) 2009-present 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
#include <script/script.h>
7
8
#include <crypto/common.h>
9
#include <crypto/hex_base.h>
10
#include <hash.h>
11
#include <uint256.h>
12
#include <util/hash_type.h>
13
14
#include <string>
15
16
221k
CScriptID::CScriptID(const CScript& in) : BaseHash(Hash160(in)) {}
17
18
std::string GetOpName(opcodetype opcode)
19
0
{
20
0
    switch (opcode)
21
0
    {
22
    // push value
23
0
    case OP_0                      : return "0";
  Branch (23:5): [True: 0, False: 0]
24
0
    case OP_PUSHDATA1              : return "OP_PUSHDATA1";
  Branch (24:5): [True: 0, False: 0]
25
0
    case OP_PUSHDATA2              : return "OP_PUSHDATA2";
  Branch (25:5): [True: 0, False: 0]
26
0
    case OP_PUSHDATA4              : return "OP_PUSHDATA4";
  Branch (26:5): [True: 0, False: 0]
27
0
    case OP_1NEGATE                : return "-1";
  Branch (27:5): [True: 0, False: 0]
28
0
    case OP_RESERVED               : return "OP_RESERVED";
  Branch (28:5): [True: 0, False: 0]
29
0
    case OP_1                      : return "1";
  Branch (29:5): [True: 0, False: 0]
30
0
    case OP_2                      : return "2";
  Branch (30:5): [True: 0, False: 0]
31
0
    case OP_3                      : return "3";
  Branch (31:5): [True: 0, False: 0]
32
0
    case OP_4                      : return "4";
  Branch (32:5): [True: 0, False: 0]
33
0
    case OP_5                      : return "5";
  Branch (33:5): [True: 0, False: 0]
34
0
    case OP_6                      : return "6";
  Branch (34:5): [True: 0, False: 0]
35
0
    case OP_7                      : return "7";
  Branch (35:5): [True: 0, False: 0]
36
0
    case OP_8                      : return "8";
  Branch (36:5): [True: 0, False: 0]
37
0
    case OP_9                      : return "9";
  Branch (37:5): [True: 0, False: 0]
38
0
    case OP_10                     : return "10";
  Branch (38:5): [True: 0, False: 0]
39
0
    case OP_11                     : return "11";
  Branch (39:5): [True: 0, False: 0]
40
0
    case OP_12                     : return "12";
  Branch (40:5): [True: 0, False: 0]
41
0
    case OP_13                     : return "13";
  Branch (41:5): [True: 0, False: 0]
42
0
    case OP_14                     : return "14";
  Branch (42:5): [True: 0, False: 0]
43
0
    case OP_15                     : return "15";
  Branch (43:5): [True: 0, False: 0]
44
0
    case OP_16                     : return "16";
  Branch (44:5): [True: 0, False: 0]
45
46
    // control
47
0
    case OP_NOP                    : return "OP_NOP";
  Branch (47:5): [True: 0, False: 0]
48
0
    case OP_VER                    : return "OP_VER";
  Branch (48:5): [True: 0, False: 0]
49
0
    case OP_IF                     : return "OP_IF";
  Branch (49:5): [True: 0, False: 0]
50
0
    case OP_NOTIF                  : return "OP_NOTIF";
  Branch (50:5): [True: 0, False: 0]
51
0
    case OP_VERIF                  : return "OP_VERIF";
  Branch (51:5): [True: 0, False: 0]
52
0
    case OP_VERNOTIF               : return "OP_VERNOTIF";
  Branch (52:5): [True: 0, False: 0]
53
0
    case OP_ELSE                   : return "OP_ELSE";
  Branch (53:5): [True: 0, False: 0]
54
0
    case OP_ENDIF                  : return "OP_ENDIF";
  Branch (54:5): [True: 0, False: 0]
55
0
    case OP_VERIFY                 : return "OP_VERIFY";
  Branch (55:5): [True: 0, False: 0]
56
0
    case OP_RETURN                 : return "OP_RETURN";
  Branch (56:5): [True: 0, False: 0]
57
58
    // stack ops
59
0
    case OP_TOALTSTACK             : return "OP_TOALTSTACK";
  Branch (59:5): [True: 0, False: 0]
60
0
    case OP_FROMALTSTACK           : return "OP_FROMALTSTACK";
  Branch (60:5): [True: 0, False: 0]
61
0
    case OP_2DROP                  : return "OP_2DROP";
  Branch (61:5): [True: 0, False: 0]
62
0
    case OP_2DUP                   : return "OP_2DUP";
  Branch (62:5): [True: 0, False: 0]
63
0
    case OP_3DUP                   : return "OP_3DUP";
  Branch (63:5): [True: 0, False: 0]
64
0
    case OP_2OVER                  : return "OP_2OVER";
  Branch (64:5): [True: 0, False: 0]
65
0
    case OP_2ROT                   : return "OP_2ROT";
  Branch (65:5): [True: 0, False: 0]
66
0
    case OP_2SWAP                  : return "OP_2SWAP";
  Branch (66:5): [True: 0, False: 0]
67
0
    case OP_IFDUP                  : return "OP_IFDUP";
  Branch (67:5): [True: 0, False: 0]
68
0
    case OP_DEPTH                  : return "OP_DEPTH";
  Branch (68:5): [True: 0, False: 0]
69
0
    case OP_DROP                   : return "OP_DROP";
  Branch (69:5): [True: 0, False: 0]
70
0
    case OP_DUP                    : return "OP_DUP";
  Branch (70:5): [True: 0, False: 0]
71
0
    case OP_NIP                    : return "OP_NIP";
  Branch (71:5): [True: 0, False: 0]
72
0
    case OP_OVER                   : return "OP_OVER";
  Branch (72:5): [True: 0, False: 0]
73
0
    case OP_PICK                   : return "OP_PICK";
  Branch (73:5): [True: 0, False: 0]
74
0
    case OP_ROLL                   : return "OP_ROLL";
  Branch (74:5): [True: 0, False: 0]
75
0
    case OP_ROT                    : return "OP_ROT";
  Branch (75:5): [True: 0, False: 0]
76
0
    case OP_SWAP                   : return "OP_SWAP";
  Branch (76:5): [True: 0, False: 0]
77
0
    case OP_TUCK                   : return "OP_TUCK";
  Branch (77:5): [True: 0, False: 0]
78
79
    // splice ops
80
0
    case OP_CAT                    : return "OP_CAT";
  Branch (80:5): [True: 0, False: 0]
81
0
    case OP_SUBSTR                 : return "OP_SUBSTR";
  Branch (81:5): [True: 0, False: 0]
82
0
    case OP_LEFT                   : return "OP_LEFT";
  Branch (82:5): [True: 0, False: 0]
83
0
    case OP_RIGHT                  : return "OP_RIGHT";
  Branch (83:5): [True: 0, False: 0]
84
0
    case OP_SIZE                   : return "OP_SIZE";
  Branch (84:5): [True: 0, False: 0]
85
86
    // bit logic
87
0
    case OP_INVERT                 : return "OP_INVERT";
  Branch (87:5): [True: 0, False: 0]
88
0
    case OP_AND                    : return "OP_AND";
  Branch (88:5): [True: 0, False: 0]
89
0
    case OP_OR                     : return "OP_OR";
  Branch (89:5): [True: 0, False: 0]
90
0
    case OP_XOR                    : return "OP_XOR";
  Branch (90:5): [True: 0, False: 0]
91
0
    case OP_EQUAL                  : return "OP_EQUAL";
  Branch (91:5): [True: 0, False: 0]
92
0
    case OP_EQUALVERIFY            : return "OP_EQUALVERIFY";
  Branch (92:5): [True: 0, False: 0]
93
0
    case OP_RESERVED1              : return "OP_RESERVED1";
  Branch (93:5): [True: 0, False: 0]
94
0
    case OP_RESERVED2              : return "OP_RESERVED2";
  Branch (94:5): [True: 0, False: 0]
95
96
    // numeric
97
0
    case OP_1ADD                   : return "OP_1ADD";
  Branch (97:5): [True: 0, False: 0]
98
0
    case OP_1SUB                   : return "OP_1SUB";
  Branch (98:5): [True: 0, False: 0]
99
0
    case OP_2MUL                   : return "OP_2MUL";
  Branch (99:5): [True: 0, False: 0]
100
0
    case OP_2DIV                   : return "OP_2DIV";
  Branch (100:5): [True: 0, False: 0]
101
0
    case OP_NEGATE                 : return "OP_NEGATE";
  Branch (101:5): [True: 0, False: 0]
102
0
    case OP_ABS                    : return "OP_ABS";
  Branch (102:5): [True: 0, False: 0]
103
0
    case OP_NOT                    : return "OP_NOT";
  Branch (103:5): [True: 0, False: 0]
104
0
    case OP_0NOTEQUAL              : return "OP_0NOTEQUAL";
  Branch (104:5): [True: 0, False: 0]
105
0
    case OP_ADD                    : return "OP_ADD";
  Branch (105:5): [True: 0, False: 0]
106
0
    case OP_SUB                    : return "OP_SUB";
  Branch (106:5): [True: 0, False: 0]
107
0
    case OP_MUL                    : return "OP_MUL";
  Branch (107:5): [True: 0, False: 0]
108
0
    case OP_DIV                    : return "OP_DIV";
  Branch (108:5): [True: 0, False: 0]
109
0
    case OP_MOD                    : return "OP_MOD";
  Branch (109:5): [True: 0, False: 0]
110
0
    case OP_LSHIFT                 : return "OP_LSHIFT";
  Branch (110:5): [True: 0, False: 0]
111
0
    case OP_RSHIFT                 : return "OP_RSHIFT";
  Branch (111:5): [True: 0, False: 0]
112
0
    case OP_BOOLAND                : return "OP_BOOLAND";
  Branch (112:5): [True: 0, False: 0]
113
0
    case OP_BOOLOR                 : return "OP_BOOLOR";
  Branch (113:5): [True: 0, False: 0]
114
0
    case OP_NUMEQUAL               : return "OP_NUMEQUAL";
  Branch (114:5): [True: 0, False: 0]
115
0
    case OP_NUMEQUALVERIFY         : return "OP_NUMEQUALVERIFY";
  Branch (115:5): [True: 0, False: 0]
116
0
    case OP_NUMNOTEQUAL            : return "OP_NUMNOTEQUAL";
  Branch (116:5): [True: 0, False: 0]
117
0
    case OP_LESSTHAN               : return "OP_LESSTHAN";
  Branch (117:5): [True: 0, False: 0]
118
0
    case OP_GREATERTHAN            : return "OP_GREATERTHAN";
  Branch (118:5): [True: 0, False: 0]
119
0
    case OP_LESSTHANOREQUAL        : return "OP_LESSTHANOREQUAL";
  Branch (119:5): [True: 0, False: 0]
120
0
    case OP_GREATERTHANOREQUAL     : return "OP_GREATERTHANOREQUAL";
  Branch (120:5): [True: 0, False: 0]
121
0
    case OP_MIN                    : return "OP_MIN";
  Branch (121:5): [True: 0, False: 0]
122
0
    case OP_MAX                    : return "OP_MAX";
  Branch (122:5): [True: 0, False: 0]
123
0
    case OP_WITHIN                 : return "OP_WITHIN";
  Branch (123:5): [True: 0, False: 0]
124
125
    // crypto
126
0
    case OP_RIPEMD160              : return "OP_RIPEMD160";
  Branch (126:5): [True: 0, False: 0]
127
0
    case OP_SHA1                   : return "OP_SHA1";
  Branch (127:5): [True: 0, False: 0]
128
0
    case OP_SHA256                 : return "OP_SHA256";
  Branch (128:5): [True: 0, False: 0]
129
0
    case OP_HASH160                : return "OP_HASH160";
  Branch (129:5): [True: 0, False: 0]
130
0
    case OP_HASH256                : return "OP_HASH256";
  Branch (130:5): [True: 0, False: 0]
131
0
    case OP_CODESEPARATOR          : return "OP_CODESEPARATOR";
  Branch (131:5): [True: 0, False: 0]
132
0
    case OP_CHECKSIG               : return "OP_CHECKSIG";
  Branch (132:5): [True: 0, False: 0]
133
0
    case OP_CHECKSIGVERIFY         : return "OP_CHECKSIGVERIFY";
  Branch (133:5): [True: 0, False: 0]
134
0
    case OP_CHECKMULTISIG          : return "OP_CHECKMULTISIG";
  Branch (134:5): [True: 0, False: 0]
135
0
    case OP_CHECKMULTISIGVERIFY    : return "OP_CHECKMULTISIGVERIFY";
  Branch (135:5): [True: 0, False: 0]
136
137
    // expansion
138
0
    case OP_NOP1                   : return "OP_NOP1";
  Branch (138:5): [True: 0, False: 0]
139
0
    case OP_CHECKLOCKTIMEVERIFY    : return "OP_CHECKLOCKTIMEVERIFY";
  Branch (139:5): [True: 0, False: 0]
140
0
    case OP_CHECKSEQUENCEVERIFY    : return "OP_CHECKSEQUENCEVERIFY";
  Branch (140:5): [True: 0, False: 0]
141
0
    case OP_NOP4                   : return "OP_NOP4";
  Branch (141:5): [True: 0, False: 0]
142
0
    case OP_NOP5                   : return "OP_NOP5";
  Branch (142:5): [True: 0, False: 0]
143
0
    case OP_NOP6                   : return "OP_NOP6";
  Branch (143:5): [True: 0, False: 0]
144
0
    case OP_NOP7                   : return "OP_NOP7";
  Branch (144:5): [True: 0, False: 0]
145
0
    case OP_NOP8                   : return "OP_NOP8";
  Branch (145:5): [True: 0, False: 0]
146
0
    case OP_NOP9                   : return "OP_NOP9";
  Branch (146:5): [True: 0, False: 0]
147
0
    case OP_NOP10                  : return "OP_NOP10";
  Branch (147:5): [True: 0, False: 0]
148
149
    // Opcode added by BIP 342 (Tapscript)
150
0
    case OP_CHECKSIGADD            : return "OP_CHECKSIGADD";
  Branch (150:5): [True: 0, False: 0]
151
152
0
    case OP_INVALIDOPCODE          : return "OP_INVALIDOPCODE";
  Branch (152:5): [True: 0, False: 0]
153
154
0
    default:
  Branch (154:5): [True: 0, False: 0]
155
0
        return "OP_UNKNOWN";
156
0
    }
157
0
}
158
159
unsigned int CScript::GetSigOpCount(bool fAccurate) const
160
14.2M
{
161
14.2M
    unsigned int n = 0;
162
14.2M
    const_iterator pc = begin();
163
14.2M
    opcodetype lastOpcode = OP_INVALIDOPCODE;
164
42.0M
    while (pc < end())
  Branch (164:12): [True: 27.8M, False: 14.2M]
165
27.8M
    {
166
27.8M
        opcodetype opcode;
167
27.8M
        if (!GetOp(pc, opcode))
  Branch (167:13): [True: 4.15k, False: 27.8M]
168
4.15k
            break;
169
27.8M
        if (opcode == OP_CHECKSIG || opcode == OP_CHECKSIGVERIFY)
  Branch (169:13): [True: 12.2k, False: 27.8M]
  Branch (169:38): [True: 810, False: 27.8M]
170
13.0k
            n++;
171
27.8M
        else if (opcode == OP_CHECKMULTISIG || opcode == OP_CHECKMULTISIGVERIFY)
  Branch (171:18): [True: 1.48k, False: 27.8M]
  Branch (171:48): [True: 1.60k, False: 27.8M]
172
3.09k
        {
173
3.09k
            if (fAccurate && lastOpcode >= OP_1 && lastOpcode <= OP_16)
  Branch (173:17): [True: 3.09k, False: 0]
  Branch (173:30): [True: 2.98k, False: 106]
  Branch (173:52): [True: 623, False: 2.36k]
174
623
                n += DecodeOP_N(lastOpcode);
175
2.47k
            else
176
2.47k
                n += MAX_PUBKEYS_PER_MULTISIG;
177
3.09k
        }
178
27.8M
        lastOpcode = opcode;
179
27.8M
    }
180
14.2M
    return n;
181
14.2M
}
182
183
unsigned int CScript::GetSigOpCount(const CScript& scriptSig) const
184
4.35k
{
185
4.35k
    if (!IsPayToScriptHash())
  Branch (185:9): [True: 0, False: 4.35k]
186
0
        return GetSigOpCount(true);
187
188
    // This is a pay-to-script-hash scriptPubKey;
189
    // get the last item that the scriptSig
190
    // pushes onto the stack:
191
4.35k
    const_iterator pc = scriptSig.begin();
192
4.35k
    std::vector<unsigned char> vData;
193
21.1k
    while (pc < scriptSig.end())
  Branch (193:12): [True: 16.8k, False: 4.35k]
194
16.8k
    {
195
16.8k
        opcodetype opcode;
196
16.8k
        if (!scriptSig.GetOp(pc, opcode, vData))
  Branch (196:13): [True: 0, False: 16.8k]
197
0
            return 0;
198
16.8k
        if (opcode > OP_16)
  Branch (198:13): [True: 0, False: 16.8k]
199
0
            return 0;
200
16.8k
    }
201
202
    /// ... and return its opcount:
203
4.35k
    CScript subscript(vData.begin(), vData.end());
204
4.35k
    return subscript.GetSigOpCount(true);
205
4.35k
}
206
207
bool CScript::IsPayToAnchor() const
208
98.5k
{
209
98.5k
    return (this->size() == 4 &&
  Branch (209:13): [True: 38.1k, False: 60.3k]
210
98.5k
        (*this)[0] == OP_1 &&
  Branch (210:9): [True: 38.1k, False: 1]
211
98.5k
        (*this)[1] == 0x02 &&
  Branch (211:9): [True: 38.1k, False: 0]
212
98.5k
        (*this)[2] == 0x4e &&
  Branch (212:9): [True: 38.1k, False: 0]
213
98.5k
        (*this)[3] == 0x73);
  Branch (213:9): [True: 38.1k, False: 0]
214
98.5k
}
215
216
bool CScript::IsPayToAnchor(int version, const std::vector<unsigned char>& program)
217
2.89k
{
218
2.89k
    return version == 1 &&
  Branch (218:12): [True: 2.89k, False: 0]
219
2.89k
        program.size() == 2 &&
  Branch (219:9): [True: 2.89k, False: 0]
220
2.89k
        program[0] == 0x4e &&
  Branch (220:9): [True: 2.89k, False: 0]
221
2.89k
        program[1] == 0x73;
  Branch (221:9): [True: 2.89k, False: 0]
222
2.89k
}
223
224
bool CScript::IsPayToScriptHash() const
225
804k
{
226
    // Extra-fast test for pay-to-script-hash CScripts:
227
804k
    return (this->size() == 23 &&
  Branch (227:13): [True: 38.8k, False: 765k]
228
804k
            (*this)[0] == OP_HASH160 &&
  Branch (228:13): [True: 38.8k, False: 1]
229
804k
            (*this)[1] == 0x14 &&
  Branch (229:13): [True: 38.8k, False: 0]
230
804k
            (*this)[22] == OP_EQUAL);
  Branch (230:13): [True: 38.8k, False: 0]
231
804k
}
232
233
bool CScript::IsPayToWitnessScriptHash() const
234
0
{
235
    // Extra-fast test for pay-to-witness-script-hash CScripts:
236
0
    return (this->size() == 34 &&
  Branch (236:13): [True: 0, False: 0]
237
0
            (*this)[0] == OP_0 &&
  Branch (237:13): [True: 0, False: 0]
238
0
            (*this)[1] == 0x20);
  Branch (238:13): [True: 0, False: 0]
239
0
}
240
241
bool CScript::IsPayToTaproot() const
242
0
{
243
0
    return (this->size() == 34 &&
  Branch (243:13): [True: 0, False: 0]
244
0
            (*this)[0] == OP_1 &&
  Branch (244:13): [True: 0, False: 0]
245
0
            (*this)[1] == 0x20);
  Branch (245:13): [True: 0, False: 0]
246
0
}
247
248
// A witness program is any valid CScript that consists of a 1-byte push opcode
249
// followed by a data push between 2 and 40 bytes.
250
bool CScript::IsWitnessProgram(int& version, std::vector<unsigned char>& program) const
251
1.29M
{
252
1.29M
    if (this->size() < 4 || this->size() > 42) {
  Branch (252:9): [True: 3.33k, False: 1.29M]
  Branch (252:29): [True: 44.9k, False: 1.24M]
253
48.0k
        return false;
254
48.0k
    }
255
1.24M
    if ((*this)[0] != OP_0 && ((*this)[0] < OP_1 || (*this)[0] > OP_16)) {
  Branch (255:9): [True: 128k, False: 1.11M]
  Branch (255:32): [True: 334, False: 128k]
  Branch (255:53): [True: 34.3k, False: 93.8k]
256
34.6k
        return false;
257
34.6k
    }
258
1.21M
    if ((size_t)((*this)[1] + 2) == this->size()) {
  Branch (258:9): [True: 1.21M, False: 930]
259
1.21M
        version = DecodeOP_N((opcodetype)(*this)[0]);
260
1.21M
        program = std::vector<unsigned char>(this->begin() + 2, this->end());
261
1.21M
        return true;
262
1.21M
    }
263
930
    return false;
264
1.21M
}
265
266
bool CScript::IsPushOnly(const_iterator pc) const
267
535k
{
268
702k
    while (pc < end())
  Branch (268:12): [True: 167k, False: 535k]
269
167k
    {
270
167k
        opcodetype opcode;
271
167k
        if (!GetOp(pc, opcode))
  Branch (271:13): [True: 51, False: 167k]
272
51
            return false;
273
        // Note that IsPushOnly() *does* consider OP_RESERVED to be a
274
        // push-type opcode, however execution of OP_RESERVED fails, so
275
        // it's not relevant to P2SH/BIP62 as the scriptSig would fail prior to
276
        // the P2SH special validation code being executed.
277
167k
        if (opcode > OP_16)
  Branch (277:13): [True: 18, False: 167k]
278
18
            return false;
279
167k
    }
280
535k
    return true;
281
535k
}
282
283
bool CScript::IsPushOnly() const
284
491k
{
285
491k
    return this->IsPushOnly(begin());
286
491k
}
287
288
std::string CScriptWitness::ToString() const
289
0
{
290
0
    std::string ret = "CScriptWitness(";
291
0
    for (unsigned int i = 0; i < stack.size(); i++) {
  Branch (291:30): [True: 0, False: 0]
292
0
        if (i) {
  Branch (292:13): [True: 0, False: 0]
293
0
            ret += ", ";
294
0
        }
295
0
        ret += HexStr(stack[i]);
296
0
    }
297
0
    return ret + ")";
298
0
}
299
300
bool CScript::HasValidOps() const
301
0
{
302
0
    CScript::const_iterator it = begin();
303
0
    while (it < end()) {
  Branch (303:12): [True: 0, False: 0]
304
0
        opcodetype opcode;
305
0
        std::vector<unsigned char> item;
306
0
        if (!GetOp(it, opcode, item) || opcode > MAX_OPCODE || item.size() > MAX_SCRIPT_ELEMENT_SIZE) {
  Branch (306:13): [True: 0, False: 0]
  Branch (306:41): [True: 0, False: 0]
  Branch (306:64): [True: 0, False: 0]
307
0
            return false;
308
0
        }
309
0
    }
310
0
    return true;
311
0
}
312
313
bool GetScriptOp(CScriptBase::const_iterator& pc, CScriptBase::const_iterator end, opcodetype& opcodeRet, std::vector<unsigned char>* pvchRet)
314
28.5M
{
315
28.5M
    opcodeRet = OP_INVALIDOPCODE;
316
28.5M
    if (pvchRet)
  Branch (316:9): [True: 536k, False: 28.0M]
317
536k
        pvchRet->clear();
318
28.5M
    if (pc >= end)
  Branch (318:9): [True: 831, False: 28.5M]
319
831
        return false;
320
321
    // Read instruction
322
28.5M
    if (end - pc < 1)
  Branch (322:9): [True: 0, False: 28.5M]
323
0
        return false;
324
28.5M
    unsigned int opcode = *pc++;
325
326
    // Immediate operand
327
28.5M
    if (opcode <= OP_PUSHDATA4)
  Branch (327:9): [True: 23.2M, False: 5.36M]
328
23.2M
    {
329
23.2M
        unsigned int nSize = 0;
330
23.2M
        if (opcode < OP_PUSHDATA1)
  Branch (330:13): [True: 23.1M, False: 83.4k]
331
23.1M
        {
332
23.1M
            nSize = opcode;
333
23.1M
        }
334
83.4k
        else if (opcode == OP_PUSHDATA1)
  Branch (334:18): [True: 9.27k, False: 74.1k]
335
9.27k
        {
336
9.27k
            if (end - pc < 1)
  Branch (336:17): [True: 92, False: 9.18k]
337
92
                return false;
338
9.18k
            nSize = *pc++;
339
9.18k
        }
340
74.1k
        else if (opcode == OP_PUSHDATA2)
  Branch (340:18): [True: 7.15k, False: 66.9k]
341
7.15k
        {
342
7.15k
            if (end - pc < 2)
  Branch (342:17): [True: 216, False: 6.93k]
343
216
                return false;
344
6.93k
            nSize = ReadLE16(&pc[0]);
345
6.93k
            pc += 2;
346
6.93k
        }
347
66.9k
        else if (opcode == OP_PUSHDATA4)
  Branch (347:18): [True: 66.9k, False: 18.4E]
348
66.9k
        {
349
66.9k
            if (end - pc < 4)
  Branch (349:17): [True: 149, False: 66.8k]
350
149
                return false;
351
66.8k
            nSize = ReadLE32(&pc[0]);
352
66.8k
            pc += 4;
353
66.8k
        }
354
23.2M
        if (end - pc < 0 || (unsigned int)(end - pc) < nSize)
  Branch (354:13): [True: 107, False: 23.2M]
  Branch (354:29): [True: 6.04k, False: 23.2M]
355
5.75k
            return false;
356
23.2M
        if (pvchRet)
  Branch (356:13): [True: 334k, False: 22.8M]
357
334k
            pvchRet->assign(pc, pc + nSize);
358
23.2M
        pc += nSize;
359
23.2M
    }
360
361
28.5M
    opcodeRet = static_cast<opcodetype>(opcode);
362
28.5M
    return true;
363
28.5M
}
364
365
bool IsOpSuccess(const opcodetype& opcode)
366
0
{
367
0
    return opcode == 80 || opcode == 98 || (opcode >= 126 && opcode <= 129) ||
  Branch (367:12): [True: 0, False: 0]
  Branch (367:28): [True: 0, False: 0]
  Branch (367:45): [True: 0, False: 0]
  Branch (367:62): [True: 0, False: 0]
368
0
           (opcode >= 131 && opcode <= 134) || (opcode >= 137 && opcode <= 138) ||
  Branch (368:13): [True: 0, False: 0]
  Branch (368:30): [True: 0, False: 0]
  Branch (368:49): [True: 0, False: 0]
  Branch (368:66): [True: 0, False: 0]
369
0
           (opcode >= 141 && opcode <= 142) || (opcode >= 149 && opcode <= 153) ||
  Branch (369:13): [True: 0, False: 0]
  Branch (369:30): [True: 0, False: 0]
  Branch (369:49): [True: 0, False: 0]
  Branch (369:66): [True: 0, False: 0]
370
0
           (opcode >= 187 && opcode <= 254);
  Branch (370:13): [True: 0, False: 0]
  Branch (370:30): [True: 0, False: 0]
371
0
}
372
373
131k
bool CheckMinimalPush(const std::vector<unsigned char>& data, opcodetype opcode) {
374
    // Excludes OP_1NEGATE, OP_1-16 since they are by definition minimal
375
131k
    assert(0 <= opcode && opcode <= OP_PUSHDATA4);
  Branch (375:5): [True: 131k, False: 0]
  Branch (375:5): [True: 131k, False: 0]
  Branch (375:5): [True: 131k, False: 0]
376
131k
    if (data.size() == 0) {
  Branch (376:9): [True: 59.8k, False: 71.3k]
377
        // Should have used OP_0.
378
59.8k
        return opcode == OP_0;
379
71.3k
    } else if (data.size() == 1 && data[0] >= 1 && data[0] <= 16) {
  Branch (379:16): [True: 2.49k, False: 68.8k]
  Branch (379:36): [True: 2.33k, False: 159]
  Branch (379:52): [True: 72, False: 2.25k]
380
        // Should have used OP_1 .. OP_16.
381
72
        return false;
382
71.3k
    } else if (data.size() == 1 && data[0] == 0x81) {
  Branch (382:16): [True: 2.41k, False: 68.8k]
  Branch (382:36): [True: 15, False: 2.40k]
383
        // Should have used OP_1NEGATE.
384
15
        return false;
385
71.2k
    } else if (data.size() <= 75) {
  Branch (385:16): [True: 69.8k, False: 1.45k]
386
        // Must have used a direct push (opcode indicating number of bytes pushed + those bytes).
387
69.8k
        return opcode == data.size();
388
69.8k
    } else if (data.size() <= 255) {
  Branch (388:16): [True: 1.21k, False: 243]
389
        // Must have used OP_PUSHDATA.
390
1.21k
        return opcode == OP_PUSHDATA1;
391
1.21k
    } else if (data.size() <= 65535) {
  Branch (391:16): [True: 243, False: 0]
392
        // Must have used OP_PUSHDATA2.
393
243
        return opcode == OP_PUSHDATA2;
394
243
    }
395
0
    return true;
396
131k
}