Open chris-belcher opened 9 years ago
petertodd/python-bitcoinlib@f6e8dc9 fixes the same bug in a similar library
I've solved this issue so low s is always signed: see my pybitcointools fork
In transaction.py
, der_encode_sig
should:
s
value: s = N-s if s>N//2 else s
r
and s
is not greater than 0x7f, otherwise add a nullbyte (currently code only checks >= 2**255
def der_encode_sig(v, r, s):
"""Takes (vbyte, r, s) as ints and returns hex der encode sig"""
s = N-s if s>N//2 else s # BIP62 low s
b1, b2 = encode(r, 256), encode(s, 256)
if bytearray(b1)[0] & 0x80: # add null bytes if leading byte interpreted as negative
b1 = b'\x00' + b1
if bytearray(b2)[0] & 0x80:
b2 = b'\x00' + b2
left = b'\x02' + encode(len(b1), 256, 1) + b1
right = b'\x02' + encode(len(b2), 256, 1) + b2
sighex = safe_hexlify(b'\x30' + encode(len(left+right), 256, 1) + left + right)
# check BIP66, see https://github.com/simcity4242/pybitcointools/blob/master/bitcoin/transaction.py#L181-L204
assert is_bip66(sighex)
return sighex
Thanks for solving it @simcity4242 We're about to merge it into JoinMarket. https://github.com/chris-belcher/joinmarket/pull/167
Ping?
pong
Spam on Github Issues!
Here is code that reproduces the tx. It is a regtest tx, I could upload my regtest/ directory if required.
When run
Using sendrawtransaction on bitcoin core console produces this error
The relevant line the debug.log