Skip to main content

Int64

A 64 bit signed integer with values ranging from -18,446,744,073,709,551,615 to 18,446,744,073,709,551,615.

Extends

  • CircuitValue

Implements

  • BalanceChange

Constructors

new Int64()

new Int64(magnitude: UInt64, sgn?: Sign): Int64

Parameters

magnitude: UInt64

The magnitude of the integer as a UInt64.

sgn?: Sign= Sign.one

The sign of the integer. Default is positive (Sign.one).

Returns

Int64

Overrides

CircuitValue.constructor

Deprecated

Use Int64.create for safe creation.

WARNING: This constructor allows for ambiguous representation of zero (both +0 and -0). This can lead to unexpected behavior in operations like () and ().

Security Implications:

  1. A malicious prover could choose either positive or negative zero.
  2. Arithmetic operations that result in 0 may allow an attacker to arbitrarily choose the sign.
  3. This ambiguity could be exploited in protocols using Int64s for calculations like PNL tracking.

Recommended Fix: Use Int64.create() which enforces a canonical representation of zero, or explicitly handle the zero case in operations like mod().

Source

lib/provable/int.ts:1141

Properties

magnitude

magnitude: UInt64;

Implementation of

BalanceChange.magnitude

Source

lib/provable/int.ts:1100


sgn

sgn: Sign;

Implementation of

BalanceChange.sgn

Source

lib/provable/int.ts:1101


Unsafe

static Unsafe: {
"fromObject": Int64;
};

fromObject()

Parameters

obj

obj.magnitude: UInt64

obj.sgn: Sign

Returns

Int64

Source

lib/provable/int.ts:1206

Accessors

minusOne

get static minusOne(): Int64

Static method to create a Int64 with value -1.

Returns

Int64

Source

lib/provable/int.ts:1258


one

get static one(): Int64

Static method to create a Int64 with value 1.

Returns

Int64

Source

lib/provable/int.ts:1252


zero

get static zero(): Int64

Static method to create a Int64 with value 0.

Returns

Int64

Source

lib/provable/int.ts:1246

Methods

add()

add(y: 
| string
| number
| bigint
| UInt64
| UInt32
| Int64): Int64

Addition with overflow checking.

Parameters

y: | string | number | bigint | UInt64 | UInt32 | Int64

Returns

Int64

Implementation of

BalanceChange.add

Source

lib/provable/int.ts:1309


assertEquals()

assertEquals(y: 
| string
| number
| bigint
| UInt64
| UInt32
| Int64, message?: string): void

Asserts that two values are equal.

Parameters

y: | string | number | bigint | UInt64 | UInt32 | Int64

message?: string

Returns

void

Implementation of

BalanceChange.assertEquals

Overrides

CircuitValue.assertEquals

Source

lib/provable/int.ts:1391


div()

div(y: 
| string
| number
| bigint
| UInt64
| UInt32
| Int64): Int64

Integer division with canonical zero representation.

Parameters

y: | string | number | bigint | UInt64 | UInt32 | Int64

The divisor. Can be an Int64, number, string, bigint, UInt64, or UInt32.

Returns

Int64

A new Int64 representing the quotient, with canonical zero representation.

x.div(y) returns the floor of x / y, that is, the greatest z such that `z y <= x`. On negative numbers, this rounds towards zero.

This method guarantees that all results, including zero, have a consistent representation, eliminating potential ambiguities in zero handling.

Implementation of

BalanceChange.div

Source

lib/provable/int.ts:1341


equals()

equals(y: 
| string
| number
| bigint
| UInt64
| UInt32
| Int64): Bool

Checks if two values are equal.

Parameters

y: | string | number | bigint | UInt64 | UInt32 | Int64

Returns

Bool

Implementation of

BalanceChange.equals

Overrides

CircuitValue.equals

Source

lib/provable/int.ts:1384


fromObject()

fromObject(obj: {
"magnitude": string | number | bigint | UInt64;
"sgn": bigint | Sign;
}): Int64

Parameters

obj

obj.magnitude: string | number | bigint | UInt64

obj.sgn: bigint | Sign

Returns

Int64

Implementation of

BalanceChange.fromObject

Source

lib/provable/int.ts:1212


isConstant()

isConstant(): boolean

Returns

boolean

Implementation of

BalanceChange.isConstant

Overrides

CircuitValue.isConstant

Source

lib/provable/int.ts:1235


isNegative()

isNegative(): Bool

Checks if the value is negative (x < 0).

Returns

