Skip to content

Commit 8b85aca

Browse files
author
Bob McElrath
committed
Interpret 0x00 as OP_0 instead of b''
1 parent ecd7c71 commit 8b85aca

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

bitcoin/core/script.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,9 @@ def __iter__(self):
621621
PUSHDATA encodings.
622622
"""
623623
for (opcode, data, sop_idx) in self.raw_iter():
624-
if data is not None:
624+
if opcode == 0:
625+
yield 0
626+
elif data is not None:
625627
yield data
626628
else:
627629
opcode = CScriptOp(opcode)

bitcoin/tests/test_script.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def T(serialized_script, expected_tokens, test_roundtrip=True):
9595
T('', [])
9696

9797
# standard pushdata
98-
T('00', [b''])
98+
T('00', [OP_0])
9999
T('0100', [b'\x00'])
100100
T('4b' + 'ff'*0x4b, [b'\xff'*0x4b])
101101

@@ -108,6 +108,7 @@ def T(serialized_script, expected_tokens, test_roundtrip=True):
108108
T('4e04000000deadbeef', [x('deadbeef')], False)
109109

110110
# numbers
111+
T('00', [0x0])
111112
T('4f', [OP_1NEGATE])
112113
T('51', [0x1])
113114
T('52', [0x2])
@@ -240,7 +241,7 @@ def T(script, expected_repr):
240241
"CScript([1, x('7ac977d8373df875eceda362298e5d09d4b72b53'), OP_DROP])")
241242

242243
T(CScript(x('0001ff515261ff')),
243-
"CScript([x(''), x('ff'), 1, 2, OP_NOP, OP_INVALIDOPCODE])")
244+
"CScript([0, x('ff'), 1, 2, OP_NOP, OP_INVALIDOPCODE])")
244245

245246
# truncated scripts
246247
T(CScript(x('6101')),

0 commit comments

Comments
 (0)