rpc: fix invalid parameter error codes for {sign,verify}message RPCs #18466

pull theStack wants to merge 3 commits into bitcoin:master from theStack:20200329-rpc-improve-signverifymessage-error-codes changing 4 files +34 −4
  1. theStack commented at 6:18 PM on March 29, 2020: member

    RPCs that accept address parameters usually return the intended error code RPC_INVALID_ADDRESS_OR_KEY (-5) if a passed address is invalid. The two exceptions to the rule are signmessage and verifymessage, which return RPC_TYPE_ERROR (-3) in this case instead. Oddly enough verifymessage returns RPC_INVALID_ADDRESS_OR_KEY when the signature was malformed, where RPC_TYPE_ERROR would be more approriate.

    This PR fixes these inaccuracies and as well adds tests to rpc_signmessage.py that check the parameter validity and error codes for the related RPCs signmessagewithprivkey, signmessage and verifymessage.

    master branch:

    $ ./bitcoin-cli signmessage invalid_addr message
    error code: -3
    error message:
    Invalid address
    $ ./bitcoin-cli verifymessage invalid_addr dummy_sig message
    error code: -3
    error message:
    Invalid address
    $ ./bitcoin-cli verifymessage 12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX invalid_sig message
    error code: -5
    error message:
    Malformed base64 encoding
    

    PR branch:

    $ ./bitcoin-cli signmessage invalid_addr message
    error code: -5
    error message:
    Invalid address
    $ ./bitcoin-cli verifymessage invalid_addr dummy_sig message
    error code: -5
    error message:
    Invalid address
    $ ./bitcoin-cli verifymessage 12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX invalid_sig message
    error code: -3
    error message:
    Malformed base64 encoding
    
  2. theStack force-pushed on Mar 29, 2020
  3. DrahtBot added the label RPC/REST/ZMQ on Mar 29, 2020
  4. DrahtBot added the label Tests on Mar 29, 2020
  5. DrahtBot added the label Wallet on Mar 29, 2020
  6. fanquake removed the label Tests on Mar 30, 2020
  7. MarcoFalke added the label Needs release note on Apr 17, 2020
  8. MarcoFalke commented at 2:40 PM on April 17, 2020: member

    Do we have guidelines on what error code to use?

  9. theStack commented at 3:21 PM on April 17, 2020: member

    Do we have guidelines on what error code to use?

    Not that I know of, I was just orienting myself on what most other RPCs receiving address parameters use as error codes (see e.g.

    git grep "RPC_.*Invalid address"

    ). Even without guideline I'd assume it's common practice to choose the most specific error code, and only use the more more generic one (like RPC_TYPE_ERROR) if none of the specific ones match.

  10. laanwj commented at 3:10 PM on August 28, 2020: member

    I think it's good to be consistent here, whether there are guidelines or not. To return the same return values for the same kind of errors over different RPC calls.

    I do agree this change needs a release notes mention. Some people depend on specific return values, see e.g. talaia-labs/python-teos#37 (which is not relevant to this specific RPCs).

  11. rpc: fix {sign,message}verify RPC errors for invalid address/signature e62f0c71f1
  12. test: check parameter validity in rpc_signmessage.py
    checks parameter validity and error codes for the related RPCs:
        - signmessagewithprivkey
        - signmessage
        - verifymessage
    9e399b9b2d
  13. doc: release note for changed {sign,verify}message error codes a5cfb40e27
  14. theStack force-pushed on Aug 29, 2020
  15. theStack commented at 8:45 AM on August 29, 2020: member

    Added a relase note commit and rebased on master.

  16. DrahtBot commented at 11:45 PM on October 15, 2020: member

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    No conflicts as of last run.

  17. luke-jr approved
  18. luke-jr commented at 9:01 PM on October 24, 2020: member

    utACK

  19. MarcoFalke removed the label Needs release note on Oct 25, 2020
  20. meshcollider commented at 12:28 AM on January 19, 2021: contributor

    utACK a5cfb40e27bd281354bd0d14d91f83efb6bfce9f

  21. laanwj commented at 10:45 AM on March 1, 2021: member

    Code review ACK a5cfb40e27bd281354bd0d14d91f83efb6bfce9f

  22. laanwj merged this on Mar 1, 2021
  23. laanwj closed this on Mar 1, 2021

  24. sidhujag referenced this in commit 5e53f9413c on Mar 1, 2021
  25. DrahtBot locked this on Aug 16, 2022
  26. theStack deleted the branch on May 4, 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