Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 0 additions & 93 deletions authGroth16.go

This file was deleted.

30 changes: 26 additions & 4 deletions authV2Groth16.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ var AuthV2Groth16Alg = ProvingMethodAlg{Groth16, string(circuits.AuthV2CircuitID
// ProvingMethodGroth16AuthV2 instance for Groth16 proving method with an authV2 circuit
type ProvingMethodGroth16AuthV2 struct {
ProvingMethodAlg
cacheMutex sync.RWMutex
cache map[[sha256.Size]byte]witness.Calculator
circuitSubVersions []string
cacheMutex sync.RWMutex
cache map[[sha256.Size]byte]witness.Calculator
}

// ProvingMethodGroth16AuthInstance instance for Groth16 proving method with an authV2 circuit
Expand All @@ -34,8 +35,9 @@ var (
// nolint : used for init proving method instance
func init() {
ProvingMethodGroth16AuthV2Instance = &ProvingMethodGroth16AuthV2{
ProvingMethodAlg: AuthV2Groth16Alg,
cache: make(map[[sha256.Size]byte]witness.Calculator),
ProvingMethodAlg: AuthV2Groth16Alg,
circuitSubVersions: []string{},
cache: make(map[[sha256.Size]byte]witness.Calculator),
}
RegisterProvingMethod(ProvingMethodGroth16AuthV2Instance.ProvingMethodAlg,
func() ProvingMethod { return ProvingMethodGroth16AuthV2Instance })
Expand All @@ -51,6 +53,26 @@ func (m *ProvingMethodGroth16AuthV2) CircuitID() string {
return m.ProvingMethodAlg.CircuitID
}

// SupportedCircuits returns list of supported circuit IDs
func (m *ProvingMethodGroth16AuthV2) SupportedCircuits() []string {
seen := make(map[string]struct{}, 1+len(m.circuitSubVersions))
out := make([]string, 0, 1+len(m.circuitSubVersions))

add := func(s string) {
if _, ok := seen[s]; ok {
return
}
seen[s] = struct{}{}
out = append(out, s)
}

add(m.ProvingMethodAlg.CircuitID)
for _, s := range m.circuitSubVersions {
add(s)
}
return out
}
Comment on lines +57 to +74
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SupportedCircuits() method is duplicated identically between ProvingMethodGroth16AuthV2 and ProvingMethodGroth16AuthV3. Consider extracting this logic into a shared helper function or embedding a common type to reduce code duplication and improve maintainability.

Copilot uses AI. Check for mistakes.

// Verify performs Groth16 proof verification and checks equality of message hash and proven challenge public signals
func (m *ProvingMethodGroth16AuthV2) Verify(messageHash []byte, proof *types.ZKProof, verificationKey []byte) error {

Expand Down
55 changes: 35 additions & 20 deletions authV3Groth16.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,41 @@ import (
"github.com/iden3/go-rapidsnark/witness/wazero"
)

const (
// Groth16 alg
Groth16 string = "groth16"
)

// AuthV3Groth16Alg its auth v3 alg (groth16 vs auth v3 circuit)
var AuthV3Groth16Alg = ProvingMethodAlg{Groth16, string(circuits.AuthV3CircuitID)}

// AuthV3_8_32Groth16Alg its auth v3 alg (groth16 vs auth v3-8-32 circuit)
var AuthV3_8_32Groth16Alg = ProvingMethodAlg{Groth16, string(circuits.AuthV3_8_32CircuitID)}

// ProvingMethodGroth16AuthV3 instance for Groth16 proving method with an authV3 circuit
type ProvingMethodGroth16AuthV3 struct {
ProvingMethodAlg
cacheMutex sync.RWMutex
cache map[[sha256.Size]byte]witness.Calculator
circuitSubVersions []string
cacheMutex sync.RWMutex
cache map[[sha256.Size]byte]witness.Calculator
}

var (
// ProvingMethodGroth16AuthV3Instance instance for Groth16 proving method with an authV3 circuit
ProvingMethodGroth16AuthV3Instance *ProvingMethodGroth16AuthV3
// ProvingMethodGroth16AuthV3_8_32_Instance instance for Groth16 proving method with an authV3 circuit
ProvingMethodGroth16AuthV3_8_32Instance *ProvingMethodGroth16AuthV3
)

// nolint : used for init proving method instance
func init() {
authV3_8_32 := "authV3-8-32"
ProvingMethodGroth16AuthV3Instance = &ProvingMethodGroth16AuthV3{
ProvingMethodAlg: AuthV3Groth16Alg,
cache: make(map[[sha256.Size]byte]witness.Calculator),
}

ProvingMethodGroth16AuthV3_8_32Instance = &ProvingMethodGroth16AuthV3{
ProvingMethodAlg: AuthV3_8_32Groth16Alg,
cache: make(map[[sha256.Size]byte]witness.Calculator),
ProvingMethodAlg: AuthV3Groth16Alg,
circuitSubVersions: []string{authV3_8_32},
cache: make(map[[sha256.Size]byte]witness.Calculator),
}

RegisterProvingMethod(ProvingMethodGroth16AuthV3Instance.ProvingMethodAlg,
func() ProvingMethod { return ProvingMethodGroth16AuthV3Instance })

RegisterProvingMethod(ProvingMethodGroth16AuthV3_8_32Instance.ProvingMethodAlg,
func() ProvingMethod { return ProvingMethodGroth16AuthV3_8_32Instance })
RegisterProvingMethod(ProvingMethodAlg{Groth16, authV3_8_32},
func() ProvingMethod { return ProvingMethodGroth16AuthV3Instance })
}

// Alg returns current zk alg
Expand All @@ -65,6 +63,26 @@ func (m *ProvingMethodGroth16AuthV3) CircuitID() string {
return m.ProvingMethodAlg.CircuitID
}

// SupportedCircuits returns list of supported circuit IDs
func (m *ProvingMethodGroth16AuthV3) SupportedCircuits() []string {
seen := make(map[string]struct{}, 1+len(m.circuitSubVersions))
out := make([]string, 0, 1+len(m.circuitSubVersions))

add := func(s string) {
if _, ok := seen[s]; ok {
return
}
seen[s] = struct{}{}
out = append(out, s)
}

add(m.ProvingMethodAlg.CircuitID)
for _, s := range m.circuitSubVersions {
add(s)
}
return out
}
Comment on lines +67 to +84
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SupportedCircuits() method is duplicated identically between ProvingMethodGroth16AuthV3 and ProvingMethodGroth16AuthV2. Consider extracting this logic into a shared helper function or embedding a common type to reduce code duplication and improve maintainability.

Copilot uses AI. Check for mistakes.

// Verify performs Groth16 proof verification and checks equality of message hash and proven challenge public signals
func (m *ProvingMethodGroth16AuthV3) Verify(messageHash []byte, proof *types.ZKProof, verificationKey []byte) error {

Expand All @@ -90,10 +108,7 @@ func (m *ProvingMethodGroth16AuthV3) Verify(messageHash []byte, proof *types.ZKP
// checks that proven message hash is set as a part of circuit specific inputs
func (m *ProvingMethodGroth16AuthV3) Prove(inputs, provingKey, wasm []byte) (*types.ZKProof, error) {

var calc witness.Calculator
var err error

calc, err = m.newWitCalc(wasm)
calc, err := m.newWitCalc(wasm)
if err != nil {
return nil, err
}
Expand Down
Loading