Bool

Implementation of

BalanceChange.isNegative

Source

lib/provable/int.ts:1424


isNonNegative()

isNonNegative(): Bool

Checks if the value is non-negative (x >= 0).

Returns

Bool

Implementation of

BalanceChange.isNonNegative

Source

lib/provable/int.ts:1416


isPositive()

isPositive(): Bool

Checks if the value is strictly positive (x > 0).

Returns

Bool

True if the value is greater than zero, false otherwise.

Implementation of

BalanceChange.isPositive

Remarks

This method considers zero as non-positive. It ensures consistency with the mathematical definition of "positive" as strictly greater than zero. This differs from some other methods which may treat zero as non-negative.

Source

lib/provable/int.ts:1409


mod()

mod(y: 
| string
| number
| bigint
| UInt64
| UInt32): Int64

Calculates the integer remainder of this Int64 divided by the given value.

The result z satisfies the following conditions:

  1. 0 <= z < |y|
  2. x - z is divisible by y

Note: This method follows the "truncate toward zero" convention for negative numbers.

Parameters

y: | string | number | bigint | UInt64 | UInt32

The divisor. Will be converted to UInt64 if not already.

Returns

Int64

A new Int64 instance representing the remainder.

Implementation of

BalanceChange.mod

Example

const x1 = Int64.from(17);
const y1 = UInt64.from(5);
console.log(x1.mod(y1).toString()); // Output: 2

Throws

Implicitly, if y is zero or negative.

Source

lib/provable/int.ts:1369


mul()

mul(y: 
| string
| number
| bigint
| UInt64
| UInt32
| Int64): Int64

Multiplication with overflow checking.

Parameters

y: | string | number | bigint | UInt64 | UInt32 | Int64

Returns

Int64

Implementation of

BalanceChange.mul

Source

lib/provable/int.ts:1323


neg()

neg(): Int64

Negates the current Int64 value.

This method returns a new Int64 instance with the opposite sign of the current value. If the current value is zero, it returns zero.

Returns

Int64

A new Int64 instance with the negated value.

Implementation of

BalanceChange.neg

Example

Int64.from(5).neg();

See

  • Int64#from for creating Int64 instances
  • Int64#zero for the zero constant

Throws

Implicitly, if the internal Provable.if condition fails

Source

lib/provable/int.ts:1298


sub()

sub(y: 
| string
| number
| bigint
| UInt64
| UInt32
| Int64): Int64

Subtraction with underflow checking.

Parameters

y: | string | number | bigint | UInt64 | UInt32 | Int64

Returns

Int64

Implementation of

BalanceChange.sub

Source

lib/provable/int.ts:1316


toBigint()

toBigint(): bigint

Turns the Int64 into a BigInt.

Returns

bigint

Implementation of

BalanceChange.toBigint

Source

lib/provable/int.ts:1222


toConstant()

toConstant(): this

Returns

this

Implementation of

BalanceChange.toConstant

Inherited from

CircuitValue.toConstant

Source

lib/provable/types/circuit-value.ts:122


toField()

toField(): Field

Returns the Field value.

Returns

Field

Implementation of

BalanceChange.toField

Source

lib/provable/int.ts:1265


toFields()

toFields(): Field[]

Returns

Field[]

Implementation of

BalanceChange.toFields

Inherited from

CircuitValue.toFields

Source

lib/provable/types/circuit-value.ts:85


toJSON()

toJSON(): any

Returns

any

Implementation of

BalanceChange.toJSON

Inherited from

CircuitValue.toJSON

Source

lib/provable/types/circuit-value.ts:118


toString()

toString(): string

Turns the Int64 into a string.

Returns

string

Implementation of

BalanceChange.toString

Source

lib/provable/int.ts:1231


check()

static check(__namedParameters: {
"magnitude": UInt64;
"sgn": Sign;
}): void

Parameters

__namedParameters

__namedParameters.magnitude: UInt64

__namedParameters.sgn: Sign

Returns

void

Overrides

CircuitValue.check

Source

lib/provable/int.ts:1428


create()

static create(magnitude: UInt64, sign: Sign): Int64

Safely creates a new Int64 instance, enforcing canonical representation of zero. This is the recommended way to create Int64 instances.

Parameters

magnitude: UInt64

The magnitude of the integer as a UInt64

sign: Sign= Sign.one

Returns

Int64

A new Int64 instance with a canonical representation.

Example

const x = Int64.create(0); // canonical representation of zero

Source

