Documentation ¶
Overview ¶
Package test provides components or functions to help test and fuzz gnark circuits.
Index ¶
- Variables
- func IsSolved(circuit, witness frontend.Circuit, curveID ecc.ID, b backend.ID, ...) (err error)
- func NewKZGSRS(ccs frontend.CompiledConstraintSystem) (kzg.SRS, error)
- func NoSerialization() func(opt *TestingOption) error
- func WithBackends(b backend.ID, backends ...backend.ID) func(opt *TestingOption) error
- func WithCompileOpts(compileOpts ...func(opt *frontend.CompileOption) error) func(opt *TestingOption) error
- func WithCurves(c ecc.ID, curves ...ecc.ID) func(opt *TestingOption) error
- func WithProverOpts(proverOpts ...func(opt *backend.ProverOption) error) func(opt *TestingOption) error
- type Assert
- func (assert *Assert) Fuzz(circuit frontend.Circuit, fuzzCount int, ...)
- func (assert *Assert) GetCounters(circuit frontend.Circuit, opts ...func(opt *TestingOption) error) []compiled.Counter
- func (assert *Assert) Log(v ...interface{})
- func (assert *Assert) ProverFailed(circuit frontend.Circuit, invalidWitness frontend.Circuit, ...)
- func (assert *Assert) ProverSucceeded(circuit frontend.Circuit, validWitness frontend.Circuit, ...)
- func (assert *Assert) Run(fn func(assert *Assert), descs ...string)
- func (assert *Assert) SolvingFailed(circuit frontend.Circuit, invalidWitness frontend.Circuit, ...)
- func (assert *Assert) SolvingSucceeded(circuit frontend.Circuit, validWitness frontend.Circuit, ...)
- type TestingOption
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func IsSolved ¶
func IsSolved(circuit, witness frontend.Circuit, curveID ecc.ID, b backend.ID, opts ...func(opt *backend.ProverOption) error) (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 frontend.CompiledConstraintSystem) (kzg.SRS, error)
NewKZGSRS uses ccs nb variables and nb constraints to initialize a kzg srs for sizes < 2^15, returns a pre-computed cached SRS
/!\ warning /!\: this method is here for convenience only: in production, a SRS generated through MPC should be used.
func NoSerialization ¶
func NoSerialization() func(opt *TestingOption) error
NoSerialization enables calls to assert.ProverSucceeded and assert.ProverFailed to skip witness serialization tests
func WithBackends ¶
WithBackends enables calls to assert.ProverSucceeded and assert.ProverFailed to run on specific backends only
(defaults to all gnark supported backends)
func WithCompileOpts ¶
func WithCompileOpts(compileOpts ...func(opt *frontend.CompileOption) error) func(opt *TestingOption) error
WithCompileOpts enables calls to assert.ProverSucceeded and assert.ProverFailed to forward compiler.Compile option to compiler.Compile calls
func WithCurves ¶
WithCurves enables calls to assert.ProverSucceeded and assert.ProverFailed to run on specific curves only
(defaults to all gnark supported curves)
func WithProverOpts ¶
func WithProverOpts(proverOpts ...func(opt *backend.ProverOption) error) func(opt *TestingOption) error
WithProverOpts enables calls to assert.ProverSucceeded and assert.ProverFailed to forward backend.Prover option to backend.Prove and backend.ReadAndProve calls
Types ¶
type Assert ¶
type Assert struct { *require.Assertions // contains filtered or unexported fields }
Assert is a helper to test circuits
func NewAssert ¶
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 ...func(opt *TestingOption) error)
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) GetCounters ¶ added in v0.6.0
func (assert *Assert) GetCounters(circuit frontend.Circuit, opts ...func(opt *TestingOption) error) []compiled.Counter
GetCounters compiles (or fetch from the compiled circuit cache) the circuit with set backends and curves and returns measured counters
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, invalidWitness frontend.Circuit, opts ...func(opt *TestingOption) error)
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, validWitness frontend.Circuit, opts ...func(opt *TestingOption) error)
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
Run runs the test function fn as a subtest. The subtest is parametrized by the description strings descs.
func (*Assert) SolvingFailed ¶
func (*Assert) SolvingSucceeded ¶
type TestingOption ¶
type TestingOption struct {
// contains filtered or unexported fields
}
TestingOption enables calls to assert.ProverSucceeded and assert.ProverFailed to run with various features
In particular: chose the curve, chose the backend and execute serialization tests on the witness
Default values to all supported curves, backends and execute serialization tests = true