Skip to main content
Version: 2.15.0

UnreducedForeignField

Defined in: lib/provable/foreign-field.ts:487

Extends​

Extended by​

Properties​

type​

type: "Unreduced" | "AlmostReduced" | "FullyReduced" = 'Unreduced';

Defined in: lib/provable/foreign-field.ts:488


value​

value: Field3;

Defined in: lib/provable/foreign-field.ts:40

The internal representation of a foreign field element, as a tuple of 3 limbs.

Inherited from​

ForeignField.value

Accessors​

Constructor​

Get Signature​

get Constructor(): typeof ForeignField;

Defined in: lib/provable/foreign-field.ts:42

Returns​

typeof ForeignField

Inherited from​

ForeignField.Constructor


modulus​

Get Signature​

get modulus(): bigint;

Defined in: lib/provable/foreign-field.ts:30

Returns​

bigint

Inherited from​

ForeignField.modulus

Methods​

add()​

add(y: number | bigint | ForeignField): UnreducedForeignField;

Defined in: lib/provable/foreign-field.ts:243

Finite field addition

Parameters​

y​

number | bigint | ForeignField

Returns​

UnreducedForeignField

Example​

x.add(2); // x + 2 mod p

Inherited from​

ForeignField.add


assertAlmostReduced()​

assertAlmostReduced(): AlmostForeignField;

Defined in: lib/provable/foreign-field.ts:198

Assert that this field element lies in the range [0, 2^k), where k = ceil(log2(p)) and p is the foreign field modulus.

Returns the field element as a AlmostForeignField.

For a more efficient version of this for multiple field elements, see assertAlmostReduced.

Note: this does not ensure that the field elements is in the canonical range [0, p). To assert that stronger property, there is assertCanonical. You should typically use assertAlmostReduced though, because it is cheaper to prove and sufficient for ensuring validity of all our non-native field arithmetic methods.

Returns​

AlmostForeignField

Inherited from​

ForeignField.assertAlmostReduced


assertCanonical()​

assertCanonical(): CanonicalForeignField;

Defined in: lib/provable/foreign-field.ts:229

Assert that this field element is fully reduced, i.e. lies in the range [0, p), where p is the foreign field modulus.

Returns the field element as a CanonicalForeignField.

Returns​

CanonicalForeignField

Inherited from​

ForeignField.assertCanonical


assertEquals()​

Call Signature​

assertEquals(y: number | bigint | CanonicalForeignField, message?: string): CanonicalForeignField;

Defined in: lib/provable/foreign-field.ts:321

Assert equality with a ForeignField-like value

Parameters​
y​

number | bigint | CanonicalForeignField

message?​

string

Returns​

CanonicalForeignField

Examples​
x.assertEquals(0, "x is zero");

Since asserting equality can also serve as a range check, this method returns x with the appropriate type:

let xChecked = x.assertEquals(1, "x is 1");
xChecked satisfies CanonicalForeignField;
Inherited from​

ForeignField.assertEquals

Call Signature​

assertEquals(y: AlmostForeignField, message?: string): AlmostForeignField;

Defined in: lib/provable/foreign-field.ts:322

Assert equality with a ForeignField-like value

Parameters​
y​

AlmostForeignField

message?​

string

Returns​

AlmostForeignField

Examples​
x.assertEquals(0, "x is zero");

Since asserting equality can also serve as a range check, this method returns x with the appropriate type:

let xChecked = x.assertEquals(1, "x is 1");
xChecked satisfies CanonicalForeignField;
Inherited from​

ForeignField.assertEquals

Call Signature​

assertEquals(y: ForeignField, message?: string): ForeignField;

Defined in: lib/provable/foreign-field.ts:323

Assert equality with a ForeignField-like value

Parameters​
y​

ForeignField

message?​

string

Returns​

ForeignField

Examples​
x.assertEquals(0, "x is zero");

Since asserting equality can also serve as a range check, this method returns x with the appropriate type:

let xChecked = x.assertEquals(1, "x is 1");
xChecked satisfies CanonicalForeignField;
Inherited from​

ForeignField.assertEquals


assertLessThan()​

assertLessThan(c: number | bigint, message?: string): void;

Defined in: lib/provable/foreign-field.ts:358

Assert that this field element is less than a constant c: x < c.

The constant must satisfy 0 <= c < 2^264, otherwise an error is thrown.

Parameters​

c​

number | bigint

message?​

string

Returns​

void

Example​

x.assertLessThan(10);

Inherited from​

ForeignField.assertLessThan


neg()​

neg(): AlmostForeignField;

Defined in: lib/provable/foreign-field.ts:254

Finite field negation

Returns​

AlmostForeignField

Example​

x.neg(); // -x mod p = p - x

Inherited from​

ForeignField.neg


sub()​

sub(y: number | bigint | ForeignField): UnreducedForeignField;

Defined in: lib/provable/foreign-field.ts:269

Finite field subtraction

Parameters​

y​

number | bigint | ForeignField

Returns​

UnreducedForeignField

Example​

x.sub(1); // x - 1 mod p

Inherited from​

ForeignField.sub


toBigInt()​

toBigInt(): bigint;

Defined in: lib/provable/foreign-field.ts:181

Convert this field element to a bigint.

Returns​

bigint

Inherited from​

ForeignField.toBigInt


toBits()​

toBits(length?: number): Bool[];

Defined in: lib/provable/foreign-field.ts:377

Unpack a field element to its bits, as a Bool[] array.

This method is provable!

Parameters​

length?​

number

Returns​

Bool[]

Inherited from​

ForeignField.toBits


toFields()​

toFields(): Field[];

Defined in: lib/provable/foreign-field.ts:425

Instance version of Provable<ForeignField>.toFields, see Provable.toFields

Returns​

Field[]

Inherited from​

ForeignField.toFields