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.

112 lines
2.0 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "github.com/urfave/cli"
  6. "github.com/arnaucube/go-snark/proof"
  7. )
  8. const (
  9. compiledFileName = "compiled.json"
  10. setupFileName = "setup.json"
  11. privateFileName = "private.json"
  12. publicFileName = "public.json"
  13. proofFileName = "proof.json"
  14. )
  15. const (
  16. proofSystemPinocchio = iota
  17. proofSystemGroth16
  18. )
  19. var proofSystem int
  20. var commands = []cli.Command{
  21. {
  22. Name: "compile",
  23. Aliases: []string{},
  24. Usage: "compile a circuit",
  25. Action: compile,
  26. },
  27. {
  28. Name: "test",
  29. Aliases: []string{},
  30. Usage: "test a circuit",
  31. Action: test,
  32. },
  33. {
  34. Name: "setup",
  35. Aliases: []string{},
  36. Usage: "generate trusted setup for a circuit",
  37. Action: setup,
  38. },
  39. {
  40. Name: "generate",
  41. Aliases: []string{},
  42. Usage: "generate the snark proofs",
  43. Action: generate,
  44. },
  45. {
  46. Name: "verify",
  47. Aliases: []string{},
  48. Usage: "verify the snark proofs",
  49. Action: verify,
  50. },
  51. }
  52. func initProofSystem() error {
  53. switch p := os.Getenv("PROOF_SYSTEM"); p {
  54. case "", "PINOCCHIO":
  55. proofSystem = proofSystemPinocchio
  56. case "GROTH16":
  57. proofSystem = proofSystemGroth16
  58. default:
  59. return fmt.Errorf("proof system not supported: %v", p)
  60. }
  61. return nil
  62. }
  63. func newSetup() (proof.Setup, error) {
  64. var s proof.Setup
  65. switch proofSystem {
  66. case proofSystemPinocchio:
  67. s = &proof.PinocchioSetup{}
  68. case proofSystemGroth16:
  69. s = &proof.Groth16Setup{}
  70. default:
  71. return nil, fmt.Errorf("proof system not supported: %v", proofSystem)
  72. }
  73. return s, nil
  74. }
  75. func newProof() (proof.Proof, error) {
  76. var p proof.Proof
  77. switch proofSystem {
  78. case proofSystemPinocchio:
  79. p = &proof.PinocchioProof{}
  80. case proofSystemGroth16:
  81. p = &proof.Groth16Proof{}
  82. default:
  83. return nil, fmt.Errorf("proof system not supported: %v", proofSystem)
  84. }
  85. return p, nil
  86. }
  87. func main() {
  88. if err := initProofSystem(); err != nil {
  89. panic(err)
  90. }
  91. app := cli.NewApp()
  92. app.Name = "go-snark"
  93. app.Version = "0.0.3-alpha"
  94. app.Flags = []cli.Flag{
  95. cli.StringFlag{Name: "config"},
  96. }
  97. app.Commands = commands
  98. if err := app.Run(os.Args); err != nil {
  99. panic(err)
  100. }
  101. }