About using gnark to write circuit output signals #1513
-
When using gnark to write a circuit, I don't want to use assert-related interfaces in the circuit, but I hope that the final results of all verifications can be output as a public signal through an output signal. When verifying the proof, this output signal must be 1 to verify the proof. The purpose is to generate a proof for wrong data, but the proof fails. Can gnark achieve this effect? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 13 replies
-
Hi @yinzhenzhen. I'm not fully understanding the question - so lets say you write a very basic circuit: type Circuit struct {
P, Q frontend.Variable `gnark:",secret"`
N frontend.Variable `gnark:",public"`
}
func (c *Circuit) Define(api frontend.API) error {
res := api.Mul(c.P, c.Q)
api.AssertIsEqual(res, c.N)
return nil
} and now you would like to create a proof for some invalid inputs e.g. Another approach (but maybe this is what you meant initially) is to perform instead of final assertion some other check. A la type Circuit struct {
P, Q frontend.Variable `gnark:",secret"`
N frontend.Variable `gnark:",public"`
IsInvalid frontend.Variable `gnark:",public"`
}
func (c *Circuit) Define(api frontend.API) error {
res := api.Mul(c.P, c.Q)
expectedResult := api.Select(c.IsInvalid, res, c.N)
api.AssertIsEqual(expectedResult, c.N)
return nil
} Now, you should be able to compute the proof for For some of the primitives (for example for recursive proof verification if you are checking SNARK proof inside a circuit) we don't have a direct way to verify invalid proofs however, but we're planning to add the primitives (see #1454 for example) |
Beta Was this translation helpful? Give feedback.
Yes, for now it is not possible. I don't think we would implement even a way to solve the circuit for invalid assignment, as in large and complex circuits it may cause unexpected side-effects.
Yes - in BLS12-377 and BW6-761 combination it should be a lot faster. These curves are compatible with each other so that there is no field arithmetic emulation overhead. See https://github.com/Consensys/gnark/blob/master/std/recursion/groth16/native_doc_test.go for an example.