test

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 License: Apache-2.0 Imports: 41 Imported by: 12

Documentation

Overview

Package test provides components or functions to help test and fuzz gnark circuits.

Index

Constants

View Source
const SolcCheck = false

Variables

View Source
var (
	ErrCompilationNotDeterministic = errors.New("compilation is not deterministic")
	ErrInvalidWitnessSolvedCS      = errors.New("invalid witness solved the constraint system")
	ErrInvalidWitnessVerified      = errors.New("invalid witness resulted in a valid proof")
)

Functions

func IsSolved

func IsSolved(circuit, witness frontend.Circuit, field *big.Int, opts ...TestEngineOption) (err error)

IsSolved returns an error if the test execution engine failed to execute the given circuit with provided witness as input.

The test execution engine implements frontend.API using big.Int operations.

This is an experimental feature.

Types

type Assert

type Assert struct {
	*require.Assertions
	// contains filtered or unexported fields
}

Assert is a helper to test circuits

func NewAssert

func NewAssert(t *testing.T) *Assert

NewAssert returns an Assert helper embedding a testify/require object for convenience

The Assert object caches the compiled circuit:

the first call to assert.ProverSucceeded/Failed will compile the circuit for n curves, m backends and subsequent calls will re-use the result of the compilation, if available.

func (*Assert) CheckCircuit added in v0.9.0

func (assert *Assert) CheckCircuit(circuit frontend.Circuit, opts ...TestingOption)

CheckCircuit performs a series of check on the provided circuit.

go test -short                  --> testEngineChecks
go test                         --> testEngineChecks  + constraintSolverChecks
go test -tags=prover_checks     --> ... + proverChecks
go test -tags=release_checks    --> ... + releaseChecks (solidity, serialization, ...)

Depending on the above flags, the following checks are performed:

  • the circuit compiles
  • the circuit can be solved with the test engine
  • the circuit can be solved with the constraint system solver
  • the circuit can be solved with the prover
  • the circuit can be verified with the verifier
  • the circuit can be verified with gnark-solidity-checker
  • the circuit, witness, proving and verifying keys can be serialized and deserialized

func (*Assert) Fuzz

func (assert *Assert) Fuzz(circuit frontend.Circuit, fuzzCount int, opts ...TestingOption)

Fuzz fuzzes the given circuit by instantiating "randomized" witnesses and cross checking execution result between constraint system solver and big.Int test execution engine

note: this is experimental and will be more tightly integrated with go1.18 built-in fuzzing

func (*Assert) Log added in v0.6.0

func (assert *Assert) Log(v ...interface{})

Log logs using the test instance logger.

func (*Assert) ProverFailed

func (assert *Assert) ProverFailed(circuit frontend.Circuit, invalidAssignment frontend.Circuit, opts ...TestingOption)

ProverSucceeded is deprecated use Assert.CheckCircuit instead

func (*Assert) ProverSucceeded

func (assert *Assert) ProverSucceeded(circuit frontend.Circuit, validAssignment frontend.Circuit, opts ...TestingOption)

ProverSucceeded is deprecated: use Assert.CheckCircuit instead

func (*Assert) Run added in v0.6.0

func (a *Assert) Run(fn func(assert *Assert), descs ...string)

Run runs the test function fn as a subtest. The subtest is parametrized by the description strings descs.

func (*Assert) SolvingFailed

func (assert *Assert) SolvingFailed(circuit frontend.Circuit, invalidWitness frontend.Circuit, opts ...TestingOption)

SolvingFailed is deprecated: use CheckCircuit instead

func (*Assert) SolvingSucceeded

func (assert *Assert) SolvingSucceeded(circuit frontend.Circuit, validWitness frontend.Circuit, opts ...TestingOption)

SolvingSucceeded is deprecated: use Assert.CheckCircuit instead

type TestEngineOption added in v0.8.0

type TestEngineOption func(e *engine) error

TestEngineOption defines an option for the test engine.

func SetAllVariablesAsConstants added in v0.8.0

func SetAllVariablesAsConstants() TestEngineOption

SetAllVariablesAsConstants is a test engine option which makes the calls to IsConstant() and ConstantValue() always return true. If this test engine option is not set, then all variables are considered as non-constant, regardless if it is constructed by a call to ConstantValue().

func WithBackendProverOptions added in v0.8.0

func WithBackendProverOptions(opts ...backend.ProverOption) TestEngineOption

WithBackendProverOptions is a test engine option which allows to define prover options. If not set, then default prover configuration is used.

type TestingOption

type TestingOption func(*testingConfig) error

TestingOption defines option for altering the behavior of Assert methods. See the descriptions of functions returning instances of this type for particular options.

func NoFuzzing added in v0.8.0

func NoFuzzing() TestingOption

NoFuzzing is a testing option which disables fuzzing tests, even when the build tag "release_checks" is set.

func NoProverChecks added in v0.9.0

func NoProverChecks() TestingOption

NoProverChecks is a testing option which disables prover checks, even when the build tag "prover_checks" or "release_checks" are set.

func NoSerializationChecks added in v0.9.0

func NoSerializationChecks() TestingOption

NoSerializationChecks is a testing option which disables serialization checks, even when the build tag "release_checks" is set.

func NoSolidityChecks added in v0.9.0

func NoSolidityChecks() TestingOption

NoSolidityChecks is a testing option which disables solidity checks, even when the build tags "solccheck" and "release_checks" are set.

When the tags are set; this requires gnark-solidity-checker to be installed, which in turns requires solc and abigen to be reachable in the PATH.

See https://github.com/ConsenSys/gnark-solidity-checker for more details.

func NoTestEngine added in v0.9.0

func NoTestEngine() TestingOption

NoTestEngine is a testing option which disables test engine checks

func WithBackends

func WithBackends(b backend.ID, backends ...backend.ID) TestingOption

WithBackends is testing option which restricts the backends the assertions are run. When not given, runs on all implemented backends.

func WithCompileOpts

func WithCompileOpts(compileOpts ...frontend.CompileOption) TestingOption

WithCompileOpts is a testing option which uses the given compileOpts when calling frontend.Compile in assertions.

func WithCurves

func WithCurves(c ecc.ID, curves ...ecc.ID) TestingOption

WithCurves is a testing option which restricts the curves the assertions are run. When not given, runs on all implemented curves.

func WithInvalidAssignment added in v0.9.0

func WithInvalidAssignment(invalidAssignment frontend.Circuit) TestingOption

WithInvalidAssignment is a testing option which adds an invalid assignment

func WithProverOpts

func WithProverOpts(proverOpts ...backend.ProverOption) TestingOption

WithProverOpts is a testing option which uses the given proverOpts when calling backend.Prover, backend.ReadAndProve and backend.IsSolved methods in assertions.

func WithSolidityExportOptions added in v0.11.0

func WithSolidityExportOptions(solidityOpts ...solidity.ExportOption) TestingOption

WithSolidityExportOptions is a testing option which uses the given solidityOpts when calling ExportSolidity method on the verification key.

func WithSolverOpts added in v0.9.0

func WithSolverOpts(solverOpts ...solver.Option) TestingOption

WithSolverOpts is a testing option which uses the given solverOpts when calling constraint system solver.

func WithValidAssignment added in v0.9.0

func WithValidAssignment(validAssignment frontend.Circuit) TestingOption

WithValidAssignment is a testing option which adds a valid assignment

func WithVerifierOpts added in v0.10.0

func WithVerifierOpts(verifierOpts ...backend.VerifierOption) TestingOption

WithVerifierOpts is a testing option which uses the given verifierOpts when calling backend.Verify method.

Directories

Path Synopsis
Package unsafekzg is a convenience package (to be use for test purposes only) to generate and cache SRS for the kzg scheme (and indirectly for PlonK setup).
Package unsafekzg is a convenience package (to be use for test purposes only) to generate and cache SRS for the kzg scheme (and indirectly for PlonK setup).

Jump to

Keyboard shortcuts

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