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 potential uint overflow #243

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

fix potential uint overflow #243

wants to merge 1 commit into from

Conversation

katat
Copy link
Collaborator

@katat katat commented Dec 11, 2024

fixes #242

@@ -14,7 +14,8 @@ struct Uint8 {
fn Uint8.new(val: Field) -> Uint8 {
let bit_len = 8;

bits::check_field_size(bit_len);
// has to ensure multiply won't overflow prime field
bits::check_field_size(bit_len * 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it off by one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inside check_field_size, it checks the prime field is strictly greater than bit_len * 2:

if to_cmp >= bit_len {
    return Err(Error::new(
        "constraint-generation",
        ErrorKind::AssertionFailed,
        span,
    ));
}

So the prime field bit len is ensured to have at least one more bit than the test value.

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.

checks in int are not enough
2 participants