Skip to content

Conversation

@ps1dr3x
Copy link

@ps1dr3x ps1dr3x commented May 12, 2019

This is related to issue #16011

Currently, in addmultisigaddress function's code the output type is always given by pwallet->m_default_address_type. (https://github.com/bitcoin/bitcoin/blob/master/src/wallet/rpcwallet.cpp#L1018)

This PR adds a fallback to legacy when one or more provided public keys are uncompressed.

@ps1dr3x
Copy link
Author

ps1dr3x commented May 13, 2019

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

@maflcko
Copy link
Member

maflcko commented May 13, 2019

Be reminded that bugfixes must be accompanied by a test that fails before the change and passes after it

@ps1dr3x
Copy link
Author

ps1dr3x commented May 13, 2019

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
Copy link
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.

@maflcko
Copy link
Member

maflcko commented May 13, 2019

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?

@sipa
Copy link
Member

sipa commented May 13, 2019

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
Copy link
Contributor

gmaxwell commented May 13, 2019

@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.

Which I suspect it isn't:

$ ./bitcoin-cli addmultisigaddress 2 '["04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f","047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77","0496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858ee"]' "" bech32
{
"address": "3J1pwTY92a2vcdqVZF4J4Ut1tdbsst68rE",

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
Copy link
Author

ps1dr3x commented May 13, 2019

This is what I'm trying to understand @gmaxwell , it doesn't happen always:

./bitcoin-cli addmultisigaddress 1 '["045897fee25bd7c5692510b2f50fcae9aa20fbc4d49d59814f4c7fdb5c4bc6eb1c0ce382458f9588e922e0d509ed8d34856787380075b00418b02e0bf7c652ef9d","02ac46c6d74d15e60f4f1035ff07ef740aca1d68d55ba0b8d336a73d7a35858831","0224a4dc5620714a9ecf67a09583d1e4c04f5bedb8ecea99028da05bb15a2a7e07"]' "" bech32
{
  "address": "bc1qarhggzk55q4ws9z0jrrsl5qumgrwnwry7lk7xl3s3sel35zskl6qdtm33s",
  "redeemScript": "5141045897fee25bd7c5692510b2f50fcae9aa20fbc4d49d59814f4c7fdb5c4bc6eb1c0ce382458f9588e922e0d509ed8d34856787380075b00418b02e0bf7c652ef9d2102ac46c6d74d15e60f4f1035ff07ef740aca1d68d55ba0b8d336a73d7a35858831210224a4dc5620714a9ecf67a09583d1e4c04f5bedb8ecea99028da05bb15a2a7e0753ae"
}

@gmaxwell
Copy link
Contributor

gmaxwell commented May 13, 2019

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.

$ ./bitcoin-cli addmultisigaddress 2 '["047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77","0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798","0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798"]' "" bech32
{
"address": "bc1q44mnt024cw8r9r3egnq5ndscdqlcyufyppdhdtccf0l7dt8w70jsz37nnz",
"redeemScript": "5241047211a824f55b505228e4c3d5194c1fcfaa15a456abdf37f9b9d97a4040afc073dee6c89064984f03385237d92167c13e236446b417ab79a0fcae412ae3316b77210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179853ae"
}

@ps1dr3x
Copy link
Author

ps1dr3x commented May 13, 2019

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
Copy link
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
Copy link
Author

ps1dr3x commented May 13, 2019

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
Copy link
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
Copy link
Author

ps1dr3x commented May 13, 2019

Oh yeah you're right, I didn't thought about that! Thank you @sdaftuar 👍

@maflcko
Copy link
Member

maflcko commented May 13, 2019

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
Copy link
Author

ps1dr3x commented May 13, 2019

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

@achow101
Copy link
Member

This was simpler than expected. I've opened a PR: #16022

@meshcollider
Copy link
Contributor

Closing in favor of #16026, thank you for your help @ps1dr3x 😄 Hope you continue contributing in the future!

meshcollider added a commit that referenced this pull request Jun 21, 2019
…ys returns a legacy address

a495034 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
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 21, 2019
…ig always returns a legacy address

a495034 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 bitcoin#16022 does.

  Alternative to bitcoin#16022 and bitcoin#16012

  Fixes bitcoin#16011

ACKs for commit a49503:

Tree-SHA512: 5b0154a714deea3b2cc3a54beb420c95eeeacf4ca30c40ca80940d9d640f8b03611b0fc14c2f0710bfd8a79e8d27ad7d9ae380b4b83d52b40ab201624f2a63f0
laanwj added a commit that referenced this pull request Aug 14, 2019
862cbf3 Add missing contributor to release notes (MeshCollider)

Pull request description:

  The user contacted me on Twitter and pointed out that he had contributed in both the reporting of the bug #16012 as well as a number of PRs following it, so I think he deserves to be credited in the release notes

  (also changed to use my real name while I'm there)

ACKs for top commit:
  laanwj:
    ACK 862cbf3

Tree-SHA512: 94bbe168783243fd436b29b741be182fb0dcc247a6e8f52dafcd301ebc63f21e4e035677aa038db95e2e9d2062f5811f2dda1fd6d53966649773c69babb3f61b
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 27, 2021
862cbf3 Add missing contributor to release notes (MeshCollider)

Pull request description:

  The user contacted me on Twitter and pointed out that he had contributed in both the reporting of the bug bitcoin#16012 as well as a number of PRs following it, so I think he deserves to be credited in the release notes

  (also changed to use my real name while I'm there)

ACKs for top commit:
  laanwj:
    ACK 862cbf3

Tree-SHA512: 94bbe168783243fd436b29b741be182fb0dcc247a6e8f52dafcd301ebc63f21e4e035677aa038db95e2e9d2062f5811f2dda1fd6d53966649773c69babb3f61b
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 28, 2021
862cbf3 Add missing contributor to release notes (MeshCollider)

Pull request description:

  The user contacted me on Twitter and pointed out that he had contributed in both the reporting of the bug bitcoin#16012 as well as a number of PRs following it, so I think he deserves to be credited in the release notes

  (also changed to use my real name while I'm there)

ACKs for top commit:
  laanwj:
    ACK 862cbf3

Tree-SHA512: 94bbe168783243fd436b29b741be182fb0dcc247a6e8f52dafcd301ebc63f21e4e035677aa038db95e2e9d2062f5811f2dda1fd6d53966649773c69babb3f61b
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 29, 2021
862cbf3 Add missing contributor to release notes (MeshCollider)

Pull request description:

  The user contacted me on Twitter and pointed out that he had contributed in both the reporting of the bug bitcoin#16012 as well as a number of PRs following it, so I think he deserves to be credited in the release notes

  (also changed to use my real name while I'm there)

ACKs for top commit:
  laanwj:
    ACK 862cbf3

Tree-SHA512: 94bbe168783243fd436b29b741be182fb0dcc247a6e8f52dafcd301ebc63f21e4e035677aa038db95e2e9d2062f5811f2dda1fd6d53966649773c69babb3f61b
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Sep 11, 2021
862cbf3 Add missing contributor to release notes (MeshCollider)

Pull request description:

  The user contacted me on Twitter and pointed out that he had contributed in both the reporting of the bug bitcoin#16012 as well as a number of PRs following it, so I think he deserves to be credited in the release notes

  (also changed to use my real name while I'm there)

ACKs for top commit:
  laanwj:
    ACK 862cbf3

Tree-SHA512: 94bbe168783243fd436b29b741be182fb0dcc247a6e8f52dafcd301ebc63f21e4e035677aa038db95e2e9d2062f5811f2dda1fd6d53966649773c69babb3f61b
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants