github.com/consensys/gnark-crypto@v0.14.0/internal/generator/test_vector_utils/generate.go (about)

     1  package test_vector_utils
     2  
     3  import (
     4  	"github.com/consensys/bavard"
     5  	"github.com/consensys/gnark-crypto/internal/generator/config"
     6  	"github.com/consensys/gnark-crypto/internal/generator/gkr"
     7  	"github.com/consensys/gnark-crypto/internal/generator/polynomial"
     8  	"github.com/consensys/gnark-crypto/internal/generator/sumcheck"
     9  	"path/filepath"
    10  )
    11  
    12  type Config struct {
    13  	config.FieldDependency
    14  	RandomizeMissingHashEntries bool
    15  }
    16  
    17  func GenerateRationals(bgen *bavard.BatchGenerator) error {
    18  	gkrConf := gkr.Config{
    19  		FieldDependency: config.FieldDependency{
    20  			FieldPackagePath: "github.com/consensys/gnark-crypto/internal/generator/test_vector_utils/small_rational",
    21  			FieldPackageName: "small_rational",
    22  			ElementType:      "small_rational.SmallRational",
    23  		},
    24  		GenerateTests:           false,
    25  		RetainTestCaseRawInfo:   true,
    26  		TestVectorsRelativePath: "../../../gkr/test_vectors",
    27  	}
    28  
    29  	baseDir := "./test_vector_utils/small_rational/"
    30  	if err := polynomial.Generate(gkrConf.FieldDependency, baseDir+"polynomial", false, bgen); err != nil {
    31  		return err
    32  	}
    33  	if err := sumcheck.Generate(gkrConf.FieldDependency, baseDir+"sumcheck", bgen); err != nil {
    34  		return err
    35  	}
    36  	if err := gkr.Generate(gkrConf, baseDir+"gkr", bgen); err != nil {
    37  		return err
    38  	}
    39  	if err := Generate(Config{gkrConf.FieldDependency, true}, baseDir+"test_vector_utils", bgen); err != nil {
    40  		return err
    41  	}
    42  
    43  	// generate gkr test vector generator for rationals
    44  	gkrConf.OutsideGkrPackage = true
    45  	return bgen.Generate(gkrConf, "main", "./gkr/template", bavard.Entry{
    46  		File: filepath.Join("gkr", "test_vectors", "main.go"), Templates: []string{"gkr.test.vectors.gen.go.tmpl", "gkr.test.vectors.go.tmpl"},
    47  	})
    48  
    49  }
    50  
    51  func Generate(conf Config, baseDir string, bgen *bavard.BatchGenerator) error {
    52  	entry := bavard.Entry{
    53  		File: filepath.Join(baseDir, "test_vector_utils.go"), Templates: []string{"test_vector_utils.go.tmpl"},
    54  	}
    55  
    56  	return bgen.Generate(conf, "test_vector_utils", "./test_vector_utils/template/", entry)
    57  }