1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00
ZoKrates/zokrates_cli/examples/book/assembly/field_to_bool.zok
2022-11-22 20:32:49 +01:00

12 lines
No EOL
358 B
Text

from "EMBED" import field_to_bool_unsafe;
def main(field x) -> bool {
// we constrain `x` to be 0 or 1
asm {
x * (x - 1) === 0;
}
// we can treat `x` as `bool` afterwards, as we constrained it properly
// `field_to_bool_unsafe` call does not produce any extra constraints
bool out = field_to_bool_unsafe(x);
return out;
}