Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Apr 22, 2021

Add info about valid prefixes from https://en.bitcoin.it/wiki/List_of_address_prefixes

Mentioned about correct prefix for Base58 encoded address and Bech32 address for mainnet and testnet. Regtest and Signet can be ignored because the error message will become too long and both networks are mostly used by devs who are either aware of prefixes or understand errors or know the right place to ask questions if any doubt.

We have so many prefixes and networks that ideally such error should just have one link which user can open and check all the information about correct prefixes. Although this can also work for time being.

Fixes #21741

src/key_io.cpp Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not simply print dec.hrp != params.Bech32HRP()?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean use something like this?

error_str = "Invalid prefix for Bech32 address. Details:" + dec.hrp + "!=" + params.Bech32HRP();

Which will give this error if wrong prefix for a bech32 address is used:

image

Looks more confusing for some users.

Copy link
Author

@ghost ghost Apr 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this works better:

error_str = "Invalid prefix `" + dec.hrp + "` for Bech32 address. Suggested prefix: `"  + params.Bech32HRP() + "`";

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Suggested prefix' implies you (the user) can just change it, which obviously isn't the case. I think the error message does need to emphasise the fact you might be using an address from the wrong network.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to mention "Wrong network" in this error but I am not sure if wrong network is the only reason why a prefix can be wrong and condition in if statement at L102 becomes true.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prayank23 if the decoding succeeded but the HRP is wrong then I think "Wrong network" is a valid assumption. It would either be that or the input was another type of data entirely, using the same checksum, which is much more unlikely and can be safely ignored.

@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 22, 2021

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

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.

+ Mention prefix and network
@ghost
Copy link
Author

ghost commented May 12, 2021

@meshcollider @MarcoFalke Let me know if this code and error message looks better

Code: L102-L113 in af99798

Error:

prayank@ubuntu:~$ bitcoin-cli getaddressinfo bc1qec3jrdfay25ny537hwfr3c7ta2zaxzhftpqz6z
error code: -5
error message:
Invalid prefix 'bc' for Bech32 address on testnet

@luke-jr
Copy link
Member

luke-jr commented Jun 11, 2021

I think it's better without these details. At the very least, normal users shouldn't need to see "mainnet".

@ghost ghost mentioned this pull request Jun 13, 2021
@brunoerg
Copy link
Contributor

Concept ACK

Invalid prefix 'bc' for Bech32 address on testnet seems good for me. I like the idea of mentioning the network (on testnet, for example), it clarifies the relation between the prefixes and the networks.

@tylerchambers
Copy link
Contributor

LGTM. Provides more context as to what went wrong vs the previous message which was somewhat unclear.

@ghost ghost closed this Jul 12, 2021
@Rspigler
Copy link
Contributor

Please mark up for grabs

@bitcoin bitcoin locked and limited conversation to collaborators Nov 11, 2025
This pull request was closed.
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.

Error messages for invalid address

7 participants