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.

80 lines
2.3 KiB

  1. package gocircomprover
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "io/ioutil"
  6. "math/big"
  7. "testing"
  8. "github.com/stretchr/testify/assert"
  9. "github.com/stretchr/testify/require"
  10. )
  11. func TestSmallCircuitGenerateProf(t *testing.T) {
  12. provingKeyJson, err := ioutil.ReadFile("testdata/small/proving_key.json")
  13. require.Nil(t, err)
  14. pk, err := ParseProvingKey(provingKeyJson)
  15. require.Nil(t, err)
  16. fmt.Println("polsA", pk.PolsA)
  17. fmt.Println("polsB", pk.PolsB)
  18. fmt.Println("polsC", pk.PolsC)
  19. witnessJson, err := ioutil.ReadFile("testdata/small/witness.json")
  20. require.Nil(t, err)
  21. w, err := ParseWitness(witnessJson)
  22. require.Nil(t, err)
  23. assert.Equal(t, Witness{big.NewInt(1), big.NewInt(33), big.NewInt(3), big.NewInt(11)}, w)
  24. proof, pubSignals, err := GenerateProof(pk, w)
  25. assert.Nil(t, err)
  26. fmt.Println("proof", proof)
  27. fmt.Println("pubSignals", pubSignals)
  28. proofStr, err := ProofToJson(proof)
  29. assert.Nil(t, err)
  30. fmt.Println("prover\n", string(proofStr))
  31. err = ioutil.WriteFile("testdata/small/proof.json", proofStr, 0644)
  32. assert.Nil(t, err)
  33. publicStr, err := json.Marshal(ArrayBigIntToString(pubSignals))
  34. assert.Nil(t, err)
  35. err = ioutil.WriteFile("testdata/small/public.json", publicStr, 0644)
  36. assert.Nil(t, err)
  37. // to verify the proof:
  38. // snarkjs verify --vk testdata/small/verification_key.json -p testdata/small/proof.json --pub testdata/small/public.json
  39. }
  40. func TestBigCircuitGenerateProf(t *testing.T) {
  41. provingKeyJson, err := ioutil.ReadFile("testdata/big/proving_key.json")
  42. require.Nil(t, err)
  43. pk, err := ParseProvingKey(provingKeyJson)
  44. require.Nil(t, err)
  45. witnessJson, err := ioutil.ReadFile("testdata/big/witness.json")
  46. require.Nil(t, err)
  47. w, err := ParseWitness(witnessJson)
  48. require.Nil(t, err)
  49. proof, pubSignals, err := GenerateProof(pk, w)
  50. assert.Nil(t, err)
  51. fmt.Println("proof", proof)
  52. fmt.Println("pubSignals", pubSignals)
  53. proofStr, err := ProofToJson(proof)
  54. assert.Nil(t, err)
  55. fmt.Println("prover\n", string(proofStr))
  56. err = ioutil.WriteFile("testdata/big/proof.json", proofStr, 0644)
  57. assert.Nil(t, err)
  58. publicStr, err := json.Marshal(ArrayBigIntToString(pubSignals))
  59. assert.Nil(t, err)
  60. err = ioutil.WriteFile("testdata/big/public.json", publicStr, 0644)
  61. assert.Nil(t, err)
  62. // to verify the proof:
  63. // snarkjs verify --vk testdata/big/verification_key.json -p testdata/big/proof.json --pub testdata/big/public.json
  64. }