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

fix: issue with bit check in from_be_bytes #14

Merged
merged 1 commit into from
Sep 5, 2024

Conversation

madztheo
Copy link
Contributor

@madztheo madztheo commented Sep 4, 2024

Description

Fixes an issue with the from_be_bytes preventing the use of the function when the number of bits of the bytes passed as argument is the same as the number of bits encoding the modulus.

Problem*

fn from_be_bytes<let NBytes: u32>(x: [u8; NBytes]) -> BigNum<N, Params> {
        let num_bits = NBytes * 8;
        let modulus_bits = Params::modulus_bits();
        assert(num_bits > modulus_bits);
        assert(num_bits - modulus_bits < 8);
        ...
}

In the original code, when num_bits yields the same value as modulus_bits the assert fails and the function is usuable.

Summary*

As this behavior is not desired, simply replacing the strictly greater than with a greater than or equal fixes the issue:

fn from_be_bytes<let NBytes: u32>(x: [u8; NBytes]) -> BigNum<N, Params> {
        let num_bits = NBytes * 8;
        let modulus_bits = Params::modulus_bits();
        assert(num_bits >= modulus_bits);
        assert(num_bits - modulus_bits < 8);
        ...
}

Which is what this PR changes.

Additional Context

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@vezenovm vezenovm merged commit 79cd220 into noir-lang:main Sep 5, 2024
2 of 3 checks passed
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.

2 participants