ZoKrates
ZoKrates copied to clipboard
Add cast from field to boolean
currently we support going from a field element to boolean this way:
field a = 0
bool b = if a == 0 then true else false fi
this is based on the comparison a == 0
, which at least takes 2 constraints.
However, the cast can also easily be done by adding the following single constraint:
a * (a-1) = 0
Isn't it the case that a cast to bool has 3 possible outcomes: true, false, and error? In general I feel like instead of casting field to bool, one should wonder if it's possible to have a boolean in the first place, no?