addmultisigaddress does not fallback to legacy when there are uncompressed public keys in the parameters #16011

issue ps1dr3x opened this issue on May 12, 2019
  1. ps1dr3x commented at 11:07 AM on May 12, 2019: none

    Following a discussion that I started firstly on the Bitcoin dev's mailing list, and then on StackExchange and Reddit, regarding some weird inconsistencies I noticed when I was working on a function to derive the p2sh from a multisig script, I'm here now to report what seems to be a bug in addmultisigaddress method.

    Reference of the discussions: https://bitcoin.stackexchange.com/questions/87579/multisig-scripts-hashing-p2sh-difference-between-legacy-and-segwit https://www.reddit.com/r/Bitcoin/comments/bmiuk5/multisig_scripts_hashing_p2sh_difference_between/

    Example:

    bitcoin-cli addmultisigaddress 1 '["045897fee25bd7c5692510b2f50fcae9aa20fbc4d49d59814f4c7fdb5c4bc6eb1c0ce382458f9588e922e0d509ed8d34856787380075b00418b02e0bf7c652ef9d","02ac46c6d74d15e60f4f1035ff07ef740aca1d68d55ba0b8d336a73d7a35858831","0224a4dc5620714a9ecf67a09583d1e4c04f5bedb8ecea99028da05bb15a2a7e07"]'
    {
      "address": "36ULucjWUTrDvaJzCyhFoVbDoNS6Zum2Du",
      "redeemScript": "5141045897fee25bd7c5692510b2f50fcae9aa20fbc4d49d59814f4c7fdb5c4bc6eb1c0ce382458f9588e922e0d509ed8d34856787380075b00418b02e0bf7c652ef9d2102ac46c6d74d15e60f4f1035ff07ef740aca1d68d55ba0b8d336a73d7a35858831210224a4dc5620714a9ecf67a09583d1e4c04f5bedb8ecea99028da05bb15a2a7e0753ae"
    }
    
    bitcoin-cli createmultisig 1 '["045897fee25bd7c5692510b2f50fcae9aa20fbc4d49d59814f4c7fdb5c4bc6eb1c0ce382458f9588e922e0d509ed8d34856787380075b00418b02e0bf7c652ef9d","02ac46c6d74d15e60f4f1035ff07ef740aca1d68d55ba0b8d336a73d7a35858831","0224a4dc5620714a9ecf67a09583d1e4c04f5bedb8ecea99028da05bb15a2a7e07"]'
    {
      "address": "3GiimyxF1R5VixfBFAbQZbuy9EesD2r6n1",
      "redeemScript": "5141045897fee25bd7c5692510b2f50fcae9aa20fbc4d49d59814f4c7fdb5c4bc6eb1c0ce382458f9588e922e0d509ed8d34856787380075b00418b02e0bf7c652ef9d2102ac46c6d74d15e60f4f1035ff07ef740aca1d68d55ba0b8d336a73d7a35858831210224a4dc5620714a9ecf67a09583d1e4c04f5bedb8ecea99028da05bb15a2a7e0753ae"
    }
    

    Expected behaviour:

    Both the two calls should return the same legacy address, because addmultisigaddress uses p2sh-segwit which is the default address type for the wallet, but segwit does not support uncompressed keys, so the first call should fallback to legacy.

    Actual behaviour:

    The first call is returning an invalid segwit address. @achow101 answered to my email to the dev list and also to my question on StackExchange and he believes that this is a bug and it could be related to the fact that the uncompressed pubkey is not part of my wallet.


    Another interesting thing is that, as user @ugamkamat pointed out on StackExchange, changing the position of the uncompressed public key from the first to the last, the first call returns a legacy address:

    ./bitcoin-cli addmultisigaddress 1 '["02ac46c6d74d15e60f4f1035ff07ef740aca1d68d55ba0b8d336a73d7a35858831","0224a4dc5620714a9ecf67a09583d1e4c04f5bedb8ecea99028da05bb15a2a7e07","045897fee25bd7c5692510b2f50fcae9aa20fbc4d49d59814f4c7fdb5c4bc6eb1c0ce382458f9588e922e0d509ed8d34856787380075b00418b02e0bf7c652ef9d"]'
    {
      "address": "35RZ8AHKWGGbNcRDaCUtznSVnPRWGqVPJu",
      "redeemScript": "512102ac46c6d74d15e60f4f1035ff07ef740aca1d68d55ba0b8d336a73d7a35858831210224a4dc5620714a9ecf67a09583d1e4c04f5bedb8ecea99028da05bb15a2a7e0741045897fee25bd7c5692510b2f50fcae9aa20fbc4d49d59814f4c7fdb5c4bc6eb1c0ce382458f9588e922e0d509ed8d34856787380075b00418b02e0bf7c652ef9d53ae"
    }
    

    I'd really like to try to contribute to the project, so I'm trying to figure out where the problem could be in the code. Any suggestion is welcome.

  2. fanquake added the label RPC/REST/ZMQ on May 12, 2019
  3. ps1dr3x renamed this:
    addmultisigaddress does not fallback to legacy if one of the input public keys is uncompressed
    addmultisigaddress does not fallback to legacy when there are uncompressed public keys in the parameters
    on May 12, 2019
  4. ps1dr3x commented at 11:44 AM on May 12, 2019: none

    More than a bug, this seems to be an unmanaged condition. I see that in addmultisigaddress function's code there's no specific checks on the provided public keys. The output type seems to be just given by pwallet->m_default_address_type. (https://github.com/bitcoin/bitcoin/blob/master/src/wallet/rpcwallet.cpp#L1018) Maybe this part can be improved, at least to check if there are some uncompressed public keys and adapting the output type accordingly

  5. meshcollider closed this on Jun 21, 2019

  6. meshcollider referenced this in commit 303ec103ba on Jun 21, 2019
  7. sidhujag referenced this in commit f7efea7b67 on Jun 21, 2019
  8. MarcoFalke locked this on Dec 16, 2021
  9. knst referenced this in commit a9d89f67bf on Feb 2, 2023
  10. knst referenced this in commit e86da0d9ef on Feb 13, 2023
  11. knst referenced this in commit 60e89cdf72 on Feb 17, 2023
  12. knst referenced this in commit 949339e934 on Feb 20, 2023
  13. knst referenced this in commit 3fca837491 on Feb 28, 2023
  14. knst referenced this in commit 9874c3e279 on Mar 14, 2023
  15. knst referenced this in commit 49e82743ab on Mar 15, 2023
  16. PastaPastaPasta referenced this in commit d5269332a4 on Mar 19, 2023

github-metadata-mirror

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