circomgnark

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

circomgnark package provides utilities to convert between Circom and Gnark proof formats, allowing for verification of zkSNARK proofs created with Circom and SnarkJS to be used within the Gnark framework. It includes functions to convert Circom proofs and verification keys to Gnark over the BN254 curve, and to verify these proofs using Gnark's verification functions. It also provides a way to handle recursive proofs and placeholders for recursive circuits.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertPublicInputs

func ConvertPublicInputs(publicSignals []string) ([]bn254fr.Element, error)

ConvertPublicInputs parses an array of strings representing public inputs into a slice of bn254fr.Element.

func MarshalCircomProofJSON

func MarshalCircomProofJSON(proof *CircomProof) ([]byte, error)

MarshalCircomProofJSON marshals the given CircomProof into pretty‑printed JSON.

func MarshalCircomPublicSignalsJSON

func MarshalCircomPublicSignalsJSON(publicSignals []string) ([]byte, error)

MarshalCircomPublicSignalsJSON marshals the given public signals (slice of strings) into pretty‑printed JSON.

func MarshalCircomVerificationKeyJSON

func MarshalCircomVerificationKeyJSON(vk *CircomVerificationKey) ([]byte, error)

MarshalCircomVerificationKeyJSON marshals the given CircomVerificationKey into pretty‑printed JSON.

func UnmarshalCircomPublicSignalsJSON

func UnmarshalCircomPublicSignalsJSON(data []byte) ([]string, error)

UnmarshalCircomPublicSignalsJSON parses the JSON-encoded public signals data into a slice of strings.

Types

type CircomProof

type CircomProof struct {
	PiA      []string   `json:"pi_a"`
	PiB      [][]string `json:"pi_b"`
	PiC      []string   `json:"pi_c"`
	Protocol string     `json:"protocol"`
}

CircomProof represents the proof structure output by SnarkJS.

func UnmarshalCircom

func UnmarshalCircom(circomProof, pubSignals string) (*CircomProof, []string, error)

UnmarshalCircom function unmarshals a circom proof and public signals from their string representations. It returns the CircomProof and a slice of public signals or an error if the unmarshalling fails.

func UnmarshalCircomProofJSON

func UnmarshalCircomProofJSON(data []byte) (*CircomProof, error)

UnmarshalCircomProofJSON parses the JSON-encoded proof data into a SnarkJSProof struct.

func (*CircomProof) ToGnark

func (circomProof *CircomProof) ToGnark() (*groth16_bn254.Proof, error)

ToGnark converts a CircomProof into a Gnark-compatible Proof structure.

func (*CircomProof) ToGnarkRecursion

func (circomProof *CircomProof) ToGnarkRecursion(circomVk *CircomVerificationKey,
	circomPublicSignals []string, fixedVk bool,
) (*GnarkRecursionProof, error)

ToGnarkRecursion converts a Circom proof, verification key, and public signals to the Gnark recursion proof format. If fixedVk is true, the verification key is fixed and must be defined as 'gnark:"-"' in the Circuit.

type CircomVerificationKey

type CircomVerificationKey struct {
	Protocol      string       `json:"protocol"`
	Curve         string       `json:"curve"`
	NPublic       int          `json:"nPublic"`
	VkAlpha1      []string     `json:"vk_alpha_1"`
	VkBeta2       [][]string   `json:"vk_beta_2"`
	VkGamma2      [][]string   `json:"vk_gamma_2"`
	VkDelta2      [][]string   `json:"vk_delta_2"`
	IC            [][]string   `json:"IC"`
	VkAlphabeta12 [][][]string `json:"vk_alphabeta_12"` // Not used in verification
}

CircomVerificationKey represents the verification key structure output by SnarkJS.

func UnmarshalCircomVerificationKeyJSON

func UnmarshalCircomVerificationKeyJSON(data []byte) (*CircomVerificationKey, error)

UnmarshalCircomVerificationKeyJSON parses the JSON-encoded verification key data into a SnarkJSVerificationKey struct.

func (*CircomVerificationKey) ToGnark

func (circomVerificationKey *CircomVerificationKey) ToGnark() (*groth16_bn254.VerifyingKey, error)

ToGnark converts a CircomVerificationKey into a Gnark-compatible VerifyingKey structure.

type GnarkProof

type GnarkProof struct {
	Proof        *groth16_bn254.Proof
	VerifyingKey *groth16_bn254.VerifyingKey
	PublicInputs []bn254fr.Element
}

GnarkProof is a proof that can be used with non-recursive circuits.

func ConvertCircomToGnark

func ConvertCircomToGnark(circomVk *CircomVerificationKey,
	circomProof *CircomProof, circomPublicSignals []string,
) (*GnarkProof, error)

ConvertCircomToGnark converts a Circom proof, verification key, and public signals to the Gnark proof format. The proof can be verified using the VerifyProof() function.

func (*GnarkProof) Verify

func (proof *GnarkProof) Verify() (bool, error)

Verify verifies the Gnark proof using the provided verification key and public inputs over the BN254 curve.

type GnarkRecursionPlaceholders

GnarkRecursionPlaceholders is a set of placeholders that can be used to define recursive circuits.

func Circom2GnarkPlaceholder

func Circom2GnarkPlaceholder(vkey []byte, nInputs int) (*GnarkRecursionPlaceholders, error)

Circom2GnarkPlaceholder function is a wrapper to convert the circom ballot circuit to a gnark recursion placeholder, it returns the resulting placeholders for the

func PlaceholdersForRecursion

func PlaceholdersForRecursion(circomVk *CircomVerificationKey,
	nPublicInputs int, fixedVk bool,
) (*GnarkRecursionPlaceholders, error)

PlaceholdersForRecursion creates placeholders for the recursion proof and verification key. If fixedVk is true, the verification key is fixed and must be defined as 'gnark:"-"' in the Circuit. It only needs the number of public inputs and the circom verification key.

type GnarkRecursionProof

GnarkRecursionProof is a proof that can be used with recursive circuits.

func Circom2GnarkProofForRecursion

func Circom2GnarkProofForRecursion(vkey []byte, rawCircomProof, rawPubSignals string) (*GnarkRecursionProof, error)

Circom2GnarkProofForRecursion function is a wrapper to convert a circom proof to a gnark proof to be verified inside another gnark circuit. It receives the circom proof, the public signals and the verification key as strings, as snarkjs returns them. Then, it converts the proof, the public signals and the verification key to the gnark format and returns a gnark recursion proof or an error.

func VerifyAndConvertToRecursion

func VerifyAndConvertToRecursion(vkey []byte, proof *CircomProof, pubSignals []string) (
	*GnarkRecursionProof, error,
)

VerifyAndConvertToRecursion function is a wrapper to circom2gnark that converts a circom proof to a gnark proof, verifies it and then converts it to a gnark recursion proof. It returns the resulting proof or an error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL