You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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).
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
The text was updated successfully, but these errors were encountered:
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, asnargo compile
worked well and compiled my program.Let's consider the following code :
with
firstX
andsecondX
being 2u32
. The if statement makes surefirstX
is greater thansecondX
, making sure the substractionfirstX - 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: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 :
should work without additional treatment of
firstX
andsecondX
.Bug
In order to make
nargo prove
working, the snippet of code needs to be modified as follows: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
andsecondX
shouldn't be necessary, asdiffX = 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
The text was updated successfully, but these errors were encountered: