Skip to content

Commit 59e7a11

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. [ yapified by gitreformat (github/ghtdak) on Mon Nov 30 21:11:09 2015 ]
1 parent f83f9bf commit 59e7a11

2 files changed

Lines changed: 8 additions & 121 deletions

File tree

bitcoin/core/script.py

Lines changed: 7 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -247,120 +247,6 @@ def __new__(cls, n):
247247

248248
OP_INVALIDOPCODE = CScriptOp(0xff)
249249

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

487+
# Invalid even when occuring in an unexecuted OP_IF branch due to either being
488+
# disabled, or never having been implemented.
489+
DISABLED_OPCODES = frozenset(
490+
(OP_VERIF, OP_VERNOTIF, OP_CAT, OP_SUBSTR, OP_LEFT, OP_RIGHT, OP_INVERT,
491+
OP_AND, OP_OR, OP_XOR, OP_2MUL, OP_2DIV, OP_MUL, OP_DIV, OP_MOD, OP_LSHIFT,
492+
OP_RSHIFT))
493+
601494

602495
class CScriptInvalidError(Exception):
603496
"""Base class for CScript exceptions"""

bitcoin/core/scripteval.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@
4040
SCRIPT_VERIFY_EVEN_S = object()
4141
SCRIPT_VERIFY_NOCACHE = object()
4242

43-
# Invalid even when occuring in an unexecuted OP_IF branch due to either being
44-
# disabled, or never implemented.
45-
disabled_opcodes = set((OP_VERIF, OP_VERNOTIF, OP_CAT, OP_SUBSTR, OP_LEFT,
46-
OP_RIGHT, OP_INVERT, OP_AND, OP_OR, OP_XOR, OP_2MUL,
47-
OP_2DIV, OP_MUL, OP_DIV, OP_MOD, OP_LSHIFT, OP_RSHIFT))
48-
4943

5044
class EvalScriptError(bitcoin.core.ValidationError):
5145
"""Base class for exceptions raised when a script fails during EvalScript()
@@ -396,7 +390,7 @@ def err_raiser(cls, *args):
396390
pbegincodehash=pbegincodehash,
397391
nOpCount=nOpCount[0])
398392

399-
if sop in disabled_opcodes:
393+
if sop in DISABLED_OPCODES:
400394
err_raiser(EvalScriptError, 'opcode %s is disabled' %
401395
OPCODE_NAMES[sop])
402396

0 commit comments

Comments
 (0)