mirror of
https://github.com/luxfi/cli.git
synced 2026-10-30 17:01:20 +00:00
The node moved every chain route from /v1/bc/<alias> to /v1/chain/<alias> and deleted the old prefix, so every chain call answered 404. The address was spelled out at 112 sites across 34 files and constants.ChainAliasPrefix was used at none of them, which is why nothing failed to compile when the segment moved. route.Chain(uri, alias) composes it now, and route.Alias reads one back, replacing three hand-rolled parsers — one of which took the alias by position in the split path and only worked because the new segment happens to leave the component count unchanged. TestChainAddressBuiltOnlyHere walks every .go file in the module and fails on a chain address in a string literal, so the segment cannot drift back; prose is free to name a route. TestGuardCatchesEachShape plants each forbidden shape and requires the guard to find it. The endpoint box and the eleven-chain table were the same list written twice; there is one list, rendered once, measured rather than hand-padded. The generated CLI reference and the faucet manifest compose through the same function. Co-authored-by: Hanzo Dev <[email protected]>
99 lines
3.3 KiB
Go
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/luxfi/cli/pkg/route"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func newVerifyCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "verify",
|
|
Short: "Verify a ZK proof (groth16 or plonk)",
|
|
Long: `Verify zero-knowledge proofs by calling Z-Chain precompiled contracts.
|
|
|
|
The Z-Chain provides on-chain verification for Groth16 and PLONK proofs via
|
|
precompiled contracts at fixed addresses. This command submits the proof and
|
|
public inputs to the verifier precompile and returns the result.`,
|
|
}
|
|
|
|
cmd.AddCommand(newVerifyGroth16Cmd())
|
|
cmd.AddCommand(newVerifyPlonkCmd())
|
|
|
|
return cmd
|
|
}
|
|
|
|
func newVerifyGroth16Cmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "groth16",
|
|
Short: "Verify a Groth16 proof",
|
|
Long: `Verify a Groth16 proof against the Z-Chain Groth16 verifier precompile.
|
|
|
|
Requires the proof file, verification key, and public inputs.
|
|
Connects to the Z-Chain RPC endpoint to call the verifier contract.`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
rpc, _ := cmd.Flags().GetString("rpc")
|
|
proof, _ := cmd.Flags().GetString("proof")
|
|
vk, _ := cmd.Flags().GetString("vk")
|
|
inputs, _ := cmd.Flags().GetString("inputs")
|
|
return verifyProof("groth16", rpc, proof, vk, inputs)
|
|
},
|
|
}
|
|
|
|
cmd.Flags().String("rpc", route.Chain("http://localhost:9630", "Z")+"/rpc", "Z-Chain RPC endpoint")
|
|
cmd.Flags().String("proof", "", "Proof file path (required)")
|
|
cmd.Flags().String("vk", "", "Verification key file path (required)")
|
|
cmd.Flags().String("inputs", "", "Public inputs file path (required)")
|
|
cmd.MarkFlagRequired("proof")
|
|
cmd.MarkFlagRequired("vk")
|
|
cmd.MarkFlagRequired("inputs")
|
|
|
|
return cmd
|
|
}
|
|
|
|
func newVerifyPlonkCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "plonk",
|
|
Short: "Verify a PLONK proof",
|
|
Long: `Verify a PLONK proof against the Z-Chain PLONK verifier precompile.
|
|
|
|
Requires the proof file, verification key, and public inputs.
|
|
Connects to the Z-Chain RPC endpoint to call the verifier contract.`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
rpc, _ := cmd.Flags().GetString("rpc")
|
|
proof, _ := cmd.Flags().GetString("proof")
|
|
vk, _ := cmd.Flags().GetString("vk")
|
|
inputs, _ := cmd.Flags().GetString("inputs")
|
|
return verifyProof("plonk", rpc, proof, vk, inputs)
|
|
},
|
|
}
|
|
|
|
cmd.Flags().String("rpc", route.Chain("http://localhost:9630", "Z")+"/rpc", "Z-Chain RPC endpoint")
|
|
cmd.Flags().String("proof", "", "Proof file path (required)")
|
|
cmd.Flags().String("vk", "", "Verification key file path (required)")
|
|
cmd.Flags().String("inputs", "", "Public inputs file path (required)")
|
|
cmd.MarkFlagRequired("proof")
|
|
cmd.MarkFlagRequired("vk")
|
|
cmd.MarkFlagRequired("inputs")
|
|
|
|
return cmd
|
|
}
|
|
|
|
func verifyProof(scheme, rpc, proofPath, vkPath, inputsPath string) error {
|
|
fmt.Printf("Verifying %s proof via Z-Chain at %s\n", scheme, rpc)
|
|
fmt.Printf(" Proof: %s\n", proofPath)
|
|
fmt.Printf(" VK: %s\n", vkPath)
|
|
fmt.Printf(" Inputs: %s\n", inputsPath)
|
|
fmt.Println()
|
|
return fmt.Errorf(
|
|
"Z-Chain %s verifier precompile call not yet implemented (rpc: %s)\n\n"+
|
|
"The Z-Chain exposes verifier precompiles for on-chain proof verification.\n"+
|
|
"Track progress: https://github.com/luxfi/node/issues?q=zkvm+verifier",
|
|
scheme, rpc,
|
|
)
|
|
}
|