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.

62 lines
1.7 KiB

  1. package verifier
  2. import (
  3. "io/ioutil"
  4. "testing"
  5. "github.com/iden3/go-circom-prover-verifier/parsers"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/stretchr/testify/require"
  8. )
  9. func TestVerify(t *testing.T) {
  10. testVerifyCircuit(t, "circuit1k")
  11. testVerifyCircuit(t, "circuit5k")
  12. // testVerifyCircuit(t, "circuit10k")
  13. // testVerifyCircuit(t, "circuit20k")
  14. }
  15. func testVerifyCircuit(t *testing.T, circuit string) {
  16. proofJson, err := ioutil.ReadFile("../testdata/" + circuit + "/proof.json")
  17. require.Nil(t, err)
  18. vkJson, err := ioutil.ReadFile("../testdata/" + circuit + "/verification_key.json")
  19. require.Nil(t, err)
  20. publicJson, err := ioutil.ReadFile("../testdata/" + circuit + "/public.json")
  21. require.Nil(t, err)
  22. public, err := parsers.ParsePublicSignals(publicJson)
  23. require.Nil(t, err)
  24. proof, err := parsers.ParseProof(proofJson)
  25. require.Nil(t, err)
  26. vk, err := parsers.ParseVk(vkJson)
  27. require.Nil(t, err)
  28. v := Verify(vk, proof, public)
  29. assert.True(t, v)
  30. // Verify again to check that `Verify` hasn't mutated the inputs
  31. v = Verify(vk, proof, public)
  32. assert.True(t, v)
  33. }
  34. func BenchmarkVerify(b *testing.B) {
  35. // benchmark with circuit2 (10000 constraints)
  36. proofJson, err := ioutil.ReadFile("../testdata/circuit2/proof.json")
  37. require.Nil(b, err)
  38. vkJson, err := ioutil.ReadFile("../testdata/circuit2/verification_key.json")
  39. require.Nil(b, err)
  40. publicJson, err := ioutil.ReadFile("../testdata/circuit2/public.json")
  41. require.Nil(b, err)
  42. public, err := parsers.ParsePublicSignals(publicJson)
  43. require.Nil(b, err)
  44. proof, err := parsers.ParseProof(proofJson)
  45. require.Nil(b, err)
  46. vk, err := parsers.ParseVk(vkJson)
  47. require.Nil(b, err)
  48. for i := 0; i < b.N; i++ {
  49. Verify(vk, proof, public)
  50. }
  51. }