scipr-lab / libsnark

C++ library for zkSNARKs
Other
1.8k stars 570 forks source link

convert a problem to a QAP #111

Open ariary opened 6 years ago

ariary commented 6 years ago

Hi everyone! I have 1 theorical question and one technical.

Theorical:

zk-SNARKs can be applied to any QAP (Quadratic Arithmetic Program). Thus, when we want to use our problem with zk-SNARK we have to "translate" (compile) it in a QAP form. here is the path to follow: problem --> Algebric circuit --> RC1S-->QAP Here is my question: how to translate our problem to a RC1S form? For example, if I want to prove that I know the secret value of a transaction (like in Zcash) how can I modelize it?

Technical:

Now admit that we have our problem modelize in the right form. How can I plug it with the code? For example the following R1CS system:

A
[0, 1, 0, 0, 0, 0]
[0, 0, 0, 1, 0, 0]
[0, 1, 0, 0, 1, 0]
[5, 0, 0, 0, 0, 1]
B
[0, 1, 0, 0, 0, 0]
[0, 1, 0, 0, 0, 0]
[1, 0, 0, 0, 0, 0]
[1, 0, 0, 0, 0, 0]
C
[0, 0, 0, 1, 0, 0]
[0, 0, 0, 0, 1, 0]
[0, 0, 0, 0, 0, 1]
[0, 0, 1, 0, 0, 0]

with witness: [1, 3, 35, 9, 27, 30]

The flattened code is:

sym_1 = x * x
y = sym_1 * x
sym_2 = y + x
~out = sym_2 + 5                           //x**3 + x +5 = 35
barryWhiteHat commented 6 years ago

how to translate our problem to a RC1S form?

Do you want to translate from a QAP to R1CS?

How can I plug it with the code?

Here is an example of how to make a r1cs from input matrixs https://github.com/JacobEberhardt/ZoKrates/blob/develop/lib/wraplibsnark.cpp#L76

ariary commented 6 years ago

@barryWhiteHat no, from a generic problem (for example: we want to prove that we know the pre-image of hash) to a R1CS.

I try the qed-it "tutorial" to understand more deeply but I have to admit that it is a little bit tricky

barryWhiteHat commented 6 years ago

If you want a generic programing language you could check https://github.com/JacobEberhardt/ZoKrates https://github.com/akosba/jsnark https://github.com/o1-labs/snarky