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.

37 lines
919 B

  1. package proof
  2. import (
  3. "math/big"
  4. "github.com/arnaucube/go-snark/fields"
  5. )
  6. // R1CSToQAP converts the R1CS values to the QAP values
  7. func R1CSToQAP(a, b, c [][]*big.Int) ([][]*big.Int, [][]*big.Int, [][]*big.Int, []*big.Int) {
  8. aT := fields.Transpose(a)
  9. bT := fields.Transpose(b)
  10. cT := fields.Transpose(c)
  11. var alphas [][]*big.Int
  12. for i := 0; i < len(aT); i++ {
  13. alphas = append(alphas, Utils.PF.LagrangeInterpolation(aT[i]))
  14. }
  15. var betas [][]*big.Int
  16. for i := 0; i < len(bT); i++ {
  17. betas = append(betas, Utils.PF.LagrangeInterpolation(bT[i]))
  18. }
  19. var gammas [][]*big.Int
  20. for i := 0; i < len(cT); i++ {
  21. gammas = append(gammas, Utils.PF.LagrangeInterpolation(cT[i]))
  22. }
  23. z := []*big.Int{big.NewInt(int64(1))}
  24. for i := 1; i < len(alphas)-1; i++ {
  25. z = Utils.PF.Mul(
  26. z,
  27. []*big.Int{
  28. Utils.PF.F.Neg(
  29. big.NewInt(int64(i))),
  30. big.NewInt(int64(1)),
  31. })
  32. }
  33. return alphas, betas, gammas, z
  34. }