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(utils/safe-comparators): constrain inputs to n bits #20

Merged

Conversation

0x471
Copy link
Contributor

@0x471 0x471 commented Feb 9, 2025

re #15

Description

  • Added range checks to ensure inputs are constrained to n bits using Num2Bits.
  • Corrected the instantiation of Num2Bits to use n + 1 bits for handling potential overflow.
  • Added comments to clarify the logic for determining if one input is less than another.

Related Issue(s)

Closes #15

Other information

Checklist

  • I have read and understand the contributor guidelines and code of conduct.
  • 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
  • I have run yarn style without getting any errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Important

We do not accept minor grammatical fixes (e.g., correcting typos, rewording sentences) unless they significantly improve clarity in technical documentation. These contributions, while appreciated, are not a priority for merging. If there is a grammatical mistake, please feel free to message the team.

@0x471 0x471 requested a review from 0xjei as a code owner February 9, 2025 02:01
// Constrain inputs to n bits
component range_check[2];
for (var i = 0; i < 2; i++) {
range_check[i] = Num2Bits(n);

Check warning

Code scanning / Circomspect

Using Num2Bits to convert field elements to bits may lead to aliasing issues. Warning

Using Num2Bits to convert field elements to bits may lead to aliasing issues.
// Additional conversion to handle arithmetic operation and capture the comparison result.
var n2b[254];
n2b = Num2Bits_strict()(in[0] + (1<<n) - in[1]);
component n2b = Num2Bits(n + 1);

Check warning

Code scanning / Circomspect

Using Num2Bits to convert field elements to bits may lead to aliasing issues. Warning

Using Num2Bits to convert field elements to bits may lead to aliasing issues.
@0x471 0x471 changed the title fix(utils): fix(safe-comparators): constrain inputs to n bits fix(utils/safe-comparators): constrain inputs to n bits Feb 9, 2025
Copy link
Member

@cedoor cedoor left a comment

Choose a reason for hiding this comment

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

LGTM thanks!

@cedoor cedoor merged commit e6e5355 into privacy-scaling-explorations:main Feb 10, 2025
3 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.

SafeLessThan is unsafe
2 participants