lib/provable/int.ts:1158


empty()

static empty<T>(): InstanceType<T>

Type parameters

T extends AnyConstructor

Returns

InstanceType\<T>

Inherited from

CircuitValue.empty

Source

lib/provable/types/circuit-value.ts:230


from()

static from(x: 
| string
| number
| bigint
| Field
| UInt64
| UInt32
| Int64): Int64

Creates a new Int64.

Check the range if the argument is a constant.

Parameters

x: | string | number | bigint | Field | UInt64 | UInt32 | Int64

Returns

Int64

Source

lib/provable/int.ts:1198


fromField()

static fromField(x: Field): Int64

Static method to create a Int64 from a Field.

Parameters

x: Field

Returns

Int64

Source

lib/provable/int.ts:1271


fromFields()

static fromFields<T>(this: T, xs: Field[]): InstanceType<T>

Type parameters

T extends AnyConstructor

Parameters

this: T

xs: Field[]

Returns

InstanceType\<T>

Inherited from

CircuitValue.fromFields

Source

lib/provable/types/circuit-value.ts:138


fromJSON()

static fromJSON<T>(this: T, value: any): InstanceType<T>

Type parameters

T extends AnyConstructor

Parameters

this: T

value: any

Returns

InstanceType\<T>

Inherited from

CircuitValue.fromJSON

Source

lib/provable/types/circuit-value.ts:208


fromObject()

static fromObject<T>(this: T, value: NonMethods<InstanceType<T>>): InstanceType<T>

Type parameters

T extends AnyConstructor

Parameters

this: T

value: NonMethods\<InstanceType\<T>>

Returns

InstanceType\<T>

Inherited from

CircuitValue.fromObject

Source

lib/provable/types/circuit-value.ts:30


fromUnsigned()

static fromUnsigned(x: UInt64 | UInt32): Int64

Creates a new Int64 from a Field.

Does not check if the Field is within range.

Parameters

x: UInt64 | UInt32

Returns

Int64

Source

lib/provable/int.ts:1188


fromValue()

static fromValue<T>(this: T, value: any): InstanceType<T>

Type parameters

T extends AnyConstructor

Parameters

this: T

value: any

Returns

InstanceType\<T>

Inherited from

CircuitValue.fromValue

Source

lib/provable/types/circuit-value.ts:98


sizeInFields()

static sizeInFields(): number

Returns

number

Inherited from

CircuitValue.sizeInFields

Source

lib/provable/types/circuit-value.ts:37


toAuxiliary()

static toAuxiliary(): []

Returns

[]

Inherited from

CircuitValue.toAuxiliary

Source

lib/provable/types/circuit-value.ts:59


toCanonical()

static toCanonical<T>(this: T, value: InstanceType<T>): InstanceType<T>

Type parameters

T extends AnyConstructor

Parameters

this: T

value: InstanceType\<T>

Returns

InstanceType\<T>

Inherited from

CircuitValue.toCanonical

Source

lib/provable/types/circuit-value.ts:177


toConstant()

static toConstant<T>(this: T, t: InstanceType<T>): InstanceType<T>

Type parameters

T extends AnyConstructor

Parameters

this: T

t: InstanceType\<T>

Returns

InstanceType\<T>

Inherited from

CircuitValue.toConstant

Source

lib/provable/types/circuit-value.ts:189


toFields()

static toFields<T>(this: T, v: InstanceType<T>): Field[]

Type parameters

T extends AnyConstructor

Parameters

this: T

v: InstanceType\<T>

Returns

Field[]

Inherited from

CircuitValue.toFields

Source

lib/provable/types/circuit-value.ts:42


toInput()

static toInput<T>(this: T, v: InstanceType<T>): HashInput

Type parameters

T extends AnyConstructor

Parameters

this: T

v: InstanceType\<T>

Returns

HashInput

Inherited from

CircuitValue.toInput

Source

lib/provable/types/circuit-value.ts:63


toJSON()

static toJSON<T>(this: T, v: InstanceType<T>): any

Type parameters

T extends AnyConstructor

Parameters

this: T

v: InstanceType\<T>

Returns

any

Inherited from

CircuitValue.toJSON

Source

lib/provable/types/circuit-value.ts:197


toValue()

static toValue<T>(this: T, v: InstanceType<T>): any

Type parameters

T extends AnyConstructor

Parameters

this: T

v: InstanceType\<T>

Returns

any

Inherited from

CircuitValue.toValue

Source

lib/provable/types/circuit-value.ts:89