Skip to main content

Class: Field

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Field(x)

Coerces anything field-like to a [[Field]].

Parameters

NameType
xstring | number | bigint | boolean | Field

Defined in

snarky.d.ts:28

Properties

ORDER

Static ORDER: bigint

The field order as a bigint.

Defined in

snarky.d.ts:266


minusOne

Static minusOne: Field

The number -1 as a [[Field]].

Defined in

snarky.d.ts:262


one

Static one: Field

The number 1 as a [[Field]].

Defined in

snarky.d.ts:254


zero

Static zero: Field

The number 0 as a [[Field]].

Defined in

snarky.d.ts:258

Methods

add

add(y): Field

Adds this [[Field]] element to another coercible to a field.

Parameters

NameType
ystring | number | boolean | Field

Returns

Field

Defined in

snarky.d.ts:56


assertBoolean

assertBoolean(): void

Assert that this [[Field]] is either 0 or 1.

Field.zero.assertBoolean();

This function can only be called inside a checked computation, like a SmartContract method, and throws an error if the assertion fails.

Returns

void

Defined in

snarky.d.ts:216


assertEquals

assertEquals(y): void

Assert that this [[Field]] equals another Field-like value. Throws an error if the assertion fails.

Field.one.assertEquals(1);

Parameters

NameType
ystring | number | boolean | Field

Returns

void

Defined in

snarky.d.ts:205


assertGt

assertGt(y): void

Assert that this [[Field]] is greater than another Field-like value.

Field.one.assertGt(0);

This function can only be called inside a checked computation, like a SmartContract method, and causes it to fail if the assertion fails.

Parameters

NameType
ystring | number | boolean | Field

Returns

void

Defined in

snarky.d.ts:184


assertGte

assertGte(y): void

Assert that this [[Field]] is greater than or equal to another Field-like value.

Field.one.assertGte(0);

This function can only be called inside a checked computation, like a SmartContract method, and causes it to fail if the assertion fails.

Parameters

NameType
ystring | number | boolean | Field

Returns

void

Defined in

snarky.d.ts:195


assertLt

assertLt(y): void

Assert that this [[Field]] is lower than another Field-like value.

Field.one.assertLt(2);

This function can only be called inside a checked computation, like a SmartContract method, and causes it to fail if the assertion fails.

Parameters

NameType
ystring | number | boolean | Field

Returns

void

Defined in

snarky.d.ts:162


assertLte

assertLte(y): void

Assert that this [[Field]] is lower than or equal to another Field-like value.

Field.one.assertLte(2);

This function can only be called inside a checked computation, like a SmartContract method, and causes it to fail if the assertion fails.

Parameters

NameType
ystring | number | boolean | Field

Returns

void

Defined in

snarky.d.ts:173


div

div(y): Field

Divides this [[Field]] element through another coercible to a field.

Parameters

NameType
ystring | number | boolean | Field

Returns

Field

Defined in

snarky.d.ts:71


equals

equals(y): Bool

Check if this [[Field]] equals another [[Field]]-like value. Returns a [[Bool]].

Field(2).equals(2); // Bool(true)

Parameters

NameType
ystring | number | boolean | Field

Returns

Bool

Defined in

snarky.d.ts:238


gt

gt(y): Bool

Check if this [[Field]] is greater than another Field-like value. Returns a [[Bool]].

Field(2).gt(1); // Bool(true)

Parameters

NameType
ystring | number | boolean | Field

Returns

Bool

Defined in

snarky.d.ts:140


gte

gte(y): Bool

Check if this [[Field]] is greater than or equal to another Field-like value. Returns a [[Bool]].

Field(2).gte(1); // Bool(true)

Parameters

NameType
ystring | number | boolean | Field

Returns

Bool

Defined in

snarky.d.ts:149


inv

inv(): Field

Inverts this [[Field]] element.

const invX = x.inv();
invX.assertEquals(Field.one.div(x));

Returns

Field

A field element that is equivalent to one divided by this element.

Defined in

snarky.d.ts:51


isConstant

isConstant(): boolean

Returns

boolean

Defined in

snarky.d.ts:245


isZero

isZero(): Bool

Returns

Bool

Defined in

snarky.d.ts:217


lt

lt(y): Bool

Check if this [[Field]] is lower than another Field-like value. Returns a [[Bool]].

Field(2).lt(3); // Bool(true)

Parameters

NameType
ystring | number | boolean | Field

Returns

Bool

Defined in

snarky.d.ts:122


lte

lte(y): Bool

Check if this [[Field]] is lower than or equal to another Field-like value. Returns a [[Bool]].

