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

How to initialize a number on the prime field? #23

Closed
w1001766 opened this issue Apr 7, 2020 · 1 comment
Closed

How to initialize a number on the prime field? #23

w1001766 opened this issue Apr 7, 2020 · 1 comment

Comments

@w1001766
Copy link

w1001766 commented Apr 7, 2020

I was testing the circuit evaluation, and I am trying to initialize some random number on the prime field by doing this in jsnark/libsnark/src/CircuitReader.cpp:

FieldT a = 10000000000000;

When I do a.print(), I got some garbage value. But when I run it on a real circuit and trying to print out some of the wire values, it actually works. Did I do something wrong?

@akosba
Copy link
Owner

akosba commented Apr 8, 2020

I was testing the circuit evaluation, and I am trying to initialize some random number on the prime field by doing this in jsnark/libsnark/src/CircuitReader.cpp: FieldT a = 10000000000000; When I do a.print(), I got some garbage value.

This seems to be related to libsnark (or libff, to be more accurate).
I tried the case you mentioned:

FieldT a = 10000000000000;
a.print()

and it is working fine. Was that the same test case you tried? What is the range of the random number you are trying to assign?

Note that if you try much greater numbers, the result will seem unexpected to you, as I think this is expected to fit into a long. If the range of the random value you're trying to assign is greater than the allowed range, you could try to look into other ways to assign the value to a FieldT variable. (I think you could find this by inspecting the code of Fp in libff. If I recall correctly, you should be able to provide the number as a string, e.g., FieldT("..."), where the argument is the decimal representation of the string. See Fp and Bigint.)

@akosba akosba closed this as completed Apr 14, 2020
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

2 participants