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

Can not passed XOR boolean check, even though I only use Binary Operations. #343

Closed
ZhAnGeek opened this issue Jul 18, 2022 · 2 comments
Closed

Comments

@ZhAnGeek
Copy link

ZhAnGeek commented Jul 18, 2022

I have tried a lot of ways to do the xor process, however it wont work. Here's my code.

the first part is about change the variables to binary, for this function we use the api XOR/OR/AND function as an parameter f

func UInt64BitOperation(api *frontend.API, a, b frontend.Variable, f func(a, b frontend.Variable) frontend.Variable) frontend.Variable {
	cs := *api
	aBits := cs.ToBinary(a, 64)
	bBits := cs.ToBinary(b, 64)
	var resBits []frontend.Variable = make([]frontend.Variable, 64)

And this below which is straight thinking but won't work

	for i := 0; i < 64; i++ {
		resBits[i] = f(aBits[i], bBits[i])
	}

And I have tried another way.

	for i := 0; i < 64; i++ {
		aC := (*api).Select(aBits[i], One, Zero)
		bC := (*api).Select(bBits[i], One, Zero)
		resBits[i] = f(aC, bC)
	}

I just check the value in hint function, so weird that aC, bC is all 1, but the XOR result returns a overflow number. And the error keep telling constraint #13307 is not satisfied: [assertIsBoolean] -1 == (0|1)

I have seen there's saying boolean operations results will always be boolean, but it seems like not the situation. How should I do?thanks.

@ZhAnGeek
Copy link
Author

ZhAnGeek commented Jul 19, 2022

func UInt64BitOperation(api frontend.API, a, b frontend.Variable, f func(a, b frontend.Variable) frontend.Variable) frontend.Variable {
	aBits := api.ToBinary(a, 64)
	bBits := api.ToBinary(b, 64)
	var resBits []frontend.Variable = make([]frontend.Variable, 64)
	for i := 0; i < 64; i++ {
		resBits[i] = f(aBits[i], bBits[i])
		api.AssertIsBoolean(aBits[i])
		api.AssertIsBoolean(bBits[i])
		api.AssertIsBoolean(f(aBits[i], bBits[i])) // _<------------ it only stucks here_
	}
	return api.FromBinary(resBits...)
}

@ivokub
Copy link
Collaborator

ivokub commented Jul 19, 2022

Hi @ZhAnGeek - can you give a full compilable circuit which causes the error? Particularly, what is the implementation of the function f you are using?

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