|
3 | 3 | verify_stack_after_op = False
|
4 | 4 |
|
5 | 5 | # ######################################
|
| 6 | +import sys |
| 7 | + |
6 | 8 | from ethereum import utils
|
7 | 9 | from ethereum.abi import is_numeric
|
8 | 10 | import copy
|
@@ -83,16 +85,29 @@ def __init__(self, **kwargs):
|
83 | 85 | # Preprocesses code, and determines which locations are in the middle
|
84 | 86 | # of pushdata and thus invalid
|
85 | 87 | def preprocess_code(code):
|
86 |
| - assert isinstance(code, str) |
| 88 | + assert isinstance(code, (str, bytes)) |
| 89 | + |
| 90 | + # python3 does not require ord() on byte strings |
| 91 | + if sys.version_info.major == 2: |
| 92 | + if isinstance(code, bytes): |
| 93 | + code = str(code) |
| 94 | + |
| 95 | + def t_ord(char): |
| 96 | + return ord(char) |
| 97 | + else: |
| 98 | + assert isinstance(code, bytes) |
| 99 | + def t_ord(char): |
| 100 | + return char |
| 101 | + |
87 | 102 | i = 0
|
88 | 103 | ops = []
|
89 | 104 | while i < len(code):
|
90 |
| - o = copy.copy(opcodes.opcodes.get(ord(code[i]), ['INVALID', 0, 0, 0]) + [ord(code[i]), 0]) |
| 105 | + o = copy.copy(opcodes.opcodes.get(t_ord(code[i]), ['INVALID', 0, 0, 0]) + [t_ord(code[i]), 0]) |
91 | 106 | ops.append(o)
|
92 | 107 | if o[0][:4] == 'PUSH':
|
93 | 108 | for j in range(int(o[0][4:])):
|
94 | 109 | i += 1
|
95 |
| - byte = ord(code[i]) if i < len(code) else 0 |
| 110 | + byte = t_ord(code[i]) if i < len(code) else 0 |
96 | 111 | o[-1] = (o[-1] << 8) + byte
|
97 | 112 | if i < len(code):
|
98 | 113 | ops.append(['INVALID', 0, 0, 0, byte, 0])
|
|
0 commit comments