Skip to content
You are reading gnark development version documentation and some displayed features may not be available in the stable release. You can switch to stable version using the version box at screen bottom.

Updated on April 29, 2021

Debug and test circuits

Common errors

The most common error you may get while trying to create a proof is:

constraint is not satisfied: [(.. * ..) != (.. * ..) + (.. * ..) + (.. * ..)]

The error means the solver couldn’t satisfy at least one of the constraints with the provided witness.


In some cases, you may encounter a couldn't solve computational constraint error, which means the solver couldn’t perform an operation needed to verify a constraint. For example, a division by 0.

The easiest way to debug a circuit is to use cs.Println(), which behaves like fmt.Println, except it outputs the values when they are solved. For example:

cs.Println("A.X", pubKey.A.X)


With solving errors and cs.Println, gnark outputs a stack trace which contain the exact line number to refer to in the circuit definition.


You can implement tests as Go unit tests, in a _test.go file. For example:

// assert object wrapping testing.T
assert := groth16.NewAssert(t)

// declare the circuit
var mimcCircuit Circuit

// compile the circuit into a R1CS
r1cs, err := frontend.Compile(ecc.BN254, backend.GROTH16, &mimcCircuit)

    // assign invalid values to a witness, ensure the proof fails
    var witness Circuit
    assert.ProverFailed(r1cs, &witness)

    // assign valid values to a witness, ensure the proof is valid
    var witness Circuit
    assert.ProverSucceeded(r1cs, &witness)
Questions or feedback? You can discuss issues and obtain free support on gnark discussions channel.
For paid professional support by Consensys, contact us at [email protected]