-
Notifications
You must be signed in to change notification settings - Fork 3
dynamic prove/verify #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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
|
||
|
|
||
| // 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 { | ||
|
|
||
|
|
@@ -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 | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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 betweenProvingMethodGroth16AuthV2andProvingMethodGroth16AuthV3. Consider extracting this logic into a shared helper function or embedding a common type to reduce code duplication and improve maintainability.