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

feat: better IntegerDivisionimplementation #18

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

0x471
Copy link

@0x471 0x471 commented Jan 4, 2025

Description

This PR introduces a better IntegerDivisontemplate
There are none breaking changes.

Related Issue(s)

Closes #14

Checklist

  • My code follows the style guidelines of this project
  • 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 format and yarn compile 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

It generates new warnings:

circomspect: analyzing template 'MultiplicationFromFloat'
warning: The output signal `remainder` defined by the template `IntegerDivision` is not constrained in `MultiplicationFromFloat`.
    ┌─ /Users/peterpan/rd/p/zk-kit.circom/packages/utils/src/float.circom:158:23
    │
158 │     (quotient, _) <== IntegerDivision()(a * b, 10 ** W);
    │                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The template `IntegerDivision` is instantiated here.
    │
    = For more details, see https://github.com/trailofbits/circomspect/blob/main/doc/analysis_passes.md#unused-output-signal.

warning: Using the signal assignment operator `<--` does not constrain the assigned signal.
   ┌─ /Users/peterpan/rd/p/zk-kit.circom/packages/utils/src/float.circom:55:5
   │
55 │     quotient <-- dividend \ divisor;
   │     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The assigned signal `quotient` is not constrained here.
   ·
63 │     dividend === divisor * quotient + remainder;
   │     -------------------------------------------- The signal `quotient` is constrained here.
   │
   = For more details, see https://github.com/trailofbits/circomspect/blob/main/doc/analysis_passes.md#signal-assignment.


circomspect: analyzing template 'IntegerDivision'
warning: Using the signal assignment operator `<--` does not constrain the assigned signal.
   ┌─ /Users/peterpan/rd/p/zk-kit.circom/packages/utils/src/float.circom:56:5
   │
56 │     remainder <-- dividend % divisor;
   │     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The assigned signal `remainder` is not constrained here.
   ·
59 │     signal isLessThan <== SafeLessThan(252)([remainder, divisor]);
   │                           --------------------------------------- The signal `remainder` is constrained here.
   ·
63 │     dividend === divisor * quotient + remainder;
   │     -------------------------------------------- The signal `remainder` is constrained here.
   │
   = For more details, see https://github.com/trailofbits/circomspect/blob/main/doc/analysis_passes.md#signal-assignment.

circomspect: analyzing template 'DivisionFromFloat'
warning: The output signal `remainder` defined by the template `IntegerDivision` is not constrained in `DivisionFromFloat`.
    ┌─ /Users/peterpan/rd/p/zk-kit.circom/packages/utils/src/float.circom:107:23
    │
107 │     (quotient, _) <== IntegerDivision()(a * (10 ** W), b);
    │                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The template `IntegerDivision` is instantiated here.
    │
    = For more details, see https://github.com/trailofbits/circomspect/blob/main/doc/analysis_passes.md#unused-output-signal.

@0x471 0x471 requested a review from 0xjei as a code owner January 4, 2025 14:30
@cedoor cedoor self-requested a review January 6, 2025 15:12
signal output remainder;

assert(divisor != 0);
quotient <-- dividend \ divisor;

Check warning

Code scanning / Circomspect

Using the signal assignment operator <-- does not constrain the assigned signal. Warning

Using the signal assignment operator <-- does not constrain the assigned signal.

assert(divisor != 0);
quotient <-- dividend \ divisor;
remainder <-- dividend % divisor;

Check warning

Code scanning / Circomspect

Using the signal assignment operator <-- does not constrain the assigned signal. Warning

Using the signal assignment operator <-- does not constrain the assigned signal.
c <== IntegerDivision(n)(a * (10 ** W), b);
// Use tuple assignment to get both quotient and remainder
signal quotient;
(quotient, _) <== IntegerDivision()(a * (10 ** W), b);

Check warning

Code scanning / Circomspect

The output signal remainder defined by the template IntegerDivision is not constrained in DivisionFromFloat. Warning

The output signal remainder defined by the template IntegerDivision is not constrained in DivisionFromFloat.
// Perform integer division after multiplication to adjust the result back to W decimal digits.
c <== IntegerDivision(n)(a * b, 10 ** W);
signal quotient;
(quotient, _) <== IntegerDivision()(a * b, 10 ** W);

Check warning

Code scanning / Circomspect

The output signal remainder defined by the template IntegerDivision is not constrained in MultiplicationFromFloat. Warning

The output signal remainder defined by the template IntegerDivision is not constrained in MultiplicationFromFloat.
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.

better IntegerDivision implementation
1 participant