Skip to content

Commit 62fc259

Browse files
committed
Implement SCRIPT_VERIFY_NULLDUMMY
1 parent 2c8883e commit 62fc259

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

bitcoin/core/scripteval.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def _CheckSig(sig, pubkey, script, txTo, inIdx, err_raiser):
152152
return key.verify(h, sig)
153153

154154

155-
def _CheckMultiSig(opcode, script, stack, txTo, inIdx, err_raiser, nOpCount):
155+
def _CheckMultiSig(opcode, script, stack, txTo, inIdx, flags, err_raiser, nOpCount):
156156
i = 1
157157
if len(stack) < i:
158158
err_raiser(MissingOpArgumentsError, opcode, stack, i)
@@ -209,10 +209,18 @@ def _CheckMultiSig(opcode, script, stack, txTo, inIdx, err_raiser, nOpCount):
209209
if opcode == OP_CHECKMULTISIGVERIFY:
210210
err_raiser(VerifyOpFailedError, opcode)
211211

212-
while i > 0:
212+
while i > 1:
213213
stack.pop()
214214
i -= 1
215215

216+
# Note how Bitcoin Core duplicates the len(stack) check, rather than
217+
# letting pop() handle it; maybe that's wrong?
218+
if len(stack) and SCRIPT_VERIFY_NULLDUMMY in flags:
219+
if stack[-1] != b'':
220+
raise err_raiser(ArgumentsInvalidError, opcode, "dummy value not OP_0")
221+
222+
stack.pop()
223+
216224
if opcode == OP_CHECKMULTISIG:
217225
if success:
218226
stack.append(b"\x01")
@@ -478,7 +486,7 @@ def check_args(n):
478486

479487
elif sop == OP_CHECKMULTISIG or sop == OP_CHECKMULTISIGVERIFY:
480488
tmpScript = CScript(scriptIn[pbegincodehash:])
481-
_CheckMultiSig(sop, tmpScript, stack, txTo, inIdx, err_raiser, nOpCount)
489+
_CheckMultiSig(sop, tmpScript, stack, txTo, inIdx, flags, err_raiser, nOpCount)
482490

483491
elif sop == OP_CHECKSIG or sop == OP_CHECKSIGVERIFY:
484492
check_args(2)

bitcoin/tests/data/script_invalid.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,18 @@
509509
"STRICTENC",
510510
"P2PK NOT with hybrid pubkey"
511511
],
512+
[
513+
"1 0x47 0x3044022051254b9fb476a52d85530792b578f86fea70ec1ffb4393e661bcccb23d8d63d3022076505f94a403c86097841944e044c70c2045ce90e36de51f7e9d3828db98a07501 0x47 0x304402200a358f750934b3feb822f1966bfcd8bbec9eeaa3a8ca941e11ee5960e181fa01022050bf6b5a8e7750f70354ae041cb68a7bade67ec6c3ab19eb359638974410626e01 0x47 0x304402200955d031fff71d8653221e85e36c3c85533d2312fc3045314b19650b7ae2f81002202a6bb8505e36201909d0921f01abff390ae6b7ff97bbf959f98aedeb0a56730901",
514+
"3 0x21 0x0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 0x21 0x03363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640 3 CHECKMULTISIG",
515+
"NULLDUMMY",
516+
"3-of-3 with nonzero dummy"
517+
],
518+
[
519+
"1 0x47 0x304402201bb2edab700a5d020236df174fefed78087697143731f659bea59642c759c16d022061f42cdbae5bcd3e8790f20bf76687443436e94a634321c16a72aa54cbc7c2ea01 0x47 0x304402204bb4a64f2a6e5c7fb2f07fef85ee56fde5e6da234c6a984262307a20e99842d702206f8303aaba5e625d223897e2ffd3f88ef1bcffef55f38dc3768e5f2e94c923f901 0x47 0x3044022040c2809b71fffb155ec8b82fe7a27f666bd97f941207be4e14ade85a1249dd4d02204d56c85ec525dd18e29a0533d5ddf61b6b1bb32980c2f63edf951aebf7a27bfe01",
520+
"3 0x21 0x0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 0x21 0x038282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508 0x21 0x03363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640 3 CHECKMULTISIG NOT",
521+
"NULLDUMMY",
522+
"3-of-3 NOT with invalid sig with nonzero dummy"
523+
],
512524
[
513525
"0x47 0x304402203e4516da7253cf068effec6b95c41221c0cf3a8e6ccb8cbf1725b562e9afde2c022054e1c258c2981cdfba5df1f46661fb6541c44f77ca0092f3600331abfffb125101 0x23 0x2103363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640ac",
514526
"0x21 0x03363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640 CHECKSIG",

0 commit comments

Comments
 (0)