diff --git a/plonky2x/verifier/cli.go b/plonky2x/verifier/cli.go index 6c85a144..f2a0a422 100644 --- a/plonky2x/verifier/cli.go +++ b/plonky2x/verifier/cli.go @@ -10,9 +10,6 @@ import ( ) func main() { - // https://github.com/succinctlabs/gnark-plonky2-verifier/blob/c01f530fe1d0107cc20da226cfec541ece9fb882/goldilocks/base.go#L131 - os.Setenv("USE_BIT_DECOMPOSITION_RANGE_CHECK", "true") - circuitPath := flag.String("circuit", "", "circuit data directory") dataPath := flag.String("data", "", "data directory") proofFlag := flag.Bool("prove", false, "create a proof") @@ -37,6 +34,8 @@ func main() { var s system.ProvingSystem if *systemFlag == "groth16" { + // https://github.com/succinctlabs/gnark-plonky2-verifier/blob/c01f530fe1d0107cc20da226cfec541ece9fb882/goldilocks/base.go#L131 + os.Setenv("USE_BIT_DECOMPOSITION_RANGE_CHECK", "true") s = system.NewGroth16System(logger, *circuitPath, *dataPath) } else if *systemFlag == "plonk" { s = system.NewPlonkSystem(logger, *circuitPath, *dataPath) diff --git a/plonky2x/verifier/system/groth16_test.go b/plonky2x/verifier/system/groth16_test.go index e0838be2..1f01d2ac 100644 --- a/plonky2x/verifier/system/groth16_test.go +++ b/plonky2x/verifier/system/groth16_test.go @@ -4,6 +4,7 @@ package system import ( + "bufio" "bytes" "encoding/hex" "encoding/json" @@ -15,7 +16,7 @@ import ( "github.com/consensys/gnark-crypto/ecc" "github.com/consensys/gnark/backend/groth16" "github.com/consensys/gnark/frontend" - "github.com/consensys/gnark/logger" + "github.com/consensys/gnark/frontend/cs/r1cs" "github.com/consensys/gnark/std/rangecheck" "github.com/stretchr/testify/assert" @@ -43,33 +44,34 @@ type Groth16ProofData struct { } func TestGroth16(t *testing.T) { - os.Setenv("USE_BIT_DECOMPOSITION_RANGE_CHECK", "true") - logger := logger.Logger() - s := NewGroth16System(logger, "../data/dummy", "../verifier-build") + range_check := true - r1cs, err := s.LoadCircuit() - assert.Nil(t, err) - pk, err := s.LoadProvingKey() - assert.Nil(t, err) - // buf := new(bytes.Buffer) - // err = vk.ExportSolidity(buf) - // if err != nil { - // panic(err) - // } - // content := buf.String() - - // contractFile, err := os.Create("VerifierGroth16.sol") - // if err != nil { - // panic(err) - // } - // w := bufio.NewWriter(contractFile) - // // write the new content to the writer - // _, err = w.Write([]byte(content)) - // if err != nil { - // panic(err) - // } - // contractFile.Close() + circuit := MyCircuit{DoRangeCheck: range_check} + + r1cs, err := frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &circuit) + if err != nil { + panic(err) + } + pk, vk, err := groth16.Setup(r1cs) + buf := new(bytes.Buffer) + err = vk.ExportSolidity(buf) + if err != nil { + panic(err) + } + content := buf.String() + filename := "VerifierGroth16.sol" + contractFile, err := os.Create(filename) + if err != nil { + panic(err) + } + w := bufio.NewWriter(contractFile) + // write the new content to the writer + _, err = w.Write([]byte(content)) + if err != nil { + panic(err) + } + contractFile.Close() assignment := MyCircuit{ X: 1,