Skip to content

Commit

Permalink
no range check flag
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstam committed Feb 15, 2024
1 parent 884ec51 commit 5ae05dd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 39 deletions.
5 changes: 2 additions & 3 deletions plonky2x/verifier/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down
72 changes: 36 additions & 36 deletions plonky2x/verifier/system/groth16_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 {
Expand All @@ -43,47 +42,48 @@ 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,
Y: 2,
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()

Expand Down

0 comments on commit 5ae05dd

Please sign in to comment.