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.

42 lines
843 B

  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 setup(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. // R1CS to QAP
  22. alphas, betas, gammas, _ := proof.R1CSToQAP(
  23. cir.R1CS.A,
  24. cir.R1CS.B,
  25. cir.R1CS.C)
  26. // calculate trusted setup
  27. setup, err := newSetup()
  28. if err != nil {
  29. return err
  30. }
  31. if err := setup.Init(cir, alphas, betas, gammas); err != nil {
  32. return err
  33. }
  34. // save setup
  35. return saveToFile(setupFileName, setup)
  36. }