test

package
v0.9.0-alpha Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: Apache-2.0 Imports: 51 Imported by: 12

Documentation

Overview

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

Index

Constants

View Source
const SerializationThreshold = 1000

SerializationThreshold is the number of constraints above which we don't do a systematic round-trip serialization check for the proving and verifying keys.

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.

func NewKZGSRS

func NewKZGSRS(ccs constraint.ConstraintSystem) (kzg.SRS, error)

NewKZGSRS uses ccs nb variables and nb constraints to initialize a kzg srs for sizes < 2¹⁵, returns a pre-computed cached SRS

/!\ warning /!\: this method is here for convenience only: in production, a SRS generated through MPC should be used.

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) 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 fails the test if any of the following step errored:

1. compiles the circuit (or fetch it from the cache) 2. using the test execution engine, executes the circuit with provided witness (must fail) 3. run Setup / Prove / Verify with the backend (must fail)

By default, this tests on all curves and proving schemes supported by gnark. See available TestingOption.

func (*Assert) ProverSucceeded

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

ProverSucceeded fails the test if any of the following step errored:

1. compiles the circuit (or fetch it from the cache) 2. using the test execution engine, executes the circuit with provided witness 3. run Setup / Prove / Verify with the backend 4. if set, (de)serializes the witness and call ReadAndProve and ReadAndVerify on the backend

By default, this tests on all curves and proving schemes supported by gnark. See available TestingOption.

func (*Assert) Run added in v0.6.0

func (assert *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)

func (*Assert) SolvingSucceeded

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

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 in assertions.

func NoSerialization

func NoSerialization() TestingOption

NoSerialization is a testing option which disables witness serialization tests in assertions.

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 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 WithSolidity

func WithSolidity() TestingOption

WithSolidity is a testing option which enables solidity tests in assertions. If the build tag "solccheck" is not set, this option is ignored. When the tag is 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 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.

Jump to

Keyboard shortcuts

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