Skip to content

correction: test a residue with zero syndromes - #334

Open
satsfy wants to merge 1 commit into
rust-bitcoin:masterfrom
satsfy:test-zero-syndromes
Open

satsfy wants to merge 1 commit into
rust-bitcoin:masterfrom
satsfy:test-zero-syndromes

Conversation

@satsfy

@satsfy satsfy commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Close #333

Since #331, the test regression_vector_7 no longer catches a mutant < to <= on the evaluator degree check, because the full residue check rejects that vector either way.

So the corrector finds errors by checking the residue at the generator polynomial roots listed in ROOT_EXPONENTS. A nonzero residue means the string has an error. Some checksums have generator roots that fall outside ROOT_EXPONENTS range, which means that these nonzero residues (errors) are undetected by the corrector alone because the corrector only check some of the roots.

The bch_errors() evaluator degree check is where that gets rejected. But if the check is done with <=, the input gets labled accepted carrying an error, so idx_err[0] panics meanwhile our tests entirely missed it.

To test that, we add a test with such a residue. It expects None from bch_errors() and panics if the check is <=.

NOTE: relied heavily on claude opus to understand the problem and the solution required. At least I learned a lot more about bech32, but please inspect it.

The corrector finds errors by checking the residue at the
generator polynomial roots listed in `ROOT_EXPONENTS`. A
nonzero residue means the string has an error. Some
checksums have generator roots that fall outside
`ROOT_EXPONENTS` range, which means that these nonzero
residues (errors) are undetected by the corrector alone.

The `bch_errors()` evaluator degree check is where that gets
rejected. But if the check is done with `<=`, the input gets
labled accepted carrying an error, so it will panic
meanwhile our tests entirely missed it.

To test that, we add a test with such a residue. It expects
`None` from `bch_errors()` and panics if the check is `<=`.
@apoelstra

Copy link
Copy Markdown
Member

This is a neat test but I don't think it makes any sense. The corrector_for_pattern function directly creates a Corrector, but the only way to construct this object from the public API is to have an incorrect string. So there's no way to make a Corrector with an empty error pattern, and I can't think of what the "correct" behavior would be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New Mutants Found

2 participants