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

checks in int are not enough #242

Open
mimoo opened this issue Dec 10, 2024 · 0 comments · May be fixed by #243
Open

checks in int are not enough #242

mimoo opened this issue Dec 10, 2024 · 0 comments · May be fixed by #243
Assignees
Labels
bug Something isn't working

Comments

@mimoo
Copy link
Contributor

mimoo commented Dec 10, 2024

this check is not good enough: https://github.com/zksecurity/noname/blob/main/src/stdlib/native/int/lib.no#L17

fn Uint8.new(val: Field) -> Uint8 {
    let bit_len = 8;

    bits::check_field_size(bit_len);

why? Because when we multiply:

fn Uint8.mul(self, rhs: Uint8) -> Uint8 {
    return Uint8.new(self.inner * rhs.inner);
}

we might return a value of 16 bits here. If our field modulus is 16 bits (or lower), then the multiplication might wrap around

so we need to check that the field modulus is 17 bits at least so it can contain the result of that multiplication

so I think it should be bits::assert_circuit_field_strictly_larger_than(bit_len * 2)

@mimoo mimoo added the bug Something isn't working label Dec 10, 2024
@katat katat linked a pull request Dec 11, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants