From 5ae05dd70b41082d1495e52b4453b99535deb970 Mon Sep 17 00:00:00 2001 From: mattstam Date: Wed, 14 Feb 2024 17:32:07 -0800 Subject: [PATCH] no range check flag --- plonky2x/verifier/cli.go | 5 +- plonky2x/verifier/system/groth16_test.go | 72 ++++++++++++------------ 2 files changed, 38 insertions(+), 39 deletions(-) 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..0ddafb1f 100644 --- a/plonky2x/verifier/system/groth16_test.go +++ b/plonky2x/verifier/system/groth16_test.go @@ -1,9 +1,10 @@ // Useful reference files in gnark: // https://github.com/Consensys/gnark-solidity-checker/blob/main/cmd/templates.go // https://github.com/Consensys/gnark/blob/cfe83dbce12428ad0b095bcc33de55c6a9121949/test/assert_solidity.go#L60-L77 -package system +package main import ( + "bufio" "bytes" "encoding/hex" "encoding/json" @@ -15,10 +16,8 @@ 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" ) type MyCircuit struct { @@ -43,33 +42,36 @@ 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") - - 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: false} + + r1cs, err := frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &circuit) + if err != nil { + panic(err) + } + pk, vk, err := groth16.Setup(r1cs) + if err != nil { + panic(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() assignment := MyCircuit{ X: 1, @@ -77,13 +79,11 @@ func TestGroth16(t *testing.T) { Z: 3, } - witness, err := frontend.NewWitness(&assignment, ecc.BN254.ScalarField()) - assert.Nil(t, err) - proof, err := groth16.Prove(r1cs, pk, witness) - assert.Nil(t, err) + witness, _ := frontend.NewWitness(&assignment, ecc.BN254.ScalarField()) + proof, _ := groth16.Prove(r1cs, pk, witness) const fpSize = 4 * 8 - buf := new(bytes.Buffer) + buf = new(bytes.Buffer) proof.WriteRawTo(buf) proofBytes := buf.Bytes()