arnaucube
arnaucube/go-snarkPublic Self-hosted repository
go-snark/r1csqap/README.md
r1csqap/README.mdRaw
 1## R1CS to Quadratic Arithmetic Program
 2[![GoDoc](https://godoc.org/github.com/arnaucube/go-snark/r1csqap?status.svg)](https://godoc.org/github.com/arnaucube/go-snark/r1csqap) R1CS to QAP
 3- `Succinct Non-Interactive Zero Knowledge for a von Neumann Architecture`, Eli Ben-Sasson, Alessandro Chiesa, Eran Tromer, Madars Virza https://eprint.iacr.org/2013/879.pdf
 4- Vitalik Buterin blog post about QAP https://medium.com/@VitalikButerin/quadratic-arithmetic-programs-from-zero-to-hero-f6d558cea649
 5- Ariel Gabizon in Zcash blog https://z.cash/blog/snark-explain5
 6- Lagrange polynomial Wikipedia article https://en.wikipedia.org/wiki/Lagrange_polynomial
 7
 8#### Usage
 9- R1CS to QAP
10```go
11pf := NewPolynomialField(f)
12
13b0 := big.NewInt(int64(0))
14b1 := big.NewInt(int64(1))
15b3 := big.NewInt(int64(3))
16b5 := big.NewInt(int64(5))
17b9 := big.NewInt(int64(9))
18b27 := big.NewInt(int64(27))
19b30 := big.NewInt(int64(30))
20b35 := big.NewInt(int64(35))
21a := [][]*big.Int{
22  []*big.Int{b0, b1, b0, b0, b0, b0},
23  []*big.Int{b0, b0, b0, b1, b0, b0},
24  []*big.Int{b0, b1, b0, b0, b1, b0},
25  []*big.Int{b5, b0, b0, b0, b0, b1},
26}
27b := [][]*big.Int{
28  []*big.Int{b0, b1, b0, b0, b0, b0},
29  []*big.Int{b0, b1, b0, b0, b0, b0},
30  []*big.Int{b1, b0, b0, b0, b0, b0},
31  []*big.Int{b1, b0, b0, b0, b0, b0},
32}
33c := [][]*big.Int{
34  []*big.Int{b0, b0, b0, b1, b0, b0},
35  []*big.Int{b0, b0, b0, b0, b1, b0},
36  []*big.Int{b0, b0, b0, b0, b0, b1},
37  []*big.Int{b0, b0, b1, b0, b0, b0},
38}
39alphas, betas, gammas, zx := pf.R1CSToQAP(a, b, c)
40fmt.Println(alphas)
41fmt.Println(betas)
42fmt.Println(gammas)
43fmt.Println(z)
44
45w := []*big.Int{b1, b3, b35, b9, b27, b30}
46ax, bx, cx, px := pf.CombinePolynomials(w, alphas, betas, gammas)
47fmt.Println(ax)
48fmt.Println(bx)
49fmt.Println(cx)
50fmt.Println(px)
51
52hx := pf.DivisorPolinomial(px, zx)
53fmt.Println(hx)
54```