You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.8 KiB

  1. ## R1CS to Quadratic Arithmetic Program
  2. [![GoDoc](https://godoc.org/github.com/arnaucube/go-snark-study/r1csqap?status.svg)](https://godoc.org/github.com/arnaucube/go-snark-study/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. #### Usage
  8. - R1CS to QAP
  9. ```go
  10. pf := NewPolynomialField(f)
  11. b0 := big.NewInt(int64(0))
  12. b1 := big.NewInt(int64(1))
  13. b3 := big.NewInt(int64(3))
  14. b5 := big.NewInt(int64(5))
  15. b9 := big.NewInt(int64(9))
  16. b27 := big.NewInt(int64(27))
  17. b30 := big.NewInt(int64(30))
  18. b35 := big.NewInt(int64(35))
  19. a := [][]*big.Int{
  20. []*big.Int{b0, b1, b0, b0, b0, b0},
  21. []*big.Int{b0, b0, b0, b1, b0, b0},
  22. []*big.Int{b0, b1, b0, b0, b1, b0},
  23. []*big.Int{b5, b0, b0, b0, b0, b1},
  24. }
  25. b := [][]*big.Int{
  26. []*big.Int{b0, b1, b0, b0, b0, b0},
  27. []*big.Int{b0, b1, b0, b0, b0, b0},
  28. []*big.Int{b1, b0, b0, b0, b0, b0},
  29. []*big.Int{b1, b0, b0, b0, b0, b0},
  30. }
  31. c := [][]*big.Int{
  32. []*big.Int{b0, b0, b0, b1, b0, b0},
  33. []*big.Int{b0, b0, b0, b0, b1, b0},
  34. []*big.Int{b0, b0, b0, b0, b0, b1},
  35. []*big.Int{b0, b0, b1, b0, b0, b0},
  36. }
  37. alphas, betas, gammas, zx := pf.R1CSToQAP(a, b, c)
  38. fmt.Println(alphas)
  39. fmt.Println(betas)
  40. fmt.Println(gammas)
  41. fmt.Println(z)
  42. w := []*big.Int{b1, b3, b35, b9, b27, b30}
  43. ax, bx, cx, px := pf.CombinePolynomials(w, alphas, betas, gammas)
  44. fmt.Println(ax)
  45. fmt.Println(bx)
  46. fmt.Println(cx)
  47. fmt.Println(px)
  48. hx := pf.DivisorPolinomial(px, zx)
  49. fmt.Println(hx)
  50. ```