From 6d8bc3c664ade7f59d69a6132dac96aad1f7880e Mon Sep 17 00:00:00 2001 From: Samuel Dobson Date: Tue, 28 Sep 2021 15:08:13 +1300 Subject: [PATCH 1/3] Add warnings field to createmultisig to warn about uncompressed keys --- src/rpc/misc.cpp | 11 +++++++++++ test/functional/rpc_createmultisig.py | 7 +++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 2c05fc39fd..762f6665da 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -113,6 +113,10 @@ static RPCHelpMan createmultisig() {RPCResult::Type::STR, "address", "The value of the new multisig address."}, {RPCResult::Type::STR_HEX, "redeemScript", "The string value of the hex-encoded redemption script."}, {RPCResult::Type::STR, "descriptor", "The descriptor for this multisig"}, + {RPCResult::Type::ARR, "warnings", /* optional */ true, "Any warnings resulting from the creation of this multisig", + { + {RPCResult::Type::STR, "", ""}, + }}, } }, RPCExamples{ @@ -161,6 +165,13 @@ static RPCHelpMan createmultisig() result.pushKV("redeemScript", HexStr(inner)); result.pushKV("descriptor", descriptor->ToString()); + UniValue warnings(UniValue::VARR); + if (!request.params[2].isNull() && OutputTypeFromDestination(dest) != output_type) { + // Only warns if the user has explicitly chosen an address type we cannot generate + warnings.push_back("Unable to make chosen address type, please ensure no uncompressed public keys are present."); + } + if (warnings.size()) result.pushKV("warnings", warnings); + return result; }, }; diff --git a/test/functional/rpc_createmultisig.py b/test/functional/rpc_createmultisig.py index f56e71ae7a..fb5964595a 100755 --- a/test/functional/rpc_createmultisig.py +++ b/test/functional/rpc_createmultisig.py @@ -78,8 +78,11 @@ def run_test(self): assert_equal(legacy_addr, wmulti0.addmultisigaddress(2, keys, '', 'legacy')['address']) # Generate addresses with the segwit types. These should all make legacy addresses - assert_equal(legacy_addr, wmulti0.createmultisig(2, keys, 'bech32')['address']) - assert_equal(legacy_addr, wmulti0.createmultisig(2, keys, 'p2sh-segwit')['address']) + for addr_type in ['bech32', 'p2sh-segwit']: + result = wmulti0.createmultisig(2, keys, addr_type) + assert_equal(legacy_addr, result['address']) + assert_equal(result['warnings'], ["Unable to make chosen address type, please ensure no uncompressed public keys are present."]) + assert_equal(legacy_addr, wmulti0.addmultisigaddress(2, keys, '', 'bech32')['address']) assert_equal(legacy_addr, wmulti0.addmultisigaddress(2, keys, '', 'p2sh-segwit')['address']) From c1f9fa4f69facf808c64d75169e97e41c20f5db8 Mon Sep 17 00:00:00 2001 From: Samuel Dobson Date: Wed, 8 Dec 2021 17:05:16 +1300 Subject: [PATCH 2/3] Add warnings field to addmultisigaddress to warn about uncompressed keys --- src/wallet/rpc/addresses.cpp | 12 ++++++++++++ test/functional/rpc_createmultisig.py | 9 ++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpc/addresses.cpp b/src/wallet/rpc/addresses.cpp index edc4c26eeb..3c07354e80 100644 --- a/src/wallet/rpc/addresses.cpp +++ b/src/wallet/rpc/addresses.cpp @@ -238,6 +238,10 @@ RPCHelpMan addmultisigaddress() {RPCResult::Type::STR, "address", "The value of the new multisig address"}, {RPCResult::Type::STR_HEX, "redeemScript", "The string value of the hex-encoded redemption script"}, {RPCResult::Type::STR, "descriptor", "The descriptor for this multisig"}, + {RPCResult::Type::ARR, "warnings", /* optional */ true, "Any warnings resulting from the creation of this multisig", + { + {RPCResult::Type::STR, "", ""}, + }}, } }, RPCExamples{ @@ -295,6 +299,14 @@ RPCHelpMan addmultisigaddress() result.pushKV("address", EncodeDestination(dest)); result.pushKV("redeemScript", HexStr(inner)); result.pushKV("descriptor", descriptor->ToString()); + + UniValue warnings(UniValue::VARR); + if (!request.params[3].isNull() && OutputTypeFromDestination(dest) != output_type) { + // Only warns if the user has explicitly chosen an address type we cannot generate + warnings.push_back("Unable to make chosen address type, please ensure no uncompressed public keys are present."); + } + if (warnings.size()) result.pushKV("warnings", warnings); + return result; }, }; diff --git a/test/functional/rpc_createmultisig.py b/test/functional/rpc_createmultisig.py index fb5964595a..1a3d14100f 100755 --- a/test/functional/rpc_createmultisig.py +++ b/test/functional/rpc_createmultisig.py @@ -75,7 +75,9 @@ def run_test(self): for keys in itertools.permutations([pk0, pk1, pk2]): # Results should be the same as this legacy one legacy_addr = node0.createmultisig(2, keys, 'legacy')['address'] - assert_equal(legacy_addr, wmulti0.addmultisigaddress(2, keys, '', 'legacy')['address']) + result = wmulti0.addmultisigaddress(2, keys, '', 'legacy') + assert_equal(legacy_addr, result['address']) + assert 'warnings' not in result # Generate addresses with the segwit types. These should all make legacy addresses for addr_type in ['bech32', 'p2sh-segwit']: @@ -83,8 +85,9 @@ def run_test(self): assert_equal(legacy_addr, result['address']) assert_equal(result['warnings'], ["Unable to make chosen address type, please ensure no uncompressed public keys are present."]) - assert_equal(legacy_addr, wmulti0.addmultisigaddress(2, keys, '', 'bech32')['address']) - assert_equal(legacy_addr, wmulti0.addmultisigaddress(2, keys, '', 'p2sh-segwit')['address']) + result = wmulti0.addmultisigaddress(2, keys, '', addr_type) + assert_equal(legacy_addr, result['address']) + assert_equal(result['warnings'], ["Unable to make chosen address type, please ensure no uncompressed public keys are present."]) self.log.info('Testing sortedmulti descriptors with BIP 67 test vectors') with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/rpc_bip67.json'), encoding='utf-8') as f: From 74c34e2996d2c4608e33b479cc765f053881a191 Mon Sep 17 00:00:00 2001 From: Samuel Dobson Date: Tue, 28 Sep 2021 15:21:45 +1300 Subject: [PATCH 3/3] Add createmultisig and addmultisigaddress warnings release note --- doc/release-notes-23113.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 doc/release-notes-23113.md diff --git a/doc/release-notes-23113.md b/doc/release-notes-23113.md new file mode 100644 index 0000000000..b0904c9d7b --- /dev/null +++ b/doc/release-notes-23113.md @@ -0,0 +1,9 @@ +Notable changes +=============== + +Updated RPCs +------------ + +- Both `createmultisig` and `addmultisigaddress` now include a `warnings` +field, which will show a warning if a non-legacy address type is requested +when using uncompressed public keys.