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.

56 lines
1.1 KiB

  1. package main
  2. import (
  3. "github.com/arnaucube/go-snark/circuit"
  4. "github.com/arnaucube/go-snark/proof"
  5. "github.com/urfave/cli"
  6. )
  7. func generate(context *cli.Context) error {
  8. // load circuit
  9. cir := &circuit.Circuit{}
  10. if err := loadFromFile(compiledFileName, cir); err != nil {
  11. return err
  12. }
  13. // load inputs
  14. var inputs circuit.Inputs
  15. if err := loadFromFile(privateFileName, &inputs.Private); err != nil {
  16. return err
  17. }
  18. if err := loadFromFile(publicFileName, &inputs.Public); err != nil {
  19. return err
  20. }
  21. // calculate witness
  22. w, err := cir.CalculateWitness(inputs.Private, inputs.Public)
  23. if err != nil {
  24. return err
  25. }
  26. // load setup
  27. setup, err := newSetup()
  28. if err != nil {
  29. return err
  30. }
  31. if err := loadFromFile(setupFileName, setup); err != nil {
  32. return err
  33. }
  34. // R1CS to QAP
  35. alphas, betas, gammas, _ := proof.R1CSToQAP(
  36. cir.R1CS.A,
  37. cir.R1CS.B,
  38. cir.R1CS.C)
  39. _, _, _, px := proof.Utils.PF.CombinePolynomials(w, alphas, betas, gammas)
  40. // generate proof
  41. proof, err := setup.Generate(cir, w, px)
  42. if err != nil {
  43. return err
  44. }
  45. // save proof
  46. return saveToFile(proofFileName, proof)
  47. }