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

perf: mark the result of builder.IsZero as boolean to save constraints when used in future #977

Merged
merged 1 commit into from
Jan 4, 2024

Conversation

winderica
Copy link
Contributor

@winderica winderica commented Dec 20, 2023

Description

Hi there, thanks for your amazing work!

In the current implementation of gnark, builder.Select introduces a constraint to enforce that the condition is boolean. However, when the condition is from the result of builder.IsZero, this constraint is unnecessary, as builder.IsZero always returns a value m that is guaranteed to be either 0 or 1.

This PR marks m in builder.IsZero as boolean, so that we can save 1 constraint when using the result in subsequent operations like Select.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas (N/A)
  • I have made corresponding changes to the documentation (N/A)
  • I have added tests that prove my fix is effective or that my feature works (N/A)
  • I did not modify files generated from templates
  • golangci-lint does not output errors locally
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules (N/A)

@CLAassistant
Copy link

CLAassistant commented Dec 20, 2023

CLA assistant check
All committers have signed the CLA.

@ivokub
Copy link
Collaborator

ivokub commented Dec 21, 2023

Hi @winderica - thanks for the contribution. I have been busy before holidays to review but will definitely get to it next year. Sorry for the delay.

I think the fix would be useful but I would first have to see thoroughly the test suite to see if there are not unintended side-effects.

@gbotrel gbotrel self-requested a review January 4, 2024 15:06
Copy link
Collaborator

@gbotrel gbotrel left a comment

Choose a reason for hiding this comment

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

lgtm 👍

@gbotrel gbotrel merged commit 84ffe1c into Consensys:master Jan 4, 2024
3 of 5 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.

4 participants