Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 5 additions & 83 deletions internal/gkr/test_vectors/generate.go
Original file line number Diff line number Diff line change
@@ -1,105 +1,27 @@
package main

import (
"fmt"
"os"
"path/filepath"
"sync"

"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/frontend/cs/scs"
gkr "github.com/consensys/gnark/internal/gkr/small_rational"
_ "github.com/consensys/gnark/std/hash/mimc" // register MIMC hash
gkr_poseidon2 "github.com/consensys/gnark/std/hash/poseidon2/gkr-poseidon2"
)

func main() {
tasks := []func() error{
gkr.GenerateSumcheckVectors,
gkr.GenerateVectors,
generateGkrSolveTestdata,
}

var wg sync.WaitGroup
wg.Add(len(tasks))
for _, f := range tasks {
go func() {
assertNoError(f())
go func(f func() error) {
if err := f(); err != nil {
panic(err)
}
wg.Done()
}()
}(f)
}
wg.Wait()
}

func assertNoError(err error) {
if err != nil {
panic(err)
}
}

// gkrPoseidon2Circuit computes H(X,Y) using gkr-poseidon2.
type gkrPoseidon2Circuit struct {
X, Y frontend.Variable
}

func (c *gkrPoseidon2Circuit) Define(api frontend.API) error {
h, err := gkr_poseidon2.New(api)
if err != nil {
return err
}
h.Write(c.X, c.Y)
api.AssertIsDifferent(h.Sum(), 0)
return nil
}

// generateGkrSolveTestdata compiles a small GKR-Poseidon2 validator circuit for
// BLS12-377 and writes its constraint system and a matching witness to the
// integration_test/ directory. The test there reads them back in a process that
// does not import gkrapi and calls Solve, exercising the full CBOR round-trip
// of the GKR proving schedule end-to-end.
func generateGkrSolveTestdata() error {
fmt.Println("generating GKR-Poseidon2 integration testdata")

assignment := gkrPoseidon2Circuit{1, 2}
var circuit gkrPoseidon2Circuit

ccs, err := frontend.Compile(ecc.BLS12_377.ScalarField(), scs.NewBuilder, &circuit)
if err != nil {
return fmt.Errorf("failed to compile circuit: %w", err)
}

w, err := frontend.NewWitness(&assignment, ecc.BLS12_377.ScalarField())
if err != nil {
return fmt.Errorf("failed to build witness: %w", err)
}

const testDataDir = "integration_test"
if err = os.MkdirAll(testDataDir, 0755); err != nil {
return fmt.Errorf("failed to create testdata directory: %w", err)
}

scsPath := filepath.Join(testDataDir, "gkr_poseidon2.scs")
scsFile, err := os.Create(scsPath)
if err != nil {
return fmt.Errorf("failed to create scs file: %w", err)
}
defer scsFile.Close()
if _, err = ccs.WriteTo(scsFile); err != nil {
return fmt.Errorf("failed to write constraint system: %w", err)
}
fmt.Printf("\twrote %s\n", scsPath)

wtnsPath := filepath.Join(testDataDir, "gkr_poseidon2.wtns")
wtnsFile, err := os.Create(wtnsPath)
if err != nil {
return fmt.Errorf("failed to create witness file: %w", err)
}
defer wtnsFile.Close()
if _, err = w.WriteTo(wtnsFile); err != nil {
return fmt.Errorf("failed to write witness: %w", err)
}
fmt.Printf("\twrote %s\n", wtnsPath)

return nil
}
Binary file not shown.
Binary file not shown.
32 changes: 0 additions & 32 deletions internal/gkr/test_vectors/integration_test/integration_test.go

This file was deleted.

18 changes: 0 additions & 18 deletions std/multicommit/nativecommit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,6 @@ func TestMultipleCommitments(t *testing.T) {
assert.ProverSucceeded(&circuit, &assignment, test.WithCurves(ecc.BN254))
}

type noCommitVariable struct {
X frontend.Variable
}

func (c *noCommitVariable) Define(api frontend.API) error {
WithCommitment(api, func(api frontend.API, commitment frontend.Variable) error { return nil })
return nil
}

// TestNoCommitVariable checks that a circuit that doesn't use the commitment variable
// compiles and prover succeeds. This is due to the randomization of the commitment.
func TestNoCommitVariable(t *testing.T) {
circuit := noCommitVariable{}
assignment := noCommitVariable{X: 10}
assert := test.NewAssert(t)
assert.ProverSucceeded(&circuit, &assignment, test.WithCurves(ecc.BN254))
}

type wideCommitment struct {
X frontend.Variable
withCommitment bool
Expand Down