-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Enhanced error messages for invalid network prefix during address parsing. #27260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/27260. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, 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. |
|
Please keep your changes, and "fixes" commits squashed. Looks like your changing the file perms on at least one file, is that intentional? |
Will do. No it was not intentional but was a side effect of moving 3 files over scp to a different host. This has been resolved and commits squashed. |
c98f7cc to
911c8b6
Compare
3c0fcda to
aff7635
Compare
|
Needs rebase on current master, if still relevant |
ef46a30 to
5ff2490
Compare
I believe this PR is still very relevant because it substantially improves the logic around address decoding and specifically the displaying of errors in the GUI and RPC. With that said I have rebased and this code is passing all tests other than |
|
Thanks, the reason I mentioned it was the silent merge conflict: |
Is there a good way to detect these silent conflicts earlier? Usually I get notified via email when there are issues that need rebased; this is the first time one has happened without a notification. Thanks |
73e3246 to
4232872
Compare
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
921a79c to
a3e6139
Compare
ef5e517 I am using this as a setup commit for the more logic like sections that are handled in key_io.cpp One of the hardest portions seems to be is that at some point this all converges into a case where you have to test that you don't have valid base58 or valid bech32 which inherently will have to run checks for both. |
223a709 to
42bddb2
Compare
- Add common prefixes and values to chainparams will be used in error string emmited from key_io.cpp. - This approach is sane and stable as chains don't change and these constants have becoome socal community consensus.
cd3cd31 to
6bc621e
Compare
|
The "test max 6 ancestor commits" job fails at eacf78c General address decoding logic exe order. This should fix it, by moving later changes into that commit: Sjors@aabb7df Some of the commit messages have weird trailing characters (adasda, etc). Noticed there's still a lot of bech32 related changes in c2c8454 Base58 decoding logic: despite the commit title, maybe split it further? |
- Fixes the core of incorrect network bech32 being decoded as Base58 - Requires an upfront bech32 decode and base58 decode (performance traded for accuracy) adasda sdfds
- Add expexted prefixes to base58 decoding based on network - Rework the case of invalid base58 and invalid bech32
- Add network prefixes to the bech32 decoding layer
- completely refactor testing to support network dependant tests and fully validates that error messages are diplayed correctly. - JSON test vector storage with migrated vectors + comments asdas
Thank you for the fixup! Applied Edit- Per the messages, it was getting late and I was flogging the rebase -i and made a mistake |
|
@portlandhodl, ping us when the PR is ready for review again. |
Improve Address Decoding Error Messages
Issue
DecodeDestinationdoes not properly handle errors when a user inputs a valid address for the wrong network (e.g., a testnet address while running the client on mainnet).The previous error messages were misleading. For example, "Invalid or unsupported Segwit (Bech32) or Base58 encoding" was displayed for a valid Bech32 address on a different network. This occurred because the
is_bech32variable only checked if the prefix matched the current network's HRP. If it didn't match, the code would fall through to Base58 decoding logic regardless of whether the string was actually a valid Bech32 address.Solution
Implementation Approach
Decode first, then validate: Instead of checking the prefix before decoding, we now decode the string using
bech32::Decode(str)upfront. This takes minimal CPU cycles and is acceptable since address validation is not a frequent operation.Gather decoding information: After Bech32 decoding, we also attempt
DecodeBase58(with a length of 100) andDecodeBase58Check. This provides enough information to properly diagnose errors.Provide network-aware error messages: When an address has an invalid prefix, the error message now includes the expected network values.
Changes Made
1. Add Base58 Encoded Prefixes to ChainParams (
src/kernel/chainparams.cpp,src/kernel/chainparams.h)2. Refactor Address Decoding Logic (
src/key_io.cpp)bech32::Decode(str)instead of checking prefix firstauto [bech32_encoding, bech32_hrp, bech32_chars] = bech32::Decode(str)3. Improved Error Messages
4. Test Updates
test/functional/data/rpc_validateaddress.jsonwith comprehensive test vectors for both mainnet and signettest/functional/rpc_validateaddress.pyto use data-driven testing across multiple networkstest/functional/rpc_invalid_address_message.pywith new error message expectationsConsistency Improvements
Reference