Ensure that uncompressed public keys in a multisig always returns a legacy address #16026

pull achow101 wants to merge 1 commits into bitcoin:master from achow101:dont-sw-ms-uncomp changing 5 files +53 −12
  1. achow101 commented at 4:29 AM on May 15, 2019: member

    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

  2. fanquake added the label RPC/REST/ZMQ on May 15, 2019
  3. gmaxwell commented at 4:42 AM on May 15, 2019: contributor

    This sounds right to me.

  4. MarcoFalke added the label Needs backport on May 15, 2019
  5. MarcoFalke added this to the milestone 0.18.1 on May 15, 2019
  6. in src/rpc/util.cpp:155 in 5fefdb3286 outdated
     150 | @@ -150,8 +151,8 @@ CPubKey AddrToPubKey(CKeyStore* const keystore, const std::string& addr_in)
     151 |      return vchPubKey;
     152 |  }
     153 |  
     154 | -// Creates a multisig redeemscript from a given list of public keys and number required.
     155 | -CScript CreateMultisigRedeemscript(const int required, const std::vector<CPubKey>& pubkeys)
     156 | +// Creates a multisig address from a given list of public keys, number required, and the address type
     157 | +CTxDestination AddAndGetMultisigDestination(CKeyStore& keystore, CScript& script_out, const int required, const std::vector<CPubKey>& pubkeys, OutputType type)
    


    Empact commented at 7:09 PM on May 15, 2019:

    nit: as an out arg, it'd be somewhat more clear to place script_out towards the end. AddAndGetDestinationForScript's placement is based on the same not being an out arg.


    laanwj commented at 11:52 AM on May 29, 2019:

    yeah, that seems to en the convention, usually wish C++ had tuple unpacking and it was unnecessary to bother with 'output arguments'


    achow101 commented at 3:38 PM on June 18, 2019:

    Done

  7. laanwj commented at 11:54 AM on May 29, 2019: member

    utACK 5fefdb3286b617a74dd395381b1be0b29f21b0e6

  8. in src/rpc/util.cpp:175 in 5fefdb3286 outdated
     174 | +        throw JSONRPCError(RPC_INVALID_PARAMETER, (strprintf("redeemScript exceeds size limit: %d > %d", script_out.size(), MAX_SCRIPT_ELEMENT_SIZE)));
     175 |      }
     176 |  
     177 | -    return result;
     178 | +    // Check if any keys are uncompressed. If so, the type is legacy
     179 | +    for (CPubKey pk : pubkeys) {
    


    meshcollider commented at 12:03 PM on June 5, 2019:

    &


    achow101 commented at 1:12 PM on June 5, 2019:

    done

  9. meshcollider commented at 12:03 PM on June 5, 2019: contributor

    utACK

  10. achow101 force-pushed on Jun 5, 2019
  11. MarcoFalke closed this on Jun 16, 2019

  12. MarcoFalke reopened this on Jun 16, 2019

  13. DrahtBot commented at 5:07 AM on June 18, 2019: member

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #16227 (Refactor CWallet's inheritance chain by achow101)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  14. achow101 force-pushed on Jun 18, 2019
  15. meshcollider added this to the "Bugfixes" column in a project

  16. in src/rpc/util.cpp:154 in 4069662070 outdated
     150 | @@ -150,8 +151,8 @@ CPubKey AddrToPubKey(CKeyStore* const keystore, const std::string& addr_in)
     151 |      return vchPubKey;
     152 |  }
     153 |  
     154 | -// Creates a multisig redeemscript from a given list of public keys and number required.
     155 | -CScript CreateMultisigRedeemscript(const int required, const std::vector<CPubKey>& pubkeys)
     156 | +// Creates a multisig address from a given list of public keys, number required, and the address type
    


    kallewoof commented at 1:39 PM on June 19, 2019:

    This comment (number required) is confusing. Reading code I understand it's the threshold for sigs (k in k-of-n). Maybe "from a given list of public keys, number of required signatures, and the address type"?


    achow101 commented at 10:05 PM on June 19, 2019:

    Done

  17. in test/functional/rpc_createmultisig.py:16 in 4069662070 outdated
      12 | -import decimal
      13 | +from test_framework.key import ECPubKey
      14 |  
      15 | +import binascii
      16 | +import decimal
      17 | +import itertools
    


    kallewoof commented at 1:46 PM on June 19, 2019:

    Unless I'm mistaken, convention is to import system libs first, then own stuff. decimal was imported here, though, so grain-of-salt.


    achow101 commented at 10:05 PM on June 19, 2019:

    A bunch of other tests do system libs after our own :man_shrugging:

  18. kallewoof approved
  19. kallewoof commented at 1:48 PM on June 19, 2019: member

    ACK 40696620703e7339957177e95a9acb1d8be80e0e

    Some nits, can be ignored (though would like comment fixed if possible).

  20. achow101 force-pushed on Jun 19, 2019
  21. kallewoof commented at 4:02 AM on June 20, 2019: member

    re-ACK 0c39c9d

  22. meshcollider commented at 8:43 AM on June 20, 2019: contributor

    @achow101 I think your force push reversed the parameter reordering you did a couple of days ago

  23. Make and get the multisig redeemscript and destination in one function instead of two
    Instead of creating a redeemScript with CreateMultisigRedeemscript and
    then getting the destination with AddAndGetDestinationForScript, do
    both in the same function.
    
    CreateMultisigRedeemscript is changed to AddAndGetMultisigDestination.
    It creates the redeemScript and returns it via an output parameter. Then
    it calls AddAndGetDestinationForScript to add the destination to the
    keystore and get the proper destination.
    
    This allows us to inspect the public keys in the redeemScript before creating
    the destination so that the correct destination is used when uncompressed
    pubkeys are in the multisig.
    a49503402b
  24. achow101 force-pushed on Jun 20, 2019
  25. achow101 commented at 3:02 PM on June 20, 2019: member

    @achow101 I think your force push reversed the parameter reordering you did a couple of days ago

    Oops. Should be fixed now.

  26. meshcollider merged this on Jun 21, 2019
  27. meshcollider closed this on Jun 21, 2019

  28. meshcollider referenced this in commit 303ec103ba on Jun 21, 2019
  29. MarcoFalke referenced this in commit e472d545b1 on Jun 21, 2019
  30. MarcoFalke removed the label Needs backport on Jun 21, 2019
  31. MarcoFalke referenced this in commit e78007fc1a on Jun 21, 2019
  32. sidhujag referenced this in commit f7efea7b67 on Jun 21, 2019
  33. HashUnlimited referenced this in commit 6a8f0b36bd on Aug 23, 2019
  34. Bushstar referenced this in commit c4b96875f2 on Aug 24, 2019
  35. Bushstar referenced this in commit 93c3a2df3d on Aug 24, 2019
  36. Bushstar referenced this in commit 92773cd27e on Aug 24, 2019
  37. Bushstar referenced this in commit 27d3bcf55d on Aug 24, 2019
  38. deadalnix referenced this in commit f14a55dc9e on Jun 12, 2020
  39. jnewbery removed this from the "Bugfixes" column in a project

  40. DrahtBot locked this on Feb 15, 2022

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