Skip to content

Commit

Permalink
feat: switch wrapper circuit from PlonK to Groth16
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstam committed Feb 5, 2024
1 parent 2047119 commit f677ee8
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions plonky2x/verifier/circuit.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import (
"time"

"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark/backend/plonk"
"github.com/consensys/gnark/backend/groth16"
"github.com/consensys/gnark/constraint"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/frontend/cs/scs"
"github.com/consensys/gnark/frontend/cs/r1cs"
"github.com/consensys/gnark/logger"
"github.com/consensys/gnark/test"
"github.com/succinctlabs/gnark-plonky2-verifier/types"
"github.com/succinctlabs/gnark-plonky2-verifier/variables"
"github.com/succinctlabs/gnark-plonky2-verifier/verifier"
Expand Down Expand Up @@ -75,7 +74,7 @@ func (c *Plonky2xVerifierCircuit) Define(api frontend.API) error {
return nil
}

func CompileVerifierCircuit(dummyCircuitPath string) (constraint.ConstraintSystem, plonk.ProvingKey, plonk.VerifyingKey, error) {
func CompileVerifierCircuit(dummyCircuitPath string) (constraint.ConstraintSystem, groth16.ProvingKey, groth16.VerifyingKey, error) {
log := logger.Logger()
verifierOnlyCircuitData := variables.DeserializeVerifierOnlyCircuitData(
types.ReadVerifierOnlyCircuitData(dummyCircuitPath + "/verifier_only_circuit_data.json"),
Expand All @@ -93,18 +92,14 @@ func CompileVerifierCircuit(dummyCircuitPath string) (constraint.ConstraintSyste
OutputHash: new(frontend.Variable),
CommonCircuitData: commonCircuitData,
}
r1cs, err := frontend.Compile(ecc.BN254.ScalarField(), scs.NewBuilder, &circuit)
r1cs, err := frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &circuit)
if err != nil {
return nil, nil, nil, fmt.Errorf("failed to compile circuit: %w", err)
}

log.Info().Msg("Running circuit setup")
start := time.Now()
srs, err := test.NewKZGSRS(r1cs)
if err != nil {
panic(err)
}
pk, vk, err := plonk.Setup(r1cs, srs)
pk, vk, err := groth16.Setup(r1cs)
if err != nil {
return nil, nil, nil, err
}
Expand All @@ -114,7 +109,7 @@ func CompileVerifierCircuit(dummyCircuitPath string) (constraint.ConstraintSyste
return r1cs, pk, vk, nil
}

func SaveVerifierCircuit(path string, r1cs constraint.ConstraintSystem, pk plonk.ProvingKey, vk plonk.VerifyingKey) error {
func SaveVerifierCircuit(path string, r1cs constraint.ConstraintSystem, pk groth16.ProvingKey, vk groth16.VerifyingKey) error {
log := logger.Logger()
os.MkdirAll(path, 0755)
log.Info().Msg("Saving circuit constraints to " + path + "/r1cs.bin")
Expand Down

0 comments on commit f677ee8

Please sign in to comment.