-
Notifications
You must be signed in to change notification settings - Fork 204
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
acir_field
's FieldElement::is_negative
invalid in some cases
#5174
Comments
I've had a little look into this and the logic of this function is correct for how we're using it. The only place we're using it is when converting a field element into an i128 and so we're going to have values in the ranges 0..2^127-1 (representing positive integers) and p-2^127..p (representing negative integers). If we were to use field elements outside of this range we would get invalid results anyway. That said, this method is devoid of any context as it is which opens it up to being misused in future. We should just inline it into |
# Description ## Problem\* Resolves #5174 ## Summary\* This PR inlines `FieldElement.is_negative` into `FieldElement.to_i128` so it can't be misused elsewhere while documenting the reasoning behind it. ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
Aim
FieldElement::is_negative
should be correct in all casesExpected Behavior
I expect
FieldElement::is_negative
to be correct in all casesBug
acvm-repo/acir_field/src/field_element.rs
As far as I can tell, this will be incorrect when the field element is in the middle of its range.
Instead, I believe we should compare without
num_bits
, i.e.self.neg() < self
To Reproduce
No response
Project Impact
None
Impact Context
No response
Workaround
None
Workaround Description
No response
Additional Context
No response
Installation Method
None
Nargo Version
No response
NoirJS Version
No response
Would you like to submit a PR for this Issue?
None
Support Needs
No response
The text was updated successfully, but these errors were encountered: