generator

package
v0.20.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2026 License: Apache-2.0 Imports: 2 Imported by: 5

Documentation

Overview

Package generator provides a wrapper around the internal field generator.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate added in v0.20.0

func Generate(packageName, elementName, modulus string, outputDir string, opts ...Option) error

Generate generates arithmetic operations for a given modulus.

Example
package main

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

	"github.com/consensys/gnark-crypto/field/generator"
)

func main() {
	// Define the field parameters
	packageName := "goldilocks"
	elementName := "Element"
	modulus := "0xffffffff00000001"
	outputDir := filepath.Join(os.TempDir(), "gnark-crypto-field-gen")

	// Ensure output directory exists
	_ = os.MkdirAll(outputDir, 0755)
	defer os.RemoveAll(outputDir)

	// Generate the field arithmetic code
	err := generator.Generate(packageName, elementName, modulus, outputDir,
		generator.WithASM(filepath.Join(outputDir, "asm"), "asm"),
	)
	if err != nil {
		fmt.Printf("failed to generate field: %v\n", err)
		return
	}

	fmt.Println("successfully generated field arithmetic code")
}

Types

type Option added in v0.15.0

type Option func(*options)

Option is a functional option for the generator.

func WithASM added in v0.15.0

func WithASM(buildDir, includeDir string) Option

WithASM enables assembly code generation. buildDir is the destination path to create output files. includeDir is the directory name to include in the generated files.

func WithAddChain added in v0.20.0

func WithAddChain() Option

WithAddChain enables the use of addition chains for inversion.

func WithExtensions added in v0.17.0

func WithExtensions() Option

WithExtensions enables field extensions code generation.

func WithFFT added in v0.15.0

func WithFFT(generatorFullMultiplicativeGroup uint64, generatorMaxTwoAdicSubgroup string, logTwoOrderMaxTwoAdicSubgroup string) Option

WithFFT enables FFT code generation.

func WithIOP added in v0.19.0

func WithIOP() Option

WithIOP enables IOP code generation.

func WithPoseidon2 added in v0.17.0

func WithPoseidon2() Option

WithPoseidon2 enables Poseidon2 code generation.

func WithSIS added in v0.15.0

func WithSIS() Option

WithSIS enables SIS code generation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL