Int64
Defined in: lib/provable/int.ts:1174
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
Defined in: lib/provable/int.ts:1219
Parameters
magnitude
The magnitude of the integer as a UInt64.
sgn?
Sign
= Sign.one
The sign of the integer. Default is positive (Sign.one).
Returns
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().
Overrides
CircuitValue.constructor
Properties
magnitude
magnitude: UInt64;
Defined in: lib/provable/int.ts:1178
Implementation of
BalanceChange.magnitude
sgn
sgn: Sign;
Defined in: lib/provable/int.ts:1179
Implementation of
BalanceChange.sgn
Unsafe
static Unsafe: {
fromObject: Int64;
};
Defined in: lib/provable/int.ts:1284
fromObject()
Parameters
obj
magnitude
sgn
Returns
Accessors
minusOne
Get Signature
get static minusOne(): Int64
Defined in: lib/provable/int.ts:1333
Static method to create a Int64 with value -1
.
Returns
one
Get Signature
get static one(): Int64
Defined in: lib/provable/int.ts:1327
Static method to create a Int64 with value 1
.
Returns
zero
Get Signature
get static zero(): Int64
Defined in: lib/provable/int.ts:1321
Static method to create a Int64 with value 0
.
Returns
Methods
add()
add(y:
| string
| number
| bigint
| UInt64
| UInt32
| Int64): Int64
Defined in: lib/provable/int.ts:1384
Addition with overflow checking.
Parameters
y
string
| number
| bigint
| UInt64
| UInt32
| Int64
Returns
Implementation of
BalanceChange.add
assertEquals()
assertEquals(y:
| string
| number
| bigint
| UInt64
| UInt32
| Int64, message?: string): void
Defined in: lib/provable/int.ts:1462
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
div()
div(y:
| string
| number
| bigint
| UInt64
| UInt32
| Int64): Int64
Defined in: lib/provable/int.ts:1416
Integer division with canonical zero representation.
Parameters
y
The divisor. Can be an Int64, number, string, bigint, UInt64, or UInt32.
string
| number
| bigint
| UInt64
| UInt32
| Int64
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
equals()
equals(y:
| string
| number
| bigint
| UInt64
| UInt32
| Int64): Bool
Defined in: lib/provable/int.ts:1455
Checks if two values are equal.
Parameters
y
string
| number
| bigint
| UInt64
| UInt32
| Int64
Returns
Implementation of
BalanceChange.equals
Overrides
CircuitValue.equals
fromObject()
fromObject(obj: {
magnitude: string | number | bigint | UInt64;
sgn: bigint | Sign;
}): Int64
Defined in: lib/provable/int.ts:1290
Parameters
obj
magnitude
string
| number
| bigint
| UInt64
sgn
bigint
| Sign
Returns
Implementation of
BalanceChange.fromObject
isConstant()
isConstant(): boolean
Defined in: lib/provable/int.ts:1310
Returns
boolean
Implementation of
BalanceChange.isConstant
Overrides
CircuitValue.isConstant
isNegative()
isNegative(): Bool
Defined in: lib/provable/int.ts:1492
Checks if the value is negative (x < 0).
Returns
Implementation of
BalanceChange.isNegative
isNonNegative()
isNonNegative(): Bool
Defined in: lib/provable/int.ts:1484
Checks if the value is non-negative (x >= 0).
Returns
Implementation of
BalanceChange.isNonNegative
isPositive()
isPositive(): Bool
Defined in: lib/provable/int.ts:1477
Checks if the value is strictly positive (x > 0).
Returns
True if the value is greater than zero, false otherwise.
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.
Implementation of
BalanceChange.isPositive
mod()
mod(y: string | number | bigint | UInt64 | UInt32): Int64
Defined in: lib/provable/int.ts:1444
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
The divisor. Will be converted to UInt64 if not already.
string
| number
| bigint
| UInt64
| UInt32
Returns
A new Int64 instance representing the remainder.
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.
Implementation of
BalanceChange.mod
mul()
mul(y:
| string
| number
| bigint
| UInt64
| UInt32
| Int64): Int64
Defined in: lib/provable/int.ts:1398
Multiplication with overflow checking.
Parameters
y
string
| number
| bigint
| UInt64
| UInt32
| Int64
Returns
Implementation of
BalanceChange.mul
neg()
neg(): Int64
Defined in: lib/provable/int.ts:1373
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.
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
Implementation of
BalanceChange.neg
sub()
sub(y:
| string
| number
| bigint
| UInt64
| UInt32
| Int64): Int64
Defined in: lib/provable/int.ts:1391
Subtraction with underflow checking.
Parameters
y
string
| number
| bigint
| UInt64
| UInt32
| Int64
Returns
Implementation of
BalanceChange.sub
toBigint()
toBigint(): bigint
Defined in: lib/provable/int.ts:1297
Turns the Int64 into a BigInt.
Returns
bigint
Implementation of
BalanceChange.toBigint
toConstant()
toConstant(): this
Defined in: lib/provable/types/circuit-value.ts:113
Returns
this
Implementation of
BalanceChange.toConstant
Inherited from
CircuitValue.toConstant
toField()
toField(): Field
Defined in: lib/provable/int.ts:1340
Returns the Field value.
Returns
Implementation of
BalanceChange.toField
toFields()
toFields(): Field[]
Defined in: lib/provable/types/circuit-value.ts:79
Returns
Field
[]
Implementation of
BalanceChange.toFields
Inherited from
CircuitValue.toFields
toJSON()
toJSON(): any
Defined in: lib/provable/types/circuit-value.ts:109
Returns
any
Implementation of
BalanceChange.toJSON
Inherited from
CircuitValue.toJSON
toString()
toString(): string
Defined in: lib/provable/int.ts:1306
Turns the Int64 into a string.
Returns
string
Implementation of
BalanceChange.toString
check()
static check(__namedParameters: {
magnitude: UInt64;
sgn: Sign;
}): void
Defined in: lib/provable/int.ts:1496
Parameters
__namedParameters
magnitude
sgn
Returns
void
Overrides
CircuitValue.check
create()
static create(magnitude: UInt64, sign: Sign): Int64
Defined in: lib/provable/int.ts:1236
Safely creates a new Int64 instance, enforcing canonical representation of zero. This is the recommended way to create Int64 instances.
Parameters
magnitude
The magnitude of the integer as a UInt64
sign
Sign
= Sign.one
The sign of the integer.
Returns
A new Int64 instance with a canonical representation.
Example
const x = Int64.create(0); // canonical representation of zero
empty()
static empty<T>(): InstanceType<T>
Defined in: lib/provable/types/circuit-value.ts:205
Type Parameters
• T extends AnyConstructor
Returns
InstanceType
<T
>
Inherited from
CircuitValue.empty
from()
static from(x:
| string
| number
| bigint
| Field
| UInt64
| UInt32
| Int64): Int64
Defined in: lib/provable/int.ts:1276
Creates a new Int64.
Check the range if the argument is a constant.
Parameters
x
string
| number
| bigint
| Field
| UInt64
| UInt32
| Int64
Returns
fromField()
static fromField(x: Field): Int64
Defined in: lib/provable/int.ts:1346
Static method to create a Int64 from a Field.
Parameters
x
Returns
fromFields()
static fromFields<T>(this: T, xs: Field[]): InstanceType<T>
Defined in: lib/provable/types/circuit-value.ts:129
Type Parameters
• T extends AnyConstructor
Parameters
this
T
xs
Field
[]
Returns
InstanceType
<T
>
Inherited from
CircuitValue.fromFields
fromJSON()
static fromJSON<T>(this: T, value: any): InstanceType<T>
Defined in: lib/provable/types/circuit-value.ts:186
Type Parameters
• T extends AnyConstructor
Parameters
this
T
value
any
Returns
InstanceType
<T
>
Inherited from
CircuitValue.fromJSON
fromObject()
static fromObject<T>(this: T, value: NonMethods<InstanceType<T>>): InstanceType<T>
Defined in: lib/provable/types/circuit-value.ts:30
Type Parameters
• T extends AnyConstructor
Parameters
this
T
value
NonMethods
<InstanceType
<T
>>
Returns
InstanceType
<T
>
Inherited from
CircuitValue.fromObject
fromUnsigned()
static fromUnsigned(x: UInt64 | UInt32): Int64
Defined in: lib/provable/int.ts:1266
Creates a new Int64 from a Field.
Does not check if the Field is within range.
Parameters
x
Returns
fromValue()
static fromValue<T>(this: T, value: any): InstanceType<T>
Defined in: lib/provable/types/circuit-value.ts:92
Type Parameters
• T extends AnyConstructor
Parameters
this
T
value
any
Returns
InstanceType
<T
>
Inherited from
CircuitValue.fromValue
sizeInFields()
static sizeInFields(): number
Defined in: lib/provable/types/circuit-value.ts:37
Returns
number
Inherited from
CircuitValue.sizeInFields
toAuxiliary()
static toAuxiliary(): []
Defined in: lib/provable/types/circuit-value.ts:56
Returns
[]
Inherited from
CircuitValue.toAuxiliary
toCanonical()
static toCanonical<T>(this: T, value: InstanceType<T>): InstanceType<T>
Defined in: lib/provable/types/circuit-value.ts:161
Type Parameters
• T extends AnyConstructor
Parameters
this
T
value
InstanceType
<T
>
Returns
InstanceType
<T
>
Inherited from
CircuitValue.toCanonical
toConstant()
static toConstant<T>(this: T, t: InstanceType<T>): InstanceType<T>
Defined in: lib/provable/types/circuit-value.ts:170
Type Parameters
• T extends AnyConstructor
Parameters
this
T
t
InstanceType
<T
>
Returns
InstanceType
<T
>
Inherited from
CircuitValue.toConstant
toFields()
static toFields<T>(this: T, v: InstanceType<T>): Field[]
Defined in: lib/provable/types/circuit-value.ts:42
Type Parameters
• T extends AnyConstructor
Parameters
this
T
v
InstanceType
<T
>
Returns
Field
[]
Inherited from
CircuitValue.toFields
toInput()
static toInput<T>(this: T, v: InstanceType<T>): HashInput
Defined in: lib/provable/types/circuit-value.ts:60
Type Parameters
• T extends AnyConstructor
Parameters
this
T
v
InstanceType
<T
>
Returns
HashInput
Inherited from
CircuitValue.toInput
toJSON()
static toJSON<T>(this: T, v: InstanceType<T>): any
Defined in: lib/provable/types/circuit-value.ts:175
Type Parameters
• T extends AnyConstructor
Parameters
this
T
v
InstanceType
<T
>
Returns
any
Inherited from
CircuitValue.toJSON
toValue()
static toValue<T>(this: T, v: InstanceType<T>): any
Defined in: lib/provable/types/circuit-value.ts:83
Type Parameters
• T extends AnyConstructor
Parameters
this
T
v
InstanceType
<T
>
Returns
any
Inherited from
CircuitValue.toValue