arnaucube / go-snark-study

zkSNARK library implementation in Go from scratch (compiler, setup, prover, verifier)
GNU General Public License v3.0
255 stars 57 forks source link

go build error #16

Open triplewz opened 4 years ago

triplewz commented 4 years ago

Hello, when i tried to build main.go, it showed that

# github.com/arnaucube/go-snark/cli
./main.go:57:3: cannot use []cli.Command literal (type []cli.Command) as type []*cli.Command in field value
./main.go:85:17: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in array or slice literal:
    cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
./main.go:87:15: cannot use commands (type []cli.Command) as type []*cli.Command in assignment

What's the reason?

triplewz commented 4 years ago

I use the following code, and it works fine.

var commands = []*cli.Command{         // pointer
    {
        Name:    "compile",
        Aliases: []string{},
        Usage:   "compile a circuit",
        Action:  CompileCircuit,
    },
    {
        Name:    "trustedsetup",
        Aliases: []string{},
        Usage:   "generate trusted setup for a circuit",
        Action:  TrustedSetup,
    },
    {
        Name:    "genproofs",
        Aliases: []string{},
        Usage:   "generate the snark proofs",
        Action:  GenerateProofs,
    },
    {
        Name:    "verify",
        Aliases: []string{},
        Usage:   "verify the snark proofs",
        Action:  VerifyProofs,
    },
    {
        Name:    "groth16",
        Aliases: []string{},
        Usage:   "use groth16 protocol",
        Subcommands: []*cli.Command{                        //pointer
            {
                Name:    "trustedsetup",
                Aliases: []string{},
                Usage:   "generate trusted setup for a circuit",
                Action:  Groth16TrustedSetup,
            },
            {
                Name:    "genproofs",
                Aliases: []string{},
                Usage:   "generate the snark proofs",
                Action:  Groth16GenerateProofs,
            },
            {
                Name:    "verify",
                Aliases: []string{},
                Usage:   "verify the snark proofs",
                Action:  Groth16VerifyProofs,
            },
        },
    },
}

func main() {
    app := cli.NewApp()
    app.Name = "go-snarks-cli"
    app.Version = "0.0.3-alpha"
    app.Flags = []cli.Flag{
        &cli.StringFlag{Name: "config"},     //
    }
    app.Commands = commands

    err := app.Run(os.Args)
    if err != nil {
        log.Fatal(err)
    }
}
arnaucube commented 4 years ago

Which version are you using? I've tried just now with the current master version of this repo, and worked fine Which version of the urfave/cli are you using ( https://github.com/arnaucube/go-snark/blob/master/go.mod#L7 )?

triplewz commented 4 years ago

Ok, I used version 2 of the urfave/cli, maybe this is the reason.