-
Notifications
You must be signed in to change notification settings - Fork 49
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
More error correction preparation (upgrades to Field
, Polynomial
, InvalidResidueError
and others)
#202
Commits on Sep 18, 2024
-
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.
Configuration menu - View commit details
-
Copy full SHA for 8eaec9d - Browse repository at this point
Copy the full SHA 8eaec9dView commit details -
field: split trait into "normal" field trait and sealed trait
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.
Configuration menu - View commit details
-
Copy full SHA for 3c97cd1 - Browse repository at this point
Copy the full SHA 3c97cd1View commit details -
field: add format_as_rust_code utility method
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.
Configuration menu - View commit details
-
Copy full SHA for 011674d - Browse repository at this point
Copy the full SHA 011674dView commit details -
field: add Default bound to Field
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.
Configuration menu - View commit details
-
Copy full SHA for 14e4f7b - Browse repository at this point
Copy the full SHA 14e4f7bView commit details -
Configuration menu - View commit details
-
Copy full SHA for c389d72 - Browse repository at this point
Copy the full SHA c389d72View commit details -
This adds some new methods to Field, which have default impls and are therefore non-breaking. (And they are general-purpose "field" things.)
Configuration menu - View commit details
-
Copy full SHA for f47ec0b - Browse repository at this point
Copy the full SHA f47ec0bView commit details -
primitives: introduce FieldVec type
This will allow `Polynomial` to work without an allocator (at least for "small" checksums, including every checksum supported by this library). Here a "small" checksum is one of length at most 6 (which covers bech32 and bech32m). codex32 (13 characters) and "long codex32" (15 characters) will not work with no-alloc. I would kinda like to fix this but it results in large types, especially a large InvalidResidueError type, so probably it will need to be feature-gated or something. For now we just punt on it.
Configuration menu - View commit details
-
Copy full SHA for d548ce5 - Browse repository at this point
Copy the full SHA d548ce5View commit details -
polynomial: use FieldVec in Polynomial
We can now use `PrintImpl` even without an allocator. This is of limited use of course, but it paves the ground for use to do error correction without an allocator, which is interesting.
Configuration menu - View commit details
-
Copy full SHA for 1fce601 - Browse repository at this point
Copy the full SHA 1fce601View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2d3833c - Browse repository at this point
Copy the full SHA 2d3833cView commit details -
primitives: introduce InvalidResidueError
We are going to want to extend the ChecksumError::InvalidResidue error variant to allow error correction, and in order to do so, we need to know the actual residue computed from a string, not just that the residue failed to match the target. Uses the `Polynomial` type; see the previous commits for some caveats about this type when alloc is disabled. (Prior to this PR, you just couldn't use Polynomial at all without alloc.) As an initial application of the new error, avoid re-validating a bech32 address to handle the distinction between bech32m and bech32. Instead, if bech32m validation fails, check if the "bad" residue actually matches the bech32 target. If so, accept. On my system this reduces the `bech32_parse_address` benchmark from 610ns to 455ns, more than a 33% speedup.
Configuration menu - View commit details
-
Copy full SHA for 09bcf08 - Browse repository at this point
Copy the full SHA 09bcf08View commit details