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

Unexpected overflow error while using nargo prove. #3640

Closed
TAdev0 opened this issue Nov 30, 2023 · 3 comments
Closed

Unexpected overflow error while using nargo prove. #3640

TAdev0 opened this issue Nov 30, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@TAdev0
Copy link
Contributor

TAdev0 commented Nov 30, 2023

Aim

While working on a small Noir program, I ran into an issue related to overflow/underflow detection using nargo prove command. This bug doesn't concern compilation, as nargo compile worked well and compiled my program.

Let's consider the following code :

 if (firstX > secondX) {
            diffX = firstX - secondX;
        }

with firstX and secondX being 2 u32. The if statement makes sure firstX is greater than secondX, making sure the substraction firstX - secondX will never encounter underflow issue.

Neverthless, when using nargo prove to generate a proof of my program with valid inputs, i get this error:

error: Assertion failed: 'attempt to subtract with overflow'

This seems odd as there is no situation in which there is an overflow (moreover, subtraction could theoretically only lead to underflow with uint values).

Expected Behavior

The short snippet of code :

 if (firstX > secondX) {
            diffX = firstX - secondX;
        }

should work without additional treatment of firstX and secondX.

Bug

In order to make nargo prove working, the snippet of code needs to be modified as follows:

        if (firstX > secondX) {
            diffX = std::wrapping_sub(firstX, secondX);
        }

std::wrapping_sub is not mentioned in Noir Documentation . I guess this is supposed to compute a modular subtraction, just like in Rust.
Nonetheless, wrapping firstX and secondX shouldn't be necessary, as diffX = firstX - secondX; will never require modular arithmetic in order to be computed successfully.

Installation Method

Noirup

Nargo Version

nargo 0.19.2

Would you like to submit a PR for this Issue?

Yes

@TAdev0 TAdev0 added the bug Something isn't working label Nov 30, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Nov 30, 2023
@TAdev0
Copy link
Contributor Author

TAdev0 commented Nov 30, 2023

@jfecher @kevaundray it seems this issue has already been reported, could you confirm this? Thank you.

@akonior
Copy link
Contributor

akonior commented Nov 30, 2023

Duplicate of issue #3493 and should already be fixed by PR #3494. Will be fixed in release 0.19.3.

@TomAFrench
Copy link
Member

Yep, this bug should already be fixed in 0.19.3. Updating to this release will fix the issue.

Thanks for your help @akonior :)

@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

3 participants