From 589ed31fde771c606488412324d0affd76e8b670 Mon Sep 17 00:00:00 2001 From: undeath Date: Fri, 29 Jun 2018 11:32:39 +0200 Subject: [PATCH] fix bug in segwit SIGHASH_SINGLE signing --- jmbitcoin/jmbitcoin/secp256k1_transaction.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/jmbitcoin/jmbitcoin/secp256k1_transaction.py b/jmbitcoin/jmbitcoin/secp256k1_transaction.py index b2ec4d5..420320b 100644 --- a/jmbitcoin/jmbitcoin/secp256k1_transaction.py +++ b/jmbitcoin/jmbitcoin/secp256k1_transaction.py @@ -2,7 +2,6 @@ import binascii, re, json, copy, sys from jmbitcoin.secp256k1_main import * from _functools import reduce -import os is_python2 = sys.version_info.major == 2 @@ -200,7 +199,7 @@ def segwit_signature_form(txobj, i, script, amount, hashcode=SIGHASH_ALL): hashPrevouts = bin_dbl_sha256(pi) #create hashSequence if not hashcode & SIGHASH_ANYONECANPAY and not ( - hashcode & 0x1f == SIGHASH_NONE) and not (hashcode & 0x1f == SIGHASH_NONE): + hashcode & 0x1f == SIGHASH_SINGLE) and not (hashcode & 0x1f == SIGHASH_NONE): pi = "" for inp in txobj["ins"]: pi += encode(inp["sequence"], 256, 4)[::-1] @@ -221,12 +220,10 @@ def segwit_signature_form(txobj, i, script, amount, hashcode=SIGHASH_ALL): pi += (num_to_var_int(len(binascii.unhexlify(out["script"]))) + \ binascii.unhexlify(out["script"])) hashOutputs = bin_dbl_sha256(pi) - elif hashcode & 0x1f == SIGHASH_SINGLE: - pi = "" - if i < len(txobj['outs']): - pi += encode(txobj["outs"][i]["value"], 256, 8)[::-1] - pi += (num_to_var_int(len(binascii.unhexlify(txobj["outs"][i][ - "script"]))) + binascii.unhexlify(txobj["outs"][i]["script"])) + elif hashcode & 0x1f == SIGHASH_SINGLE and i < len(txobj['outs']): + pi = encode(txobj["outs"][i]["value"], 256, 8)[::-1] + pi += (num_to_var_int(len(binascii.unhexlify(txobj["outs"][i]["script"]))) + + binascii.unhexlify(txobj["outs"][i]["script"])) hashOutputs = bin_dbl_sha256(pi) else: hashOutputs = "\x00"*32