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
887 B

  1. package gocircomprover
  2. import (
  3. "fmt"
  4. "math/big"
  5. "github.com/ethereum/go-ethereum/crypto/bn256"
  6. )
  7. // Vk is the Verification Key data structure
  8. type Vk struct {
  9. Alpha *bn256.G1
  10. Beta *bn256.G2
  11. Gamma *bn256.G2
  12. Delta *bn256.G2
  13. IC []*bn256.G1
  14. }
  15. func Verify(vk *Vk, proof *Proof, inputs []*big.Int) bool {
  16. if len(inputs)+1 != len(vk.IC) {
  17. fmt.Println("len(inputs)+1 != len(vk.IC)")
  18. return false
  19. }
  20. vkX := new(bn256.G1).ScalarBaseMult(big.NewInt(0))
  21. for i := 0; i < len(inputs); i++ {
  22. // check input inside field
  23. if inputs[0].Cmp(R) != -1 {
  24. return false
  25. }
  26. vkX = new(bn256.G1).Add(vkX, new(bn256.G1).ScalarMult(vk.IC[i+1], inputs[i]))
  27. }
  28. vkX = new(bn256.G1).Add(vkX, vk.IC[0])
  29. g1 := []*bn256.G1{proof.A, vk.Alpha.Neg(vk.Alpha), vkX.Neg(vkX), proof.C.Neg(proof.C)}
  30. g2 := []*bn256.G2{proof.B, vk.Beta, vk.Gamma, vk.Delta}
  31. return bn256.PairingCheck(g1, g2)
  32. }