From b58b8fcbcd70370a0b279a8c14f43f595ff69128 Mon Sep 17 00:00:00 2001 From: Adam Gibson Date: Tue, 25 Jul 2017 17:33:58 +0300 Subject: [PATCH] Fix tests, fix bug in mixed-transaction signing (not used in JM) More on bug: when signing txs with SW and non-SW inputs, the existing signature_form for non-SW inputs didnt pay attention to whether the tx serialization was SW or non-SW style, so if a SW-style tx serialization was passed in, it was kept in SW form after passing through signature_form, resulting in an attempt to create a signature based on SW style sighashing. The fix here just ensures that signature_form always enforces the tx format to be non-SW style, so allowing callers to sign() to get a valid signature whatever they pass in. --- jmbitcoin/jmbitcoin/secp256k1_transaction.py | 3 +++ jmclient/test/test_configure.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/jmbitcoin/jmbitcoin/secp256k1_transaction.py b/jmbitcoin/jmbitcoin/secp256k1_transaction.py index b9b2783..1c7bf63 100644 --- a/jmbitcoin/jmbitcoin/secp256k1_transaction.py +++ b/jmbitcoin/jmbitcoin/secp256k1_transaction.py @@ -223,6 +223,9 @@ def signature_form(tx, i, script, hashcode=SIGHASH_ALL): return serialize(signature_form(deserialize(tx), i, script, hashcode)) newtx = copy.deepcopy(tx) for inp in newtx["ins"]: + #If tx is passed in in segwit form, it must be switched to non-segwit. + if "txinwitness" in inp: + del inp["txinwitness"] inp["script"] = "" newtx["ins"][i]["script"] = script if hashcode & 0x1f == SIGHASH_NONE: diff --git a/jmclient/test/test_configure.py b/jmclient/test/test_configure.py index b94d1ba..44f9981 100644 --- a/jmclient/test/test_configure.py +++ b/jmclient/test/test_configure.py @@ -23,9 +23,9 @@ def test_load_config(): load_program_config(bs="regtest") os.makedirs("dummydirforconfig") ncp = os.path.join(os.getcwd(), "dummydirforconfig") - #need to erase remembered data in global config jm_single().config_location = "joinmarket.cfg" - load_program_config(config_path=ncp) + #TODO hack: the default config won't load on bitcoin-rpc; need to fix. + load_program_config(config_path=ncp, bs="blockr") os.remove("dummydirforconfig/joinmarket.cfg") os.removedirs("dummydirforconfig") jm_single().config_location = "joinmarket.cfg"