This PR adds a fallback to legacy when one or more provided public keys are uncompressed.
rpc: addmultisigaddress should fallback to OutputType::LEGACY when uncompressed public keys are provided #1601108ff8ba369
fanquake added the label RPC/REST/ZMQ on May 12, 2019
fanquake added the label Wallet on May 12, 2019
ps1dr3x
commented at 8:51 AM on May 13, 2019:
none
I just noticed that the function AddAndGetDestinationForScript, called by addmultisigaddress to calculate the destination, should already do this check (calling IsSolvable function) and falling back to legacy, but for some reason it doesn't (IsSolvable returns true). (https://github.com/bitcoin/bitcoin/blob/master/src/outputtype.cpp#L76)
I'm digging into it
MarcoFalke
commented at 1:23 PM on May 13, 2019:
member
Be reminded that bugfixes must be accompanied by a test that fails before the change and passes after it
ps1dr3x
commented at 2:10 PM on May 13, 2019:
none
Thank you for the reminder @MarcoFalke , I'll add a test soon. I'm just trying to figure out if my current fix is enough or there are any other broken parts in the process, because there's a comment here saying that the use of uncompressed keys should be managed, but apparently it's not
gmaxwell
commented at 7:23 PM on May 13, 2019:
contributor
@MarcoFalke so, you would prefer we close this fix of a potentially money losing bug if no one felt like adding a test case for trivial functionality? I couldn't more strongly disagree.
MarcoFalke
commented at 7:36 PM on May 13, 2019:
member
So you would prefer to not have a test, so that we can regress on this in the future and cause money loss for users?
Nothing prevents fixing the bug, and the separately adding a test. I certainly agree we should have tests for issues discovered in the past, but that doesn't mean there is a strong requirement to have one in the same PR, by the same author.
gmaxwell
commented at 7:56 PM on May 13, 2019:
contributor
@MarcoFalke Perhaps I misunderstood you. It sounded to me like you were expressing the view that a fix wouldn't be accepted if it was submitted without an automated test, if so I believe that isn't a position that we should take.
If instead you were just expressing doubt that there was actually a bug here to fix, then I agree. But coming with an automated test is not the bar for determining if a bug exists or not. I also think it's great to ask contributors if they'd be willing to automate their test, but we should probably lean towards "I'll help you figure out how to do it" especially for new contributors, rather than "you must be this tall to ride, good luck".
And our urgency should be modulated somewhat by how easy it would be to accidentally regress: If someone finds a spelling error in a help message we're not exactly going to insist on adding a regression test which checks that help output for the misspelled word. :) Some fixes have a low probability of an accidentally regression and a targeted test which only catches that one behaviour may well not be worth its maintenance burden.
Similarly, if a 'bug' were really inconsequential-- then I could support a position that including a test would be a minimum proof of work before we'd bother dealing with it, but this would be a serious bug if it were real.
It's a little surprising that its silently auto-returning legacy when you give it an explicit parameter, it might be better to return an error, but before actually arguing that I'd want to go look to see if that had already been discussed. Auto-returning legacy when it must when there is no argument is at most a doc bug.
ps1dr3x
commented at 8:29 PM on May 13, 2019:
none
This is what I'm trying to understand @gmaxwell , it doesn't happen always:
gmaxwell
commented at 8:33 PM on May 13, 2019:
contributor
Indeed, I just tested further. It appears to me that it only auto switches to legacy when more than the threshold of keys is uncompressed. 0_o This is absolutely a bug.
ps1dr3x
commented at 8:37 PM on May 13, 2019:
none
I noticed that, and also this comment only after opening the PR, so this commit now seems more like a workaround for a problem which I still don't understand.
I followed the code of the function AddAndGetDestinationForScript but I still don't get where/when this fallback happens, and why only few cases are affected.
achow101
commented at 8:41 PM on May 13, 2019:
member
I believe this affects createmultisigaddress as well. A more correct fix would be to change AddAndGetDestinationForScript and possibly ProduceSignature as well. I can work on a better fix for this when I have time next week.
ps1dr3x
commented at 9:00 PM on May 13, 2019:
none
Maybe is unrelated and I'm missing something stupid because I don't have any experience on the bitcoin test framework, but I'm having some problems even with the test.
I wrote this simple test in rpc_createmultisig.py (because seems there's only one file for both the calls):
def do_multisig_fallback_to_legacy(self):
self.log.info('Check that addmultisigaddress and createmultisig fallback to legacy when uncompressed public keys are provided')
pubkey1 = "045897fee25bd7c5692510b2f50fcae9aa20fbc4d49d59814f4c7fdb5c4bc6eb1c0ce382458f9588e922e0d509ed8d34856787380075b00418b02e0bf7c652ef9d"
pubkey2 = "02ac46c6d74d15e60f4f1035ff07ef740aca1d68d55ba0b8d336a73d7a35858831"
pubkey3 = "0224a4dc5620714a9ecf67a09583d1e4c04f5bedb8ecea99028da05bb15a2a7e07"
for self.output_type in ["legacy", "p2sh-segwit", "bech32"]:
msigw = self.nodes[0].addmultisigaddress(1, [pubkey1, pubkey2, pubkey3], None, self.output_type)
assert msigw["address"] == "3GiimyxF1R5VixfBFAbQZbuy9EesD2r6n1"
But the assert fails, both with my commit and without, and if I print the 3 addresses (msigw["address"]) I get other different invalid addresses (but the same redeemScript):
2019-05-13T19:17:07.346000Z TestFramework (INFO): Check that addmultisigaddress and createmultisig fallback to legacy when uncompressed public keys are provided
{'address': '2N8GvqitGcsaqvkHivJDHBYuEMas2zoTNQm', 'redeemScript': '5141045897fee25bd7c5692510b2f50fcae9aa20fbc4d49d59814f4c7fdb5c4bc6eb1c0ce382458f9588e922e0d509ed8d34856787380075b00418b02e0bf7c652ef9d2102ac46c6d74d15e60f4f1035ff07ef740aca1d68d55ba0b8d336a73d7a35858831210224a4dc5620714a9ecf67a09583d1e4c04f5bedb8ecea99028da05bb15a2a7e0753ae'}
{'address': '2Mx2YyMfY5vMa8MwXt7K8RSaV1ieGMycCpF', 'redeemScript': '5141045897fee25bd7c5692510b2f50fcae9aa20fbc4d49d59814f4c7fdb5c4bc6eb1c0ce382458f9588e922e0d509ed8d34856787380075b00418b02e0bf7c652ef9d2102ac46c6d74d15e60f4f1035ff07ef740aca1d68d55ba0b8d336a73d7a35858831210224a4dc5620714a9ecf67a09583d1e4c04f5bedb8ecea99028da05bb15a2a7e0753ae'}
{'address': 'bcrt1qarhggzk55q4ws9z0jrrsl5qumgrwnwry7lk7xl3s3sel35zskl6qh68c79', 'redeemScript': '5141045897fee25bd7c5692510b2f50fcae9aa20fbc4d49d59814f4c7fdb5c4bc6eb1c0ce382458f9588e922e0d509ed8d34856787380075b00418b02e0bf7c652ef9d2102ac46c6d74d15e60f4f1035ff07ef740aca1d68d55ba0b8d336a73d7a35858831210224a4dc5620714a9ecf67a09583d1e4c04f5bedb8ecea99028da05bb15a2a7e0753ae'}
Do you have any idea on what's wrong here? The same call with bitcoin-cli to the compiled and running node (same code) returns the expected addresses...
sdaftuar
commented at 9:30 PM on May 13, 2019:
member
@ps1dr3x I haven't dived into this but I noticed that your test uses a "3..." prefix for the address, but the address encoding for regtest/testnet (which is what we use in our test framework) is different than mainnet, so P2SH addresses will start with a "2".
ps1dr3x
commented at 10:00 PM on May 13, 2019:
none
Oh yeah you're right, I didn't thought about that! Thank you @sdaftuar :+1:
MarcoFalke
commented at 10:02 PM on May 13, 2019:
member
It is fine if you don't add a test case if it is too hard to get one. I thought this would be a single line added with an assert, but I guess it turned out more involved?
ps1dr3x
commented at 10:27 PM on May 13, 2019:
none
Yes, and at this point maybe that test will not even fit for the real causes @MarcoFalke . I asked mainly because I was experimenting but I'll not commit that, at least before the real causes are discovered :)
Anyway, meanwhile that @achow101 cannot work on this, I'll continue to try getting more information (or hopefully finding possible fixes) on this
fanquake added the label Bug on May 13, 2019
achow101
commented at 11:30 PM on May 13, 2019:
member
This was simpler than expected. I've opened a PR: #16022
meshcollider
commented at 11:47 PM on June 18, 2019:
contributor
Closing in favor of #16026, thank you for your help @ps1dr3x 😄 Hope you continue contributing in the future!
meshcollider closed this on Jun 18, 2019
meshcollider referenced this in commit 303ec103ba on Jun 21, 2019
sidhujag referenced this in commit f7efea7b67 on Jun 21, 2019
laanwj referenced this in commit 286332495d on Aug 14, 2019
PastaPastaPasta referenced this in commit 831c4d9e7d on Jun 27, 2021
PastaPastaPasta referenced this in commit dffe3eab9c on Jun 28, 2021
PastaPastaPasta referenced this in commit eec2100be3 on Jun 29, 2021
PastaPastaPasta referenced this in commit a6b10c214c on Sep 11, 2021
This is a metadata mirror of the GitHub repository
bitcoin/bitcoin.
This site is not affiliated with GitHub.
Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:14 UTC
This site is hosted by @0xB10C More mirrored repositories can be found on mirror.b10c.me