Updated on January 4, 2022
As described in Circuit structure,
func Define(api frontend.API) error
apiis the root object to manipulate when defining constraints.
x² := api.Mul(x, x) to write x \times x. For example, to prove that we know the solution to
the cubic equation x^3 + x + 5 = y, write:
x3 := api.Mul(circuit.X, circuit.X, circuit.X) api.AssertIsEqual(circuit.Y, api.Add(x3, circuit.X, 5))
APIs, when possible, take a variadic list of
This allows flexibility on the circuit definition side when coding, for example:
api.Mul(X, 2, api.Add(Y, Z, 42))
Constants bigger than base field modulus will be reduced \mod n.
Reusing circuit components
Other zk-SNARK libraries introduced the term gadget to describe circuit composition.
gnark has no need for gadgets, because you can use functions that can live, be
versioned, and tested in a Go package like any other piece of code.
gnark provides a standard library with common functions like hashes or
Refer to the Go package documentation for a complete list of the API with examples.
Refer to the EdDSA tutorial for an example.