elibensasson / libSTARK

A library for zero knowledge (ZK) scalable transparent argument of knowledge (STARK)
Other
507 stars 90 forks source link

Questions about TinyRAM #15

Open jimouris opened 5 years ago

jimouris commented 5 years ago

Hello,

I have some questions about TinyRAM. Does TinyRAM support labels and comments as claimed in the documentation?

Also, how can I see the result of the ANSWER instruction?

How I can give input? It seems that there are two tapes, for primary and auxiliary input respectively, and that there is a read instruction that reads from the tapes, however, I could not find any example on how to use it.

Finally, UMOD seems to be broken. I have filled some registers with values and when I call UMOD I get ERROR: Fatal error encoutered. Run debug build for more information and stack trace. Example usage:

MOV r0 r0 9
MOV r1 r0 4
UMOD r5 r0 r1
ANSWER r5 r5 r5

Thanks in advance, Dimitris Mouris

iddo333 commented 5 years ago

About labels, the current implementation is rather low-level and the programmer needs to take care of label handling. You can see for example in the file tinyram/stark-tinyram-tests/ConstraintsSystem2Bair_UTEST.cpp that there are label comments such as /L5/ to represent line#5 in MachineInstruction instruction2(Opcode::CJMP, true, 0, 0, 20 /L5/); It is also presented a little more clearly in Appendix C of https://eprint.iacr.org/2016/646

About the output of the ANSWER instruction, it is implemented in ALU_ANSWER_Gadget::generateWitness() of tinyram/stark-tinyram/src/TinyRAMtoBair/RamToContraintSystem/ALU.cpp (the current code has verbose printout at the end of this function but it's commented-out, you can comment-in this code).

jimouris commented 5 years ago

@iddo333 Thanks for your reply.

I saw the L5 that you mention in the source code and also the Line#linenumber notation in the paper, but it seems that TinyRAM uses just a line number in jump instructions. It's line-numbers not PC numbers, thanks.

About the ANSWER, it didn't compile at first since #include <iostream> was missing from ALU.cpp, but with this addition it worked fine. I already had a pull request #16 about another typo in ALU.cpp, I also added the forgotten iostream.

What about the input tapes with the read instruction? Is there another way to give input to a TinyRAM program?

Finally, are all the hardcoded inputs in the asm programs public? For example, in a MOV r0 r0 5, is 5 public (shared with the verifier), or it remains private (only the prover knows it)? In either case, how can I have private variables?

Thanks!