-
Notifications
You must be signed in to change notification settings - Fork 87
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 underconstrained sign
function.
#84
Conversation
- `sign` has been moved from `maingate` to `integer` - An extra range check on the auxiliary witness has been added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's okay to check only the sign of least significant limb if the value is in canonical form (reduced), but in the original impl we are using the least significant limb of unreduced a
, which might have alias.
I think we could fix this by change:
- self.assert_in_field(ctx, a)?;
+ let a = &self.reduce_if_limb_values_exceeds_reduced(ctx, a)?;
+ let a = &self.reduce_if_max_operand_value_exceeds(ctx, a)?;
Does this make sense @kilic? And I'm not sure if we need to do assert_in_field
or not, I thought by design all AssignedInteger
should be already checked in field.
I think we need to |
Yes, we need to make sure it's in canonical form, otherwise the sign will be different. So the original api seems incorrect because it might use the unreduced integer to retrieve the sign (the integer is reduced in Just checked the impl again, I agree that we need to call |
@han0110 @davidnevadoc |
Another way to work around this problem is to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reduce
function is lazy it does not enforce the reduction into field but enforces to be in next power of two of the modulus
I see now, thanks for explaination
Description
The
sign
function inmaingate
returns the parity of a field element.In order to do this for an element
x
it exhibits thatx = 2 * k + sign
. Where sign is 0 or 1 andk
is an auxiliary witness.However,
k
needs to be range checked so that this equation doesn't wrap around, inverting the sign.Note: It would be great to find a way to implement this function without the need for range checks, but I haven't been able to do so.
Any suggestions in this direction are greatly appreciated.
Changes
sign
has been moved frommaingate
tointeger