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

AssertIsBoolean doesn't work with frontend.Variables that were declared using cs.Constant #136

Closed
OlivierBBB opened this issue Sep 7, 2021 · 0 comments

Comments

@OlivierBBB
Copy link

The first two test circuits below don't work: visibility of zero and sum is 0.

package circuits

import (
	"testing"

	"github.com/consensys/gnark-crypto/ecc"
	"github.com/consensys/gnark/backend"
	"github.com/consensys/gnark/frontend"
	"github.com/stretchr/testify/assert"
)

// empty circuits
type IsBool1 struct{}
type IsBool2 struct{}
type IsBool3 struct{}

func TestIsBool1(t *testing.T) {

	var circuit IsBool1

	_, err := frontend.Compile(ecc.BN254, backend.GROTH16, &circuit)
	assert.Nil(t, err, "Circuit compilation failed")
}

func TestIsBool2(t *testing.T) {

	var circuit IsBool2

	_, err := frontend.Compile(ecc.BN254, backend.GROTH16, &circuit)
	assert.Nil(t, err, "Circuit compilation failed")
}

func TestIsBool3(t *testing.T) {

	var circuit IsBool3

	_, err := frontend.Compile(ecc.BN254, backend.GROTH16, &circuit)
	assert.Nil(t, err, "Circuit compilation failed")
}

func (c *IsBool1) Define(curve ecc.ID, cs *frontend.ConstraintSystem) error {

	zero := cs.Constant(0)
	one := cs.Constant(1)
	cs.AssertIsBoolean(zero)
	cs.AssertIsBoolean(one)
	return nil
}

func (c *IsBool2) Define(curve ecc.ID, cs *frontend.ConstraintSystem) error {

	zero := cs.Constant(0)
	one := cs.Constant(1)
	sum := cs.Add(zero, one)
	cs.AssertIsBoolean(sum)
	return nil
}

func (c *IsBool3) Define(curve ecc.ID, cs *frontend.ConstraintSystem) error {

	zero := cs.Constant(0)
	one := cs.Constant(1)
	prod := cs.Mul(zero, one)
	cs.AssertIsBoolean(prod)

	return nil
}
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

No branches or pull requests

2 participants