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.

53 lines
1.1 KiB

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