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

[Question] About GLOBAL_FIELD_P #11

Closed
a2468834 opened this issue Oct 16, 2021 · 1 comment
Closed

[Question] About GLOBAL_FIELD_P #11

a2468834 opened this issue Oct 16, 2021 · 1 comment

Comments

@a2468834
Copy link

a2468834 commented Oct 16, 2021

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?

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. 🙏❤

@a2468834 a2468834 changed the title [Question] Some problems around GLOBAL_FIELD_P [Question] About GLOBAL_FIELD_P Oct 19, 2021
@a2468834
Copy link
Author

a2468834 commented Oct 21, 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

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

No branches or pull requests

1 participant