Field
Field elements are the basic unit of data in zero knowledge proof programming. An element of a Field is like an integer, except that all operations are performed modulo a prime. Each field element can store a number up to almost 256 bits in size. All other data types that can be used in provable code can be represented as Fields.
For the cryptography inclined, the exact max value that a field can store is: 28,948,022,309,329,048,855,892,746,252,171,976,963,363,056,481,941,560,715,954,676,764,349,967,630,337.
For example, in typical programming, you might use:
const sum = 1 + 3;
.
In o1js, you write this as:
const sum1 = Field(1).add(Field(3));
This can be simplified as:
// Note that the `3` is automatically converted to a Field instance.
const sum2 = Field(1).add(3);
Overflow Behavior
Field arithmetic supports overflow and underflow. See Integers for an o1js type that behaves more like a traditional integer type.
// The result is 0 because the sum overflows.
const overflow = Field(Field.ORDER - 1n).add(1);
// The result is equivalent to the order of the field minus 1 because the subtraction underflows.
const underflow = Field(0).sub(1);
Read more at the language reference: Field.