Browse Source

fix bug in segwit SIGHASH_SINGLE signing

master
undeath 8 years ago
parent
commit
589ed31fde
  1. 13
      jmbitcoin/jmbitcoin/secp256k1_transaction.py

13
jmbitcoin/jmbitcoin/secp256k1_transaction.py

@ -2,7 +2,6 @@
import binascii, re, json, copy, sys import binascii, re, json, copy, sys
from jmbitcoin.secp256k1_main import * from jmbitcoin.secp256k1_main import *
from _functools import reduce from _functools import reduce
import os
is_python2 = sys.version_info.major == 2 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) hashPrevouts = bin_dbl_sha256(pi)
#create hashSequence #create hashSequence
if not hashcode & SIGHASH_ANYONECANPAY and not ( 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 = "" pi = ""
for inp in txobj["ins"]: for inp in txobj["ins"]:
pi += encode(inp["sequence"], 256, 4)[::-1] 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"]))) + \ pi += (num_to_var_int(len(binascii.unhexlify(out["script"]))) + \
binascii.unhexlify(out["script"])) binascii.unhexlify(out["script"]))
hashOutputs = bin_dbl_sha256(pi) hashOutputs = bin_dbl_sha256(pi)
elif hashcode & 0x1f == SIGHASH_SINGLE: elif hashcode & 0x1f == SIGHASH_SINGLE and i < len(txobj['outs']):
pi = "" pi = encode(txobj["outs"][i]["value"], 256, 8)[::-1]
if i < len(txobj['outs']): pi += (num_to_var_int(len(binascii.unhexlify(txobj["outs"][i]["script"]))) +
pi += encode(txobj["outs"][i]["value"], 256, 8)[::-1] binascii.unhexlify(txobj["outs"][i]["script"]))
pi += (num_to_var_int(len(binascii.unhexlify(txobj["outs"][i][
"script"]))) + binascii.unhexlify(txobj["outs"][i]["script"]))
hashOutputs = bin_dbl_sha256(pi) hashOutputs = bin_dbl_sha256(pi)
else: else:
hashOutputs = "\x00"*32 hashOutputs = "\x00"*32

Loading…
Cancel
Save