gnark
gnark copied to clipboard
fix: IsZero bug will make Cmp panic
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) }
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 can you merge in another temporary branch and add your edit to close this issue?
@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.