Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cs: (experimental) add support for IF and FOR #14

Closed
gbotrel opened this issue Mar 6, 2020 · 1 comment
Closed

cs: (experimental) add support for IF and FOR #14

gbotrel opened this issue Mar 6, 2020 · 1 comment
Assignees

Comments

@gbotrel
Copy link
Collaborator

gbotrel commented Mar 6, 2020

Idea:

// signature
func (cs *CS) IF(condition *Constraint, ifBlock func(), elseBlock ...func())
	// example: 
	circuit.IF(condition, func() {
		circuit.IF(circuit.NOT(condition2), func() {
			// if block
			circuit.MUL(...)
		}, func() {
			// optional else block
			circuit.DIV(...)
		})		
	})
        const maxLoops = 100
	for i := 0; i < maxLoops; i++ {
		circuit.IF(circuit.IS_SMALLER(myContraint, i), func() {
		})
                myConstraint = circuit.ADD(myConstraint, 1)
	}

Work in progress. Likely needs better syntax, may need new type of constraints / "boolean predicates".

@ThomasPiellard
Copy link
Collaborator

In the example that you gave: the IS_SMALLER(..) that would return a bool is actually difficult to write as a r1c (I didn't find how to do it at the time I was writing the cs.go file).

I suggest to keep things simple at first step and write an
IF(c, func(..) []*constraints, func(..) []constraints) []*constraints
where c is a variable that has been boolean constrained. Writing the IF like this would be syntaxic sugar to avoid writing by hand the two paths and then the SELECT at the end.

@gbotrel gbotrel closed this as completed Sep 22, 2020
ruslangm pushed a commit to ruslangm/gnark that referenced this issue Feb 6, 2023
ThomasPiellard added a commit to ThomasPiellard/gnark that referenced this issue Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants