Skip to main content

Field

const Field: typeof Field & (...args: [
| string
| number
| bigint
| FieldConst
| FieldVar
| Field]) => Field;

A Field is an element of a prime order finite field. Every other provable type is built using the Field type.

The field is the pasta base field of order 2^254 + 0x224698fc094cf91b992d30ed00000001 (Field.ORDER).

You can create a new Field from everything "field-like" (bigint, integer number, decimal string, Field).

Example

Field(10n); // Field construction from a bigint
Field(100); // Field construction from a number
Field("1"); // Field construction from a decimal string

Beware: Fields cannot be constructed from fractional numbers or alphanumeric strings:

Field(3.141); // ERROR: Cannot convert a float to a field element
Field("abc"); // ERROR: Invalid argument "abc"

Creating a Field from a negative number can result in unexpected behavior if you are not familiar with modular arithmetic.

Example

const x = Field(-1); // valid Field construction from negative number
const y = Field(Field.ORDER - 1n); // same as `x`

Important: All the functions defined on a Field (arithmetic, logic, etc.) take their arguments as "field-like". A Field itself is also defined as a "field-like" element.

Param

the value to convert to a Field

Source

lib/provable/wrapped.ts:42