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:906


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:924


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:918


neg

neg(): Scalar

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

Returns

Scalar

Defined in

snarky.d.ts:900


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:912


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:886


toJSON

toJSON(): string

Serializes this Scalar to a string

Returns

string

Defined in

snarky.d.ts:929


check

Static check(x): void

Parameters

NameType
xScalar

Returns

void

Defined in

snarky.d.ts:971


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:970


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:950


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:942


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:965


random

Static random(): Scalar

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

Returns

Scalar

Defined in

snarky.d.ts:955


sizeInFields

Static sizeInFields(): number

Returns the size of this type.

Returns

number

Defined in

snarky.d.ts:946


toAuxiliary

Static toAuxiliary(x?): []

Static method to serialize a Scalar into its auxiliary data.

Parameters

NameType
x?Scalar

Returns

[]

Defined in

snarky.d.ts:938


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:934


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:894


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:960