Skip to main content

Class: Scalar

Represents a Scalar.

Table of contents

Constructors

Methods

Constructors

constructor

new Scalar()

Methods

add

add(y): Scalar

Add scalar field elements. Can only be called outside of circuit execution

Parameters

NameType
yScalar

Returns

Scalar

Defined in

snarky.d.ts:933


div

div(y): Scalar

Divide scalar field elements. Can only be called outside of circuit execution

Parameters

NameType
yScalar

Returns

Scalar

Defined in

snarky.d.ts:951


mul

mul(y): Scalar

Multiply scalar field elements. Can only be called outside of circuit execution

Parameters

NameType
yScalar

Returns

Scalar

Defined in

snarky.d.ts:945


neg

neg(): Scalar

Negate a scalar field element. Can only be called outside of circuit execution

Returns

Scalar

Defined in

snarky.d.ts:927


sub

sub(y): Scalar

Subtract scalar field elements. Can only be called outside of circuit execution

Parameters

NameType
yScalar

Returns

Scalar

Defined in

snarky.d.ts:939


toFields

toFields(): Field[]

Serialize this Scalar to Field elements.

WARNING: This function is for internal usage by the proof system. It returns 255 field elements which represent the Scalar in a shifted, bitwise format. Check out toFieldsCompressed for a user-friendly serialization that can be used outside proofs.

Returns

Field[]

Defined in

snarky.d.ts:913


toJSON

toJSON(): string

Serializes this Scalar to a string

Returns

string

Defined in

snarky.d.ts:956


check

Static check(x): void

Parameters

NameType
xScalar

Returns

void

Defined in

snarky.d.ts:998


fromBigInt

Static fromBigInt(s): Scalar

Create a constant Scalar from a bigint. If the bigint is too large, it is reduced modulo the scalar field order.

Parameters

NameType
sbigint

Returns

Scalar

Defined in

snarky.d.ts:997


fromBits

Static fromBits(bits): Scalar

Creates a data structure from an array of serialized Bool.

Parameters

NameType
bitsBool[]

Returns

Scalar

Defined in

snarky.d.ts:977


fromFields

Static fromFields(fields): Scalar

Creates a data structure from an array of serialized Field elements.

Parameters

NameType
fieldsField[]

Returns

Scalar

Defined in

snarky.d.ts:969


fromJSON

Static fromJSON(x): Scalar

Deserialize a JSON structure into a Scalar. This operation does NOT affect the circuit and can't be used to prove anything about the string representation of the Scalar.

Parameters

NameType
xstring | number | boolean

Returns

Scalar

Defined in

snarky.d.ts:992


random

Static random(): Scalar

Returns a random Scalar. Randomness can not be proven inside a circuit!

Returns

Scalar

Defined in

snarky.d.ts:982


sizeInFields

Static sizeInFields(): number

Returns the size of this type.

Returns

number

Defined in

snarky.d.ts:973


toAuxiliary

Static toAuxiliary(x?): []

Static method to serialize a Scalar into its auxiliary data.

Parameters

NameType
x?Scalar

Returns

[]

Defined in

snarky.d.ts:965


toFields

Static toFields(x): Field[]

Static method to serialize a Scalar into an array of Field elements.

Parameters

NameType
xScalar

Returns

Field[]

Defined in

snarky.d.ts:961


toFieldsCompressed

Static toFieldsCompressed(s): Object

Serialize a Scalar into a Field element plus one bit, where the bit is represented as a Bool.

Note: Since the Scalar field is slightly larger than the base Field, an additional high bit is needed to represent all Scalars. However, for a random Scalar, the high bit will be false with overwhelming probability.

Parameters

NameType
sScalar

Returns

Object

NameType
fieldField
highBitBool

Defined in

snarky.d.ts:921


toJSON

Static toJSON(x): string

Serialize a Scalar 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 Scalar.

Parameters

NameType
xScalar

Returns

string

Defined in

snarky.d.ts:987