Skip to content
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

Implement error correction #205

Merged
merged 7 commits into from
Oct 18, 2024

Commits on Sep 30, 2024

  1. bech32: use correct generator exponents

    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 committed Sep 30, 2024
    Configuration menu
    Copy the full SHA
    74ec75f View commit details
    Browse the repository at this point in the history
  2. field: add ability to multiply by integers

    Adds a CHARACTERISTIC constant to the Field trait, so this is yet
    another breaking change (though in practice I don't think anybody is
    implementing Field on their own types).
    apoelstra committed Sep 30, 2024
    Configuration menu
    Copy the full SHA
    4dfe325 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    fc903d6 View commit details
    Browse the repository at this point in the history
  4. primitives: introduce the Berlekamp-Massey algorithm for computing li…

    …near shift registers
    
    This provides a general-purpose implementation of the Berlekamp-Massey
    algorithm for finding a linear shift register that generates a given
    sequence prefix.
    
    If compiled without an allocator, it will run less efficiently (and be
    limited to a maximum size) but it will work.
    
    Also introduces a fuzz test to check that it works properly and does not
    crash.
    apoelstra committed Sep 30, 2024
    Configuration menu
    Copy the full SHA
    6c24f98 View commit details
    Browse the repository at this point in the history
  5. implement error correction

    This commit pulls everything together. The actual error correction code
    isn't too big: we interpret a residue as a polynomial, evaluate it at
    various powers of alpha to get a syndrome polynomial, call
    berlekeamp-massey on this to get a "connection polynomial", then use
    Forney's algorithm to get the actual error values.
    
    Each step in the above is encapsulated separately -- the "big" stuff, in
    particular Berlekamp-Massey and obtaining the relevant constants from
    the checksum definition, were in previous commits.
    
    This PR does need to add some more functionality to Polynomial.
    Specifically we need the ability to evaluate polynomials, take their
    formal derivatives, and multiply them modulo x^d for a given d. These
    are the bulk of this PR.
    
    The next commit will introduce a fuzztest which hammers on the
    correction logic to ensure that it's not crashing.
    apoelstra committed Sep 30, 2024
    Configuration menu
    Copy the full SHA
    2e1b7be View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    383f788 View commit details
    Browse the repository at this point in the history
  7. fuzz: add fuzztests that try to correct bech32 and codex32 errors

    The codex32 test will more thoroughly exercise the algebra, since there
    we can correct up to 4 errors. The bech32 test on the other hand should
    work without an allocator (though to exercise this you need to manually
    edit fuzz/Cargo.toml to disable the alloc feature -- this is
    
    rust-lang/cargo#2980
    
    which has been open for 10 years and counting..)
    apoelstra committed Sep 30, 2024
    Configuration menu
    Copy the full SHA
    76d0dae View commit details
    Browse the repository at this point in the history