ZoKrates currently exposes three types:
This is the most basic type in ZoKrates, and it represents a positive integer in
[0, p - 1] where
p is a (large) prime number.
p is set to
21888242871839275222246405745257275088548364400416034343698204186575808495617 as imposed by the pairing curve supported by Ethereum.
field values mostly behave like unsigned integers, one should keep in mind that they overflow at
p and not some power of 2, so that we have:
def main() -> (field): field pMinusOne = 21888242871839275222246405745257275088548364400416034343698204186575808495616 0 - 1 == pMinusOne return 1
ZoKrates has limited support for booleans, to the extent that they can only be used as the condition in
if ... else ... endif expressions.
You can use them for equality checks, inequality checks and inequality checks between
Note that while equality checks are cheap, inequality checks should be use wisely as they are orders of magnitude more expensive.
Static arrays of
field can be instantiated with a constant size, and their elements can be accessed and updated:
def main() -> (field): field a = [1, 2, 3] // initialize an array with values a = 4 // set a member to a value field b = [42; 4] // initialize an array of 4 values all equal to 42 field c = [...a, 4] // initialize an array copying values from `a`, followed by 4 field d = a[1..3] // initialize an array copying a slice from `a` return a + b + c