Skip to content

Commit ac92ab6

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#23113: Add warnings to createmultisig and addmultisig if using uncompressed keys
d5cab1a Add createmultisig and addmultisigaddress warnings release note (Samuel Dobson) e46fc93 Add warnings field to addmultisigaddress to warn about uncompressed keys (Samuel Dobson) d1a9742 Add warnings field to createmultisig to warn about uncompressed keys (Samuel Dobson) Pull request description: Fixes #21368 Currently, if there are any uncompressed keys when calling `AddAndGetMultisigDestination`, it will just default to a legacy address regardless of the chosen `address_type`. Rather than keeping this silent behaviour which may be confusing to users, we explicitly add a `warnings` field which will warn the user why their address format is different. ACKs for top commit: achow101: ACK d5cab1a Tree-SHA512: c2ac7f7689251bd4fcd8c26506f053921fbaf34c7a26a74e82ebc7f82cc0bd25407fd7954bf98365dcafa51fa45dcdbee6214320580ca69509690c3555e71cc0
2 parents 90deb9f + d5cab1a commit ac92ab6

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

doc/release-notes-23113.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Notable changes
2+
===============
3+
4+
Updated RPCs
5+
------------
6+
7+
- Both `createmultisig` and `addmultisigaddress` now include a `warnings`
8+
field, which will show a warning if a non-legacy address type is requested
9+
when using uncompressed public keys.

src/rpc/misc.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ static RPCHelpMan createmultisig()
114114
{RPCResult::Type::STR, "address", "The value of the new multisig address."},
115115
{RPCResult::Type::STR_HEX, "redeemScript", "The string value of the hex-encoded redemption script."},
116116
{RPCResult::Type::STR, "descriptor", "The descriptor for this multisig"},
117+
{RPCResult::Type::ARR, "warnings", /* optional */ true, "Any warnings resulting from the creation of this multisig",
118+
{
119+
{RPCResult::Type::STR, "", ""},
120+
}},
117121
}
118122
},
119123
RPCExamples{
@@ -162,6 +166,13 @@ static RPCHelpMan createmultisig()
162166
result.pushKV("redeemScript", HexStr(inner));
163167
result.pushKV("descriptor", descriptor->ToString());
164168

169+
UniValue warnings(UniValue::VARR);
170+
if (!request.params[2].isNull() && OutputTypeFromDestination(dest) != output_type) {
171+
// Only warns if the user has explicitly chosen an address type we cannot generate
172+
warnings.push_back("Unable to make chosen address type, please ensure no uncompressed public keys are present.");
173+
}
174+
if (warnings.size()) result.pushKV("warnings", warnings);
175+
165176
return result;
166177
},
167178
};

src/wallet/rpc/addresses.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ RPCHelpMan addmultisigaddress()
238238
{RPCResult::Type::STR, "address", "The value of the new multisig address"},
239239
{RPCResult::Type::STR_HEX, "redeemScript", "The string value of the hex-encoded redemption script"},
240240
{RPCResult::Type::STR, "descriptor", "The descriptor for this multisig"},
241+
{RPCResult::Type::ARR, "warnings", /* optional */ true, "Any warnings resulting from the creation of this multisig",
242+
{
243+
{RPCResult::Type::STR, "", ""},
244+
}},
241245
}
242246
},
243247
RPCExamples{
@@ -295,6 +299,14 @@ RPCHelpMan addmultisigaddress()
295299
result.pushKV("address", EncodeDestination(dest));
296300
result.pushKV("redeemScript", HexStr(inner));
297301
result.pushKV("descriptor", descriptor->ToString());
302+
303+
UniValue warnings(UniValue::VARR);
304+
if (!request.params[3].isNull() && OutputTypeFromDestination(dest) != output_type) {
305+
// Only warns if the user has explicitly chosen an address type we cannot generate
306+
warnings.push_back("Unable to make chosen address type, please ensure no uncompressed public keys are present.");
307+
}
308+
if (warnings.size()) result.pushKV("warnings", warnings);
309+
298310
return result;
299311
},
300312
};

test/functional/rpc_createmultisig.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,19 @@ def run_test(self):
7575
for keys in itertools.permutations([pk0, pk1, pk2]):
7676
# Results should be the same as this legacy one
7777
legacy_addr = node0.createmultisig(2, keys, 'legacy')['address']
78-
assert_equal(legacy_addr, wmulti0.addmultisigaddress(2, keys, '', 'legacy')['address'])
78+
result = wmulti0.addmultisigaddress(2, keys, '', 'legacy')
79+
assert_equal(legacy_addr, result['address'])
80+
assert 'warnings' not in result
7981

8082
# Generate addresses with the segwit types. These should all make legacy addresses
81-
assert_equal(legacy_addr, wmulti0.createmultisig(2, keys, 'bech32')['address'])
82-
assert_equal(legacy_addr, wmulti0.createmultisig(2, keys, 'p2sh-segwit')['address'])
83-
assert_equal(legacy_addr, wmulti0.addmultisigaddress(2, keys, '', 'bech32')['address'])
84-
assert_equal(legacy_addr, wmulti0.addmultisigaddress(2, keys, '', 'p2sh-segwit')['address'])
83+
for addr_type in ['bech32', 'p2sh-segwit']:
84+
result = wmulti0.createmultisig(2, keys, addr_type)
85+
assert_equal(legacy_addr, result['address'])
86+
assert_equal(result['warnings'], ["Unable to make chosen address type, please ensure no uncompressed public keys are present."])
87+
88+
result = wmulti0.addmultisigaddress(2, keys, '', addr_type)
89+
assert_equal(legacy_addr, result['address'])
90+
assert_equal(result['warnings'], ["Unable to make chosen address type, please ensure no uncompressed public keys are present."])
8591

8692
self.log.info('Testing sortedmulti descriptors with BIP 67 test vectors')
8793
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data/rpc_bip67.json'), encoding='utf-8') as f:

0 commit comments

Comments
 (0)