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
These days, I have been studying about arithmetic in Circom, in order to implement UQ number with saturation arithmetic.
But some weird outcomes really bothered me.
(1) Why did the relational operator x > y fail?
var p_minus_one =21888242871839275222246405745257275088548364400416034343698204186575808495616;
assert(p_minus_one >0); // I got compiled error msg: error[T3001]: False assert reached
According to the docs, relational operators are based on a math function val(z).
In this case, p_minus_one would be val(p_minus_one) = 2188...5616, which is literally GLOBAL_FIELD_P minus integer one.
Hence, the condition p_minus_one > 0 should be hold and passed the assertion.
I believe that there must be something I have not understood, so I inaccurately think about how the above codes work.
(2) Is it available to access GLOBAL_FIELD_P in Circom language?
It doesn't a big problem.
I can do the some things like the above which just hard-coded numbers.
But I think there must be a more elegant way to achieve this task.
Thanks for anyone willing to reply me or give me the clues. 🙏❤
The text was updated successfully, but these errors were encountered:
a2468834
changed the title
[Question] Some problems around GLOBAL_FIELD_P
[Question] About GLOBAL_FIELD_P
Oct 19, 2021
I got the answer from iden3 telegram group, thanks everyone. 🙏
Circom defines the range of positives are [0, p/2] and the range of negatives are [(p/2)+1, (p-1)].
You could find more information at val(z) in the section "Relational operators" of this page.
Although there is no negative number in the formal finite field GF(p), Circom devs choose a slightly different definition for convenience.
[Update @11/23] Here are some useful constants
10944121435919637611123202872628637544274182200208017171849102093287904247808 // The most positive number
10944121435919637611123202872628637544274182200208017171849102093287904247809 // The most negative number
21888242871839275222246405745257275088548364400416034343698204186575808495616 // aka (-1) in int32
Hello everyone~ 😀
These days, I have been studying about arithmetic in Circom, in order to implement UQ number with saturation arithmetic.
But some weird outcomes really bothered me.
(1) Why did the relational operator
x > y
fail?According to the docs, relational operators are based on a math function
val(z)
.In this case,
p_minus_one
would beval(p_minus_one) = 2188...5616
, which is literallyGLOBAL_FIELD_P
minus integer one.Hence, the condition
p_minus_one > 0
should be hold and passed the assertion.I believe that there must be something I have not understood, so I inaccurately think about how the above codes work.
(2) Is it available to access
GLOBAL_FIELD_P
in Circom language?It doesn't a big problem.
I can do the some things like the above which just hard-coded numbers.
But I think there must be a more elegant way to achieve this task.
Thanks for anyone willing to reply me or give me the clues. 🙏❤
The text was updated successfully, but these errors were encountered: