Files

99 lines
3.3 KiB
Go

// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package zkcmd
import (
"fmt"
"github.com/spf13/cobra"
)
func newProveCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "prove",
Short: "Generate a ZK proof (groth16 or plonk)",
Long: `Generate zero-knowledge proofs using the Lux SRS.
Proof generation runs locally using the SRS from the trusted setup ceremony.
The resulting proof can be verified on-chain via the Z-Chain verifier precompiles
or off-chain using 'lux zk verify'.`,
}
cmd.AddCommand(newProveGroth16Cmd())
cmd.AddCommand(newProvePlonkCmd())
return cmd
}
func newProveGroth16Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "groth16",
Short: "Generate a Groth16 proof",
Long: `Generate a Groth16 proof from a circuit, witness, and SRS.
The proving key is derived from the SRS generated by the ceremony.
The witness contains both public inputs and private values.`,
RunE: func(cmd *cobra.Command, args []string) error {
circuit, _ := cmd.Flags().GetString("circuit")
witness, _ := cmd.Flags().GetString("witness")
srs, _ := cmd.Flags().GetString("srs")
output, _ := cmd.Flags().GetString("output")
return generateProof("groth16", circuit, witness, srs, output)
},
}
cmd.Flags().String("circuit", "", "Compiled circuit file path (required)")
cmd.Flags().String("witness", "", "Witness file path (required)")
cmd.Flags().String("srs", "", "SRS file path (required)")
cmd.Flags().String("output", "", "Output proof file path (required)")
cmd.MarkFlagRequired("circuit")
cmd.MarkFlagRequired("witness")
cmd.MarkFlagRequired("srs")
cmd.MarkFlagRequired("output")
return cmd
}
func newProvePlonkCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "plonk",
Short: "Generate a PLONK proof",
Long: `Generate a PLONK proof from a circuit, witness, and SRS.
PLONK uses a universal SRS that works with any circuit of bounded size,
unlike Groth16 which requires a circuit-specific trusted setup.`,
RunE: func(cmd *cobra.Command, args []string) error {
circuit, _ := cmd.Flags().GetString("circuit")
witness, _ := cmd.Flags().GetString("witness")
srs, _ := cmd.Flags().GetString("srs")
output, _ := cmd.Flags().GetString("output")
return generateProof("plonk", circuit, witness, srs, output)
},
}
cmd.Flags().String("circuit", "", "Compiled circuit file path (required)")
cmd.Flags().String("witness", "", "Witness file path (required)")
cmd.Flags().String("srs", "", "SRS file path (required)")
cmd.Flags().String("output", "", "Output proof file path (required)")
cmd.MarkFlagRequired("circuit")
cmd.MarkFlagRequired("witness")
cmd.MarkFlagRequired("srs")
cmd.MarkFlagRequired("output")
return cmd
}
func generateProof(scheme, circuitPath, witnessPath, srsPath, outputPath string) error {
fmt.Printf("Generating %s proof\n", scheme)
fmt.Printf(" Circuit: %s\n", circuitPath)
fmt.Printf(" Witness: %s\n", witnessPath)
fmt.Printf(" SRS: %s\n", srsPath)
fmt.Printf(" Output: %s\n", outputPath)
fmt.Println()
return fmt.Errorf("%s proof generation not yet implemented\n\n"+
"This will use gnark to generate proofs locally from the ceremony SRS.\n"+
"The resulting proof can be verified on Z-Chain or off-chain.\n\n"+
"Track progress: https://github.com/luxfi/node/issues?q=zkvm+prover", scheme)
}