test: check guarantees of bech32 error detection #36690

pull bartoli wants to merge 2 commits into bitcoin:master from bartoli:bech32_tests changing 2 files +93 −2
  1. bartoli commented at 9:02 PM on October 28, 2026: none

    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.

  2. bech32: test error detection guarantees
    Add tests around error detection guarantees on bech32 strings
    - validity at base max length(90) and silent payments max length (1023)
    - checksum failure after up to 4 changes at length 90
    - and potential checksum success after 5 changes at length 90
    - LocateError can't find more than 2 errors
    - checksum failure after up to 3 changes at length 1023
    - potential checksum success after 4 changesi at length 1023
    - LocateError can find different errors at length 1023
    c689d92ddf
  3. bech32 : rephrase error detection guarantees
    Saying "Guarantees finding N errors" is ambiguous and can lead to fake
    illusion of safety. We can only guarantee that up to N character changes
    can lead to no other valid checksum.
    Not that we can detect, locate or even less fix N errors
    38e87b989d
  4. DrahtBot added the label Tests on Oct 28, 2026
  5. DrahtBot commented at 9:03 PM on October 28, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

Contributors
Labels

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-10-29 06:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me