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

FpVar::{is_eq, is_neq} only need two constraints #133

Merged
merged 4 commits into from
Dec 28, 2023

Conversation

winderica
Copy link
Contributor

@winderica winderica commented Dec 20, 2023

Description

Hi there, thanks for your amazing work!

This PR reduces 1 constraint in FpVar::{is_eq, is_neq} (and in turn, is_zero, etc.), by observing that we can remove the booleanity check while preserving soundness.

This is because:

  • The first constraint (self - other) * multiplier = is_not_equal guarantees is_not_equal = 0 when self - other = 0. Otherwise, we cannot find a multiplier such that (self - other) * multiplier = 0 * multiplier = is_not_equal != 0
  • The second constraint (self - other) * not(is_not_equal) = 0 guarantees is_not_equal = 1 when self - other != 0. Otherwise, not(is_not_equal) = 1 - is_not_equal != 0, which indicates a contradiction self - other = 0.

See also gnark's implementation: https://github.com/Consensys/gnark/blob/870ef4efa8c9fa11a8778821c8376286207ca19b/frontend/cs/r1cs/api.go#L535-L569

Please correct me if I misunderstood something :)


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (master)
  • Linked to Github issue with discussion and accepted design OR have an explanation in the PR that describes this work.
  • Wrote unit tests (N/A)
  • Updated relevant documentation in the code
  • Added a relevant changelog entry to the Pending section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

@winderica winderica requested a review from a team as a code owner December 20, 2023 14:21
@winderica winderica requested review from Pratyush, mmagician and weikengchen and removed request for a team December 20, 2023 14:21
Copy link
Member

@Pratyush Pratyush left a comment

Choose a reason for hiding this comment

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

Thanks for the optimization! I left a small nit to add some more explanation of why the booleanity constraint is implicitly enforced.

src/fields/fp/mod.rs Show resolved Hide resolved
src/fields/fp/mod.rs Outdated Show resolved Hide resolved
@Pratyush Pratyush changed the title FpVar::{is_eq, is_neq} only need two constraints FpVar::{is_eq, is_neq} only need two constraints Dec 22, 2023
@Pratyush Pratyush merged commit 3cb9fde into arkworks-rs:master Dec 28, 2023
5 of 11 checks passed
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.

2 participants