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
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:
- A malicious prover could choose either positive or negative zero.
- Arithmetic operations that result in 0 may allow an attacker to arbitrarily choose the sign.
- 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
Properties
magnitude
magnitude: UInt64;
Implementation of
BalanceChange.magnitude
Source
sgn
sgn: Sign;
Implementation of
BalanceChange.sgn
Source
Unsafe
static Unsafe: {
"fromObject": Int64;
};
fromObject()
Parameters
• obj
• obj.magnitude: UInt64
• obj.sgn: Sign
Returns
Source
Accessors
minusOne
get static minusOne(): Int64
Static method to create a Int64 with value -1
.
Returns
Source
one
get static one(): Int64
Static method to create a Int64 with value 1
.
Returns
Source
zero
get static zero(): Int64
Static method to create a Int64 with value 0
.
Returns
Source
Methods
add()
add(y:
| string
| number
| bigint
| UInt64
| UInt32
| Int64): Int64
Addition with overflow checking.
Parameters
• y:
| string
| number
| bigint
| UInt64
| UInt32
| Int64
Returns
Implementation of
BalanceChange.add
Source
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
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
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
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
Implementation of
BalanceChange.equals
Overrides
CircuitValue.equals
Source
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
Implementation of
BalanceChange.fromObject
Source
isConstant()
isConstant(): boolean
Returns
boolean
Implementation of
BalanceChange.isConstant
Overrides
CircuitValue.isConstant
Source
isNegative()
isNegative(): Bool
Checks if the value is negative (x < 0).
Returns
Implementation of
BalanceChange.isNegative
Source
isNonNegative()
isNonNegative(): Bool
Checks if the value is non-negative (x >= 0).
Returns
Implementation of
BalanceChange.isNonNegative
Source
isPositive()
isPositive(): Bool
Checks if the value is strictly positive (x > 0).
Returns
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
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:
- 0 <= z < |y|
- 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
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
mul()
mul(y:
| string
| number
| bigint
| UInt64
| UInt32
| Int64): Int64
Multiplication with overflow checking.
Parameters
• y:
| string
| number
| bigint
| UInt64
| UInt32
| Int64
Returns
Implementation of
BalanceChange.mul
Source
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
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
sub()
sub(y:
| string
| number
| bigint
| UInt64
| UInt32
| Int64): Int64
Subtraction with underflow checking.
Parameters
• y:
| string
| number
| bigint
| UInt64
| UInt32
| Int64
Returns
Implementation of
BalanceChange.sub
Source
toBigint()
toBigint(): bigint
Turns the Int64 into a BigInt.
Returns
bigint
Implementation of
BalanceChange.toBigint
Source
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
Implementation of
BalanceChange.toField
Source
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
check()
static check(__namedParameters: {
"magnitude": UInt64;
"sgn": Sign;
}): void
Parameters
• __namedParameters
• __namedParameters.magnitude: UInt64
• __namedParameters.sgn: Sign
Returns
void
Overrides
CircuitValue.check
Source
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
A new Int64 instance with a canonical representation.
Example
const x = Int64.create(0); // canonical representation of zero
Source
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
Source
fromField()
static fromField(x: Field): Int64
Static method to create a Int64 from a Field.
Parameters
• x: Field
Returns
Source
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
Returns
Source
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