Skip to content

Commit 8630c48

Browse files
committed
Implement SCRIPT_VERIFY_CLEANSTACK
1 parent ca0c1bf commit 8630c48

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

bitcoin/core/scripteval.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,12 @@ def VerifyScript(scriptSig, scriptPubKey, txTo, inIdx, flags=()):
772772
if not _CastToBool(stack[-1]):
773773
raise VerifyScriptError("P2SH inner scriptPubKey returned false")
774774

775+
if SCRIPT_VERIFY_CLEANSTACK in flags:
776+
assert SCRIPT_VERIFY_P2SH in flags
777+
778+
if len(stack) != 1:
779+
raise VerifyScriptError("scriptPubKey left extra items on stack")
780+
775781

776782
class VerifySignatureError(bitcoin.core.ValidationError):
777783
pass

bitcoin/tests/data/script_invalid.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,18 @@
504504
"P2SH,STRICTENC",
505505
"2-of-3 with one valid and one invalid signature due to parse error, nSigs > validSigs"
506506
],
507+
[
508+
"11 0x47 0x304402200a5c6163f07b8d3b013c4d1d6dba25e780b39658d79ba37af7057a3b7f15ffa102201fd9b4eaa9943f734928b99a83592c2e7bf342ea2680f6a2bb705167966b742001",
509+
"0x41 0x0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 CHECKSIG",
510+
"CLEANSTACK,P2SH",
511+
"P2PK with unnecessary input"
512+
],
513+
[
514+
"11 0x47 0x304402202f7505132be14872581f35d74b759212d9da40482653f1ffa3116c3294a4a51702206adbf347a2240ca41c66522b1a22a41693610b76a8e7770645dc721d1635854f01 0x43 0x410479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8ac",
515+
"HASH160 0x14 0x31edc23bdafda4639e669f89ad6b2318dd79d032 EQUAL",
516+
"CLEANSTACK,P2SH",
517+
"P2SH with unnecessary input"
518+
],
507519

508520
["The End"]
509521
]

0 commit comments

Comments
 (0)