fix: conditional check in non-native IsZero for applying optimization #1145
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
In non-native
IsZero
check we previously checked that every limb is zero, then multiplied the results and returned it. However, as the limbs are significantly smaller than the native field, then we can use the optimization that we add the limbs and perform only a singleIsZero
check.However, the optimization we had implemented checks the condition wrong way. This prevents the optimized path to be taken.
This could lead to a underconstrained circuit in extreme cases which are not possible with the emulated parameters defined in gnark (number of limbs has to be greater than the maximal allowed overflow. This means having approximately 190 limbs, but in our parameters the maximum number of limbs is 64).
Type of change
Checklist:
golangci-lint
does not output errors locally