Skip to content

Commit 8d8ad1c

Browse files
committed
Make DISABLED_OPCODES a constant
Also remove VALID_OPCODES as it's not used in the code itself, thus not tested by anything; use DISABLED_OPCODES instead. Thanks to Isaac Cook for pointing this out.
1 parent 9f04d18 commit 8d8ad1c

File tree

2 files changed

+8
-133
lines changed

2 files changed

+8
-133
lines changed

bitcoin/core/script.py

Lines changed: 7 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -246,131 +246,6 @@ def __new__(cls, n):
246246

247247
OP_INVALIDOPCODE = CScriptOp(0xff)
248248

249-
VALID_OPCODES = {
250-
OP_1NEGATE,
251-
OP_RESERVED,
252-
OP_1,
253-
OP_2,
254-
OP_3,
255-
OP_4,
256-
OP_5,
257-
OP_6,
258-
OP_7,
259-
OP_8,
260-
OP_9,
261-
OP_10,
262-
OP_11,
263-
OP_12,
264-
OP_13,
265-
OP_14,
266-
OP_15,
267-
OP_16,
268-
269-
OP_NOP,
270-
OP_VER,
271-
OP_IF,
272-
OP_NOTIF,
273-
OP_VERIF,
274-
OP_VERNOTIF,
275-
OP_ELSE,
276-
OP_ENDIF,
277-
OP_VERIFY,
278-
OP_RETURN,
279-
280-
OP_TOALTSTACK,
281-
OP_FROMALTSTACK,
282-
OP_2DROP,
283-
OP_2DUP,
284-
OP_3DUP,
285-
OP_2OVER,
286-
OP_2ROT,
287-
OP_2SWAP,
288-
OP_IFDUP,
289-
OP_DEPTH,
290-
OP_DROP,
291-
OP_DUP,
292-
OP_NIP,
293-
OP_OVER,
294-
OP_PICK,
295-
OP_ROLL,
296-
OP_ROT,
297-
OP_SWAP,
298-
OP_TUCK,
299-
300-
OP_CAT,
301-
OP_SUBSTR,
302-
OP_LEFT,
303-
OP_RIGHT,
304-
OP_SIZE,
305-
306-
OP_INVERT,
307-
OP_AND,
308-
OP_OR,
309-
OP_XOR,
310-
OP_EQUAL,
311-
OP_EQUALVERIFY,
312-
OP_RESERVED1,
313-
OP_RESERVED2,
314-
315-
OP_1ADD,
316-
OP_1SUB,
317-
OP_2MUL,
318-
OP_2DIV,
319-
OP_NEGATE,
320-
OP_ABS,
321-
OP_NOT,
322-
OP_0NOTEQUAL,
323-
324-
OP_ADD,
325-
OP_SUB,
326-
OP_MUL,
327-
OP_DIV,
328-
OP_MOD,
329-
OP_LSHIFT,
330-
OP_RSHIFT,
331-
332-
OP_BOOLAND,
333-
OP_BOOLOR,
334-
OP_NUMEQUAL,
335-
OP_NUMEQUALVERIFY,
336-
OP_NUMNOTEQUAL,
337-
OP_LESSTHAN,
338-
OP_GREATERTHAN,
339-
OP_LESSTHANOREQUAL,
340-
OP_GREATERTHANOREQUAL,
341-
OP_MIN,
342-
OP_MAX,
343-
344-
OP_WITHIN,
345-
346-
OP_RIPEMD160,
347-
OP_SHA1,
348-
OP_SHA256,
349-
OP_HASH160,
350-
OP_HASH256,
351-
OP_CODESEPARATOR,
352-
OP_CHECKSIG,
353-
OP_CHECKSIGVERIFY,
354-
OP_CHECKMULTISIG,
355-
OP_CHECKMULTISIGVERIFY,
356-
357-
OP_NOP1,
358-
OP_NOP2,
359-
OP_NOP3,
360-
OP_NOP4,
361-
OP_NOP5,
362-
OP_NOP6,
363-
OP_NOP7,
364-
OP_NOP8,
365-
OP_NOP9,
366-
OP_NOP10,
367-
368-
OP_SMALLINTEGER,
369-
OP_PUBKEYS,
370-
OP_PUBKEYHASH,
371-
OP_PUBKEY,
372-
}
373-
374249
OPCODE_NAMES.update({
375250
OP_0: 'OP_0',
376251
OP_PUSHDATA1: 'OP_PUSHDATA1',
@@ -608,6 +483,13 @@ def __new__(cls, n):
608483
'OP_PUBKEY': OP_PUBKEY,
609484
}
610485

486+
# Invalid even when occuring in an unexecuted OP_IF branch due to either being
487+
# disabled, or never having been implemented.
488+
DISABLED_OPCODES = frozenset((OP_VERIF, OP_VERNOTIF,
489+
OP_CAT, OP_SUBSTR, OP_LEFT, OP_RIGHT, OP_INVERT, OP_AND,
490+
OP_OR, OP_XOR, OP_2MUL, OP_2DIV, OP_MUL, OP_DIV, OP_MOD,
491+
OP_LSHIFT, OP_RSHIFT))
492+
611493
class CScriptInvalidError(Exception):
612494
"""Base class for CScript exceptions"""
613495
pass

bitcoin/core/scripteval.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@
4141
SCRIPT_VERIFY_EVEN_S = object()
4242
SCRIPT_VERIFY_NOCACHE = object()
4343

44-
# Invalid even when occuring in an unexecuted OP_IF branch due to either being
45-
# disabled, or never implemented.
46-
disabled_opcodes = set((OP_VERIF, OP_VERNOTIF,
47-
OP_CAT, OP_SUBSTR, OP_LEFT, OP_RIGHT, OP_INVERT, OP_AND,
48-
OP_OR, OP_XOR, OP_2MUL, OP_2DIV, OP_MUL, OP_DIV, OP_MOD,
49-
OP_LSHIFT, OP_RSHIFT))
50-
5144
class EvalScriptError(bitcoin.core.ValidationError):
5245
"""Base class for exceptions raised when a script fails during EvalScript()
5346
@@ -377,7 +370,7 @@ def err_raiser(cls, *args):
377370
altstack=altstack, vfExec=vfExec, pbegincodehash=pbegincodehash, nOpCount=nOpCount[0])
378371

379372

380-
if sop in disabled_opcodes:
373+
if sop in DISABLED_OPCODES:
381374
err_raiser(EvalScriptError, 'opcode %s is disabled' % OPCODE_NAMES[sop])
382375

383376
if sop > OP_16:

0 commit comments

Comments
 (0)