From 629a91941029b4c8142e2ed730ba0e04df276bb6 Mon Sep 17 00:00:00 2001 From: Dmitry Petukhov Date: Thu, 13 Sep 2018 21:08:13 +0500 Subject: [PATCH] CScript.is_witness_scriptpubkey : size must match second byte + 2 Model CScript.is_witness_scriptpubkey after bitcoind's CScript::IsWitnessProgram -- it not only checks for script size and first opcode, but also checks that data push size equals script size + 2 (entire script consists of version byte and data push). In absense of this check, is_witness_scriptpubkey wrongfully detects 1-of-1 p2sh redeem script as a witness program. --- bitcoin/core/script.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/bitcoin/core/script.py b/bitcoin/core/script.py index ffd97b8b..156843ee 100644 --- a/bitcoin/core/script.py +++ b/bitcoin/core/script.py @@ -678,9 +678,23 @@ def is_p2sh(self): _bord(self[22]) == OP_EQUAL) def is_witness_scriptpubkey(self): - """Returns true if this is a scriptpubkey signaling segregated witness - data. """ - return 3 <= len(self) <= 42 and CScriptOp(struct.unpack(' 42: + return False + + head = struct.unpack('