From d5269332a45fb0ea3be5f3d678bbdba95b77c510 Mon Sep 17 00:00:00 2001 From: MeshCollider Date: Fri, 21 Jun 2019 19:43:13 +1200 Subject: [PATCH] Merge #16026: Ensure that uncompressed public keys in a multisig always returns a legacy address a49503402b6bc21e3878e151c07529941d36aed0 Make and get the multisig redeemscript and destination in one function instead of two (Andrew Chow) Pull request description: `CreateMultisigRedeemscript()` is changed to `AddAndGetMultisigDestination()` so that the process of constructing the redeemScript and then getting the `CTxDestination` are done in the same function. This allows that function to see what the keys in the multisig are so that the correct address type is returned from `AddAndGetDestinationForScript()`. This only effects the `createmultisig` and `addmultisigaddress` RPCs and does not change signing logic as #16022 does. Alternative to #16022 and #16012 Fixes #16011 ACKs for commit a49503: Tree-SHA512: 5b0154a714deea3b2cc3a54beb420c95eeeacf4ca30c40ca80940d9d640f8b03611b0fc14c2f0710bfd8a79e8d27ad7d9ae380b4b83d52b40ab201624f2a63f0 --- src/rpc/misc.cpp | 6 +++--- src/rpc/util.cpp | 13 +++++++------ src/rpc/util.h | 2 +- src/wallet/rpcwallet.cpp | 9 +++++---- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index f9763da996..58896f9452 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -279,11 +279,11 @@ static UniValue createmultisig(const JSONRPCRequest& request) } // Construct using pay-to-script-hash: - CScript inner = CreateMultisigRedeemscript(required, pubkeys); - CScriptID innerID(inner); + CScript inner; + const CTxDestination dest = AddAndGetMultisigDestination(required, pubkeys, inner); UniValue result(UniValue::VOBJ); - result.pushKV("address", EncodeDestination(ScriptHash(innerID))); + result.pushKV("address", EncodeDestination(dest)); result.pushKV("redeemScript", HexStr(inner)); return result; diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index 77bee22957..2540b6e6b2 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -209,8 +209,8 @@ CPubKey AddrToPubKey(const FillableSigningProvider& keystore, const std::string& return vchPubKey; } -// Creates a multisig redeemscript from a given list of public keys and number required. -CScript CreateMultisigRedeemscript(const int required, const std::vector& pubkeys) +// Creates a multisig address from a given list of public keys, number of signatures required +CTxDestination AddAndGetMultisigDestination(const int required, const std::vector& pubkeys, CScript& script_out) { // Gather public keys if (required < 1) { @@ -223,13 +223,14 @@ CScript CreateMultisigRedeemscript(const int required, const std::vector 16\nReduce the number"); } - CScript result = GetScriptForMultisig(required, pubkeys); + script_out = GetScriptForMultisig(required, pubkeys); - if (result.size() > MAX_SCRIPT_ELEMENT_SIZE) { - throw JSONRPCError(RPC_INVALID_PARAMETER, (strprintf("redeemScript exceeds size limit: %d > %d", result.size(), MAX_SCRIPT_ELEMENT_SIZE))); + if (script_out.size() > MAX_SCRIPT_ELEMENT_SIZE) { + throw JSONRPCError(RPC_INVALID_PARAMETER, (strprintf("redeemScript exceeds size limit: %d > %d", script_out.size(), MAX_SCRIPT_ELEMENT_SIZE))); } - return result; + // Make the address (simplier implementation in compare to bitcoin) + return ScriptHash(script_out); } class DescribeAddressVisitor diff --git a/src/rpc/util.h b/src/rpc/util.h index 07af6ffb10..16e835f71d 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -84,7 +84,7 @@ extern std::string HelpExampleRpc(const std::string& methodname, const std::stri CPubKey HexToPubKey(const std::string& hex_in); CPubKey AddrToPubKey(const FillableSigningProvider& keystore, const std::string& addr_in); -CScript CreateMultisigRedeemscript(const int required, const std::vector& pubkeys); +CTxDestination AddAndGetMultisigDestination(const int required, const std::vector& pubkeys, CScript& script_out); UniValue DescribeAddress(const CTxDestination& dest); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5118f7401f..72ea43bb1c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1030,14 +1030,15 @@ UniValue addmultisigaddress(const JSONRPCRequest& request) } // Construct using pay-to-script-hash: - CScript inner = CreateMultisigRedeemscript(required, pubkeys); - ScriptHash innerHash(inner); + CScript inner; + CTxDestination dest = AddAndGetMultisigDestination(required, pubkeys, inner); + spk_man.AddCScript(inner); - pwallet->SetAddressBook(innerHash, label, "send"); + pwallet->SetAddressBook(dest, label, "send"); UniValue result(UniValue::VOBJ); - result.pushKV("address", EncodeDestination(innerHash)); + result.pushKV("address", EncodeDestination(dest)); result.pushKV("redeemScript", HexStr(inner)); return result; }