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

Addition of Or,And constraint, plus a specific constraint checking if a value is zero #48

Merged
merged 5 commits into from Jan 13, 2021

Conversation

ThomasPiellard
Copy link
Collaborator

@ThomasPiellard ThomasPiellard commented Jan 8, 2021

Fixes #45

Addition of Or, And, IsZero constraints.

Example:

Referring to the use in #45 here is an example:

` type ExampleCircuit struct {
X frontend.Variable
}

func (circuit *ExampleCircuit) Define(curveID gurvy.ID, cs *frontend.ConstraintSystem) error {

	XminusThree := cs.Sub(circuit.X, 3)
	XminusFour := cs.Sub(circuit.X, 4)

	isXEqualToThree := cs.IsZero(XminusThree, curveID)
	isXEqualToFour := cs.IsZero(XminusFour, curveID)

	xEqualThreeOrFour := cs.Or(isXEqualToThree, isXEqualToFour)

	cs.Println("x==3?: ", isXEqualToThree)
	cs.Println("x==4?: ", isXEqualToFour)
	cs.Println("x==3 or x==4?: ", xEqualThreeOrFour)

	cs.AssertIsEqual(xEqualThreeOrFour, 1)

	return nil
}

func main() {

	var circuit ExampleCircuit
	r1cs, _ := frontend.Compile(gurvy.BN256, &circuit)

	var solution ExampleCircuit
	solution.X.Assign(3)
	parsedSolution, _ := frontend.ParseWitness(&solution)

	r1cs.IsSolved(parsedSolution)

}

`

Output:
main.go:26 x==3?: 1
main.go:27 x==4?: 0
main.go:28 x==3 or x==4?: 1

Status: tests pass.

…g testing accross curves for curved-typed circuits
@ThomasPiellard ThomasPiellard changed the title Issue 45 Addition of Or,And constraint, plus a specific constraint checking if a value is zero Jan 13, 2021
… zero, 0 otherwise, it was reversed previously)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants