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

[Fix] Square root #2049

Merged
merged 11 commits into from
Oct 17, 2023

Conversation

d0cd
Copy link
Collaborator

@d0cd d0cd commented Oct 6, 2023

This PR fixes a non-determinism issue in the square root circuit by ensuring that that result is less than (p - 1)/2, where p is the field modulus.

Note: this PR affects the elligator2::encode circuit. If determinism is not needed, we should consider adding a square_root_unchecked circuit.

This PR depends on #2072

@d0cd d0cd marked this pull request as ready for review October 10, 2023 18:28
@d0cd d0cd requested review from acoglio, howardwu and bendyarm October 10, 2023 18:28
Copy link
Contributor

@bendyarm bendyarm left a comment

Choose a reason for hiding this comment

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

Looks good!

@d0cd d0cd force-pushed the tracking/circuit-optimizations-and-fixes branch from 59429b5 to 2e4926b Compare October 13, 2023 21:04
@d0cd d0cd force-pushed the fix/non-det-in-sqrt branch from e304c9d to 23763ac Compare October 13, 2023 21:16
@d0cd d0cd changed the base branch from tracking/circuit-optimizations-and-fixes to fix/cast-field-to-group October 13, 2023 21:17
Base automatically changed from fix/cast-field-to-group to tracking/circuit-optimizations-and-fixes October 14, 2023 03:02
assert_eq!((88514, 130701, 83646), assignment.num_nonzeros());
assert_eq!(55698, assignment.num_private());
assert_eq!(55761, assignment.num_constraints());
assert_eq!((90368, 132045, 84980), assignment.num_nonzeros());
Copy link
Contributor

Choose a reason for hiding this comment

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

This pushes us to the next power of two here (2^18, as opposed to 2^17)

Copy link
Member

Choose a reason for hiding this comment

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

Great catch, I didn't notice that, thank you!

Copy link
Member

@howardwu howardwu Oct 14, 2023

Choose a reason for hiding this comment

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

I've addressed the imbalance with this PR:

@howardwu howardwu merged commit bd0ace1 into tracking/circuit-optimizations-and-fixes Oct 17, 2023
@howardwu howardwu deleted the fix/non-det-in-sqrt branch October 17, 2023 20:15
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.

5 participants