gnark
gnark copied to clipboard
Conditionals statements in circuit definition
In an imperative programming language, that would be a if
/ else
.
However, it doesn't translate well in a declarative API to define the circuit, as the output of the frontend.Compile
method is an arithmetic representation that must encode the various branches.
gnark
offers cs.Select(...)
API, which is similar to Prolog-like languages.
// Select if b is true, yields i1 else yields i2
func (cs *ConstraintSystem) Select(b Variable, i1, i2 interface{}) Variable {
At a minimum, gnark
should provide some syntactic sugar to wrap several instructions, maybe in a lambda, into a a if
-like statement.
Recently wants to use it, could you give some ideas about how to add if
in circuit?
hi @SherLzp --> there is a branch, a bit outdated to explore some ideas: https://github.com/ConsenSys/gnark/tree/feat/conditional
this is going to get some attention quite soon, but first we have some PlonK efficiency work on the plate.
in particular: https://github.com/ConsenSys/gnark/blob/feat/conditional/internal/backend/circuits/conditional.go
Noted. Thanks
When will this issue be implemented? @gbotrel