From 3c481f8921bbc587cf287329f39243abe703b868 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Thu, 20 Jun 2019 18:01:23 +1000 Subject: signrawtransactionwithkey: better error messages for bad redeemScript/witnessScript This adds checks to ensure the redeemScript/witnessScript actually correspond to the provided scriptPubKey, and, if both are provided, that they are sensibly related to each other. Thanks to github user passionofvc for raising this issue. --- test/functional/rpc_createmultisig.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test') diff --git a/test/functional/rpc_createmultisig.py b/test/functional/rpc_createmultisig.py index 62f3843756..056e193d55 100755 --- a/test/functional/rpc_createmultisig.py +++ b/test/functional/rpc_createmultisig.py @@ -134,6 +134,27 @@ class RpcCreateMultiSigTest(BitcoinTestFramework): assert_raises_rpc_error(-8, "Missing redeemScript/witnessScript", node2.signrawtransactionwithkey, rawtx, self.priv[0:self.nsigs-1], [prevtx_err]) + # if witnessScript specified, all ok + prevtx_err["witnessScript"] = prevtxs[0]["redeemScript"] + node2.signrawtransactionwithkey(rawtx, self.priv[0:self.nsigs-1], [prevtx_err]) + + # both specified, also ok + prevtx_err["redeemScript"] = prevtxs[0]["redeemScript"] + node2.signrawtransactionwithkey(rawtx, self.priv[0:self.nsigs-1], [prevtx_err]) + + # redeemScript mismatch to witnessScript + prevtx_err["redeemScript"] = "6a" # OP_RETURN + assert_raises_rpc_error(-8, "redeemScript does not correspond to witnessScript", node2.signrawtransactionwithkey, rawtx, self.priv[0:self.nsigs-1], [prevtx_err]) + + # redeemScript does not match scriptPubKey + del prevtx_err["witnessScript"] + assert_raises_rpc_error(-8, "redeemScript/witnessScript does not match scriptPubKey", node2.signrawtransactionwithkey, rawtx, self.priv[0:self.nsigs-1], [prevtx_err]) + + # witnessScript does not match scriptPubKey + prevtx_err["witnessScript"] = prevtx_err["redeemScript"] + del prevtx_err["redeemScript"] + assert_raises_rpc_error(-8, "redeemScript/witnessScript does not match scriptPubKey", node2.signrawtransactionwithkey, rawtx, self.priv[0:self.nsigs-1], [prevtx_err]) + rawtx2 = node2.signrawtransactionwithkey(rawtx, self.priv[0:self.nsigs - 1], prevtxs) rawtx3 = node2.signrawtransactionwithkey(rawtx2["hex"], [self.priv[-1]], prevtxs) -- cgit v1.2.3