Field(2).lte(3); // Bool(true)

Parameters

NameType
ystring | number | boolean | Field

Returns

Bool

Defined in

snarky.d.ts:131


mul

mul(y): Field

Multiplies this [[Field]] element with another coercible to a field.

Parameters

NameType
ystring | number | boolean | Field

Returns

Field

Defined in

snarky.d.ts:66


neg

neg(): Field

Negates this [[Field]]. This is equivalent to multiplying the [[Field]] by -1.

const negOne = Field.one.neg();
negOne.assertEquals(-1);

Returns

Field

Defined in

snarky.d.ts:39


ofFields

ofFields(fields): Field

Parameters

NameType
fieldsField[]

Returns

Field

Defined in

snarky.d.ts:301


rangeCheckHelper

rangeCheckHelper(numBits): Field

Parameters

NameType
numBitsnumber

Returns

Field

Defined in

snarky.d.ts:243


seal

seal(): Field

Returns

Field

Defined in

snarky.d.ts:241


sizeInFields

sizeInFields(): number

Returns

number

Defined in

snarky.d.ts:109


sqrt

sqrt(): Field

Square roots this [[Field]] element.

x.square().sqrt().assertEquals(x);

Returns

Field

Defined in

snarky.d.ts:90


square

square(): Field

Squares this [[Field]] element.

const x2 = x.square();
x2.assertEquals(x.mul(x));

Returns

Field

Defined in

snarky.d.ts:81


sub

sub(y): Field

Subtracts another [[Field]]-like element from this one.

Parameters

NameType
ystring | number | boolean | Field

Returns

Field

Defined in

snarky.d.ts:61


toBigInt

toBigInt(): bigint

Serialize the [[Field]] to a bigint. This operation does NOT affect the circuit and can't be used to prove anything about the bigint representation of the Field.

Returns

bigint

Defined in

snarky.d.ts:101


toBits

toBits(): Bool[]

Little endian binary representation of the field element.

Returns

Bool[]

Defined in

snarky.d.ts:222

toBits(length): Bool[]

Little endian binary representation of the field element. Fails if the field element cannot fit in length bits.

Parameters

NameType
lengthnumber

Returns

Bool[]

Defined in

snarky.d.ts:228


toConstant

toConstant(): Field

Returns

Field

Defined in

snarky.d.ts:246


toFields

toFields(): Field[]

Returns

Field[]

Defined in

snarky.d.ts:111


toJSON

toJSON(): JSONValue

Serialize the [[Field]] to a JSON string. This operation does NOT affect the circuit and can't be used to prove anything about the string representation of the Field.

Returns

JSONValue

Defined in

snarky.d.ts:106


toString

toString(): string

Serialize the [[Field]] to a string, e.g. for printing. This operation does NOT affect the circuit and can't be used to prove anything about the string representation of the Field.

Returns

string

Defined in

snarky.d.ts:96


check

Static check(x): void

Parameters

NameType
xField

Returns

void

Defined in

snarky.d.ts:344


fromBigInt

Static fromBigInt(x): Field

Parameters

NameType
xbigint

Returns

Field

Defined in

snarky.d.ts:342


fromJSON

Static fromJSON(x): null | Field

Parameters

NameType
xJSONValue

Returns

null | Field

Defined in

snarky.d.ts:338


fromNumber

Static fromNumber(x): Field

Parameters

NameType
xnumber

Returns

Field

Defined in

snarky.d.ts:341


fromString

Static fromString(x): Field

Parameters

NameType
xstring

Returns

Field

Defined in

snarky.d.ts:340


ofBits

Static ofBits(x): Field

Converts a bit array into a field element (little endian) Fails if the field element cannot fit given too many bits.

TODO: Rename to fromBits

Parameters

NameType
x(boolean | Bool)[]

Returns

Field

Defined in

snarky.d.ts:325


ofFields

Static ofFields(fields): Field

Parameters

NameType
fieldsField[]

Returns

Field

Defined in

snarky.d.ts:304


random

Static random(): Field

A random field element.

Returns

Field

Defined in

snarky.d.ts:271


sizeInFields

Static sizeInFields(): number

Returns

number

Defined in

snarky.d.ts:306


toFields

Static toFields(x): Field[]

Parameters

NameType
xField

Returns

Field[]

Defined in

snarky.d.ts:308


toInput

Static toInput(x): Object

Parameters

NameType
xField

Returns

Object

NameType
fieldsField[]

Defined in

snarky.d.ts:347


toJSON

Static toJSON(x): JSONValue

Parameters

NameType
xField

Returns

JSONValue

Defined in

snarky.d.ts:337