Extend Field and Checksum for error correction#203
Merged
apoelstra merged 6 commits intorust-bitcoin:masterfrom Sep 19, 2024
Merged
Extend Field and Checksum for error correction#203apoelstra merged 6 commits intorust-bitcoin:masterfrom
Field and Checksum for error correction#203apoelstra merged 6 commits intorust-bitcoin:masterfrom
Conversation
This is purely a code refactor to get rid of a `use` statement (which will trigger an "unused code" warning if the macro is ever called somewhere where the Field trait is already in scope). As a side effect it reduces the size of the macro by roughly 75% in terms of line count.
Several methods (and we are going to add more) don't really belong in a general-purpose field trait, which really is just "a type that can be multiplied and added and has some associated constants". This isn't a general-purpose math library, but fields are a pretty common thing for people to want. And it's pretty easy for us to expose this trait in a nice way, so we might as well do it.
This will make it easier for PrintImpl to output error correction parameters. Since this is an implementation detail of the library, stick it into the Bech32Field trait rather than the Field one.
In the next commits we'll introduce a generic no-alloc container called FieldVec whose implementation will be much nicer if we have a Default bound on all of our field elements. This way we can implement the "FieldVec", which despite the name really has nothing to do with fields, purely in terms of core traits, rather than confusing readers of the code by having Field bounds everywhere without ever doing algebra. Since fields all have a ZERO member, which is a sensible output for Default, this bound is reasonable to require.
This adds some new methods to Field, which have default impls and are therefore non-breaking. (And they are general-purpose "field" things.)
clarkmoody
approved these changes
Sep 19, 2024
Member
clarkmoody
left a comment
There was a problem hiding this comment.
ACK f47ec0b
Tests running locally. The math is above my pay-grade.
Comment on lines
+122
to
+123
| /// Sealing trait. | ||
| pub trait Sealed {} |
apoelstra
added a commit
to apoelstra/rust-bech32
that referenced
this pull request
Sep 23, 2024
There are two parameterizations of the bech32 checksum (see the "roots" unit test in src/primitives/polynomial.rs for what they are). In rust-bitcoin#203 we mixed them up, using the generator from one but the exponents from the other. We made the same mistake with codex32 apparently. When we implement error correction this will cause failures. Fix it.
apoelstra
added a commit
to apoelstra/rust-bech32
that referenced
this pull request
Sep 30, 2024
There are two parameterizations of the bech32 checksum (see the "roots" unit test in src/primitives/polynomial.rs for what they are). In rust-bitcoin#203 we mixed them up, using the generator from one but the exponents from the other. We made the same mistake with codex32 apparently. When we implement error correction this will cause failures. Fix it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The first couple commits of this PR split the
Fieldtrait into two -- a generalFieldtrait which has the algebraic functionality of a field, and a sealedBech32Fieldtrait which has the functionality that is specific to this crate.The rest add new functionality to the traits which describe extra properties of our checksums needed for error correction.
The next PRs will:
FieldVectype to backPolynomialto make it work in a no-alloc setting (at least for small checksums, for a configurable notion of "small")