gnark icon indicating copy to clipboard operation
gnark copied to clipboard

fix: IsZero bug will make Cmp panic

Open niconiconi opened this issue 3 years ago • 1 comments

A code will trigger the bug:

func isNegative(api frontend.API, x frontend.Variable) frontend.Variable { c := frontend.Variable("10944121435919637611123202872628637544274182200208017171849102093287904247808") return api.Cmp(x, c) }

niconiconi avatar Jun 25 '22 04:06 niconiconi

Suggested edit:

diff --git a/internal/backend/circuits/iszero.go b/internal/backend/circuits/iszero.go
index 91f0d4fc..d38d157b 100644
--- a/internal/backend/circuits/iszero.go
+++ b/internal/backend/circuits/iszero.go
@@ -13,8 +13,12 @@ func (circuit *isZero) Define(api frontend.API) error {
 
 	a := api.IsZero(circuit.X)
 	b := api.IsZero(circuit.Y)
+	c := api.IsZero(1)
+	d := api.IsZero(0)
 	api.AssertIsEqual(a, 1)
 	api.AssertIsEqual(b, 0)
+	api.AssertIsEqual(c, 0)
+	api.AssertIsEqual(d, 1)
 
 	return nil
 }

ivokub avatar Jul 04 '22 09:07 ivokub

@ivokub can you merge in another temporary branch and add your edit to close this issue?

gbotrel avatar Sep 13 '22 18:09 gbotrel

@ivokub can you merge in another temporary branch and add your edit to close this issue?

The incoming branch is external and couldn't add commits. Created new PR #367. This one can be closed.

ivokub avatar Sep 13 '22 21:09 ivokub