Skip to content

Commit a1c7d20

Browse files
committed
Implement SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS
1 parent 8630c48 commit a1c7d20

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

bitcoin/core/scripteval.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,9 +591,15 @@ def check_args(n):
591591
check_args(2)
592592
del stack[-2]
593593

594-
elif sop == OP_NOP or (sop >= OP_NOP1 and sop <= OP_NOP10):
594+
elif sop == OP_NOP:
595595
pass
596596

597+
elif sop >= OP_NOP1 and sop <= OP_NOP10:
598+
if SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS in flags:
599+
err_raiser(EvalScriptError, "%s reserved for soft-fork upgrades" % OPCODE_NAMES[sop])
600+
else:
601+
pass
602+
597603
elif sop == OP_OVER:
598604
check_args(2)
599605
vch = stack[-2]

bitcoin/tests/data/script_invalid.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,23 @@
163163
["1","NOP1 CHECKLOCKTIMEVERIFY NOP3 NOP4 NOP5 NOP6 NOP7 NOP8 NOP9 NOP10 2 EQUAL", "P2SH,STRICTENC"],
164164
["'NOP_1_to_10' NOP1 CHECKLOCKTIMEVERIFY NOP3 NOP4 NOP5 NOP6 NOP7 NOP8 NOP9 NOP10","'NOP_1_to_11' EQUAL", "P2SH,STRICTENC"],
165165

166+
["Ensure 100% coverage of discouraged NOPS"],
167+
["1", "NOP1", "P2SH,DISCOURAGE_UPGRADABLE_NOPS"],
168+
["1", "CHECKLOCKTIMEVERIFY", "P2SH,DISCOURAGE_UPGRADABLE_NOPS"],
169+
["1", "NOP3", "P2SH,DISCOURAGE_UPGRADABLE_NOPS"],
170+
["1", "NOP4", "P2SH,DISCOURAGE_UPGRADABLE_NOPS"],
171+
["1", "NOP5", "P2SH,DISCOURAGE_UPGRADABLE_NOPS"],
172+
["1", "NOP6", "P2SH,DISCOURAGE_UPGRADABLE_NOPS"],
173+
["1", "NOP7", "P2SH,DISCOURAGE_UPGRADABLE_NOPS"],
174+
["1", "NOP8", "P2SH,DISCOURAGE_UPGRADABLE_NOPS"],
175+
["1", "NOP9", "P2SH,DISCOURAGE_UPGRADABLE_NOPS"],
176+
["1", "NOP10", "P2SH,DISCOURAGE_UPGRADABLE_NOPS"],
177+
178+
["NOP10", "1", "P2SH,DISCOURAGE_UPGRADABLE_NOPS", "Discouraged NOP10 in scriptSig"],
179+
180+
["1 0x01 0xb9", "HASH160 0x14 0x15727299b05b45fdaf9ac9ecf7565cfe27c3e567 EQUAL",
181+
"P2SH,DISCOURAGE_UPGRADABLE_NOPS", "Discouraged NOP10 in redeemScript"],
182+
166183
["0x50","1", "P2SH,STRICTENC", "opcode 0x50 is reserved"],
167184
["1", "IF 0xba ELSE 1 ENDIF", "P2SH,STRICTENC", "opcodes above NOP10 invalid if executed"],
168185
["1", "IF 0xbb ELSE 1 ENDIF", "P2SH,STRICTENC"],

0 commit comments

Comments
 (0)