gnark icon indicating copy to clipboard operation
gnark copied to clipboard

Conditionals statements in circuit definition

Open gbotrel opened this issue 3 years ago • 5 comments

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.

gbotrel avatar Apr 09 '21 19:04 gbotrel

Recently wants to use it, could you give some ideas about how to add if in circuit?

SherLzp avatar Jun 28 '21 08:06 SherLzp

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.

gbotrel avatar Jun 29 '21 18:06 gbotrel

in particular: https://github.com/ConsenSys/gnark/blob/feat/conditional/internal/backend/circuits/conditional.go

gbotrel avatar Jun 29 '21 18:06 gbotrel

Noted. Thanks

SherLzp avatar Jun 30 '21 02:06 SherLzp

When will this issue be implemented? @gbotrel

SherLzp avatar May 13 '22 02:05 SherLzp