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

Add r < p check to FpMul #226

Merged
merged 6 commits into from
Oct 11, 2024
Merged

Add r < p check to FpMul #226

merged 6 commits into from
Oct 11, 2024

Conversation

SoraSuegami
Copy link
Collaborator

@SoraSuegami SoraSuegami commented Oct 6, 2024

Description

This PR fixes a potential attack vector in the FpMul circom template such that a remainder r larger than or equal to a module p can pass constraints.
Example: a=4, b=4, p=5, q=2, r=6.
To fix this vulnerability, I added a range check r < p to the FpMul circom template.

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • I have discussed with the team prior to submitting this PR
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes

@@ -41,6 +41,7 @@ template FpMul(n, k) {
component q_range_check[k];
signal r[k];
component r_range_check[k];
component r_p_range_check = BigLessThan(n,k);
Copy link
Member

Choose a reason for hiding this comment

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

r_p_range_check can be renamed to r_p_lt_check (or similar) as we usually use "range check" for checking bit length range.

Copy link
Member

@saleel saleel 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.
Added a minor comment.

@SoraSuegami SoraSuegami merged commit a6c3ecc into main Oct 11, 2024
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.

2 participants