This adds bech32 checks around the limits of bech32 strings, and the guarantees, as well as the limitations, of bech error detection.
The first commit adds those tests:
- validity of a bech32 string at the base max length, and invalidity after that
- validity of a bech32 string at the length limit for silent payment addresses (1023)
- failing checksums after 1-4 changes for length 90
- show that after 5 changes another valid checksum might exist
- failing checksum after 1-3 changes for length 1023
- show that after 4 changes another valid checksum might exist
- Show that LocateErrors can locate up to 2 errors
- Show that LocateErrors might locate a different solution to get a valid checksum
Second commit just modifies comments about error detection 'guarantees' around bech32 length limit constants. I think the formulation 'Guarantees finding up to N errors' is ambiguous. Someone might interpret it as 'fixes up to N errors', but it's not. It's not even 'Locates up to N errors', since LocateErrors() can find up to 2 errors. Now with the new 1023 length, LocateError can't even anymore guarantee finding the correct 2 errors (2 errors in one direction, 2 changes tried in the other direction, and we are beyond the 3 changes that guarantee there is no other possible valid checksum). So I think the comments should only say 'The checksum can detect up to N changes' instead, not guarantee more.
Context : Initially I was just looking at all code around Silent Payments, looked if the bech32 test had been updated to have tests for the new CharLimit::SILENT_PAYMENTS, and saw less tests than I expected.