Skip to main content

UInt64

o1js / Modules / UInt64

Class: UInt64

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

Hierarchy

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new UInt64(x)

Parameters

NameType
xstring | number | bigint | Field | UInt64 | UInt32

Overrides

CircuitValue.constructor

Defined in

lib/int.ts:22

Properties

value

value: Field

Defined in

lib/int.ts:19


NUM_BITS

Static NUM_BITS: number = 64

Defined in

lib/int.ts:20

Accessors

one

Static get one(): UInt64

Static method to create a UInt64 with value 1.

Returns

UInt64

Defined in

lib/int.ts:37


zero

Static get zero(): UInt64

Static method to create a UInt64 with value 0.

Returns

UInt64

Defined in

lib/int.ts:31

Methods

add

add(y): UInt64

Addition with overflow checking.

Parameters

NameType
ynumber | UInt64

Returns

UInt64

Defined in

lib/int.ts:202


and

and(x): UInt64

Bitwise AND gadget on UInt64 elements. Equivalent to the bitwise AND & operator in JavaScript. The AND gate works by comparing two bits and returning 1 if both bits are 1, and 0 otherwise.

It can be checked by a double generic gate that verifies the following relationship between the values below.

The generic gate verifies:\ a + b = sum and the conjunction equation 2 * and = sum - xor\ Where:\ a + b = sum\ a ^ b = xor\ a & b = and

You can find more details about the implementation in the Mina book

Parameters

NameType
xUInt64

Returns

UInt64

Example

let a = UInt64.from(3);    // ... 000011
let b = UInt64.from(5); // ... 000101

let c = a.and(b); // ... 000001
c.assertEquals(1);

Defined in

lib/int.ts:372


assertEquals

assertEquals(x): void

Parameters

NameType
xUInt64

Returns

void

Inherited from

CircuitValue.assertEquals

Defined in

lib/circuit-value.ts:167


assertGreaterThan

assertGreaterThan(y, message?): void

Asserts that a UInt64 is greater than another one.

Parameters

NameType
yUInt64
message?string

Returns

void

Defined in

lib/int.ts:506


assertGreaterThanOrEqual

assertGreaterThanOrEqual(y, message?): void

Asserts that a UInt64 is greater than or equal to another one.

Parameters

NameType
yUInt64
message?string

Returns

void

Defined in

lib/int.ts:538


assertGt

assertGt(y, message?): void

Parameters

NameType
yUInt64
message?string

Returns

void

Deprecated

Use assertGreaterThan instead.

Asserts that a UInt64 is greater than another one.

Defined in

lib/int.ts:499


assertGte

assertGte(y, message?): void

Parameters

NameType
yUInt64
message?string

Returns

void

Deprecated

Use assertGreaterThanOrEqual instead.

Asserts that a UInt64 is greater than or equal to another one.

Defined in

lib/int.ts:531


assertLessThan

assertLessThan(y, message?): void

Asserts that a UInt64 is less than another one.

Parameters

NameType
yUInt64
message?string

Returns

void

Defined in

lib/int.ts:474


assertLessThanOrEqual

assertLessThanOrEqual(y, message?): void

Asserts that a UInt64 is less than or equal to another one.

Parameters

NameType
yUInt64
message?string

Returns

void

Defined in

lib/int.ts:430


assertLt

assertLt(y, message?): void

Parameters

NameType
yUInt64
message?string

Returns

void

Deprecated

Use assertLessThan instead.

Asserts that a UInt64 is less than another one.

Defined in

lib/int.ts:467


assertLte

assertLte(y, message?): void

Parameters

NameType
yUInt64
message?string

Returns

void

Deprecated

Use assertLessThanOrEqual instead.

Asserts that a UInt64 is less than or equal to another one.

Defined in

lib/int.ts:423


div

div(y): UInt64

Integer division.

x.div(y) returns the floor of x / y, that is, the greatest z such that z * y <= x.

Parameters

NameType
ynumber | UInt64

Returns

UInt64

Defined in

lib/int.ts:176


divMod

divMod(y): Object

Integer division with remainder.

x.divMod(y) returns the quotient and the remainder.

Parameters

NameType
ystring | number | UInt64

Returns

Object

NameType
quotientUInt64
restUInt64

Defined in

lib/int.ts:133


equals

equals(x): Bool

Parameters

NameType
xUInt64

Returns

Bool

Inherited from

CircuitValue.equals

Defined in

lib/circuit-value.ts:163


greaterThan

greaterThan(y): Bool

Checks if a UInt64 is greater than another one.

Parameters

NameType
yUInt64

Returns

Bool

Defined in

lib/int.ts:490


greaterThanOrEqual

greaterThanOrEqual(y): Bool

Checks if a UInt64 is greater than or equal to another one.

Parameters

NameType
yUInt64

Returns

Bool

Defined in

lib/int.ts:522


gt

gt(y): Bool

Parameters

NameType
yUInt64

Returns

Bool

Deprecated

Use greaterThan instead.

Checks if a UInt64 is greater than another one.

Defined in

lib/int.ts:483


gte

gte(y): Bool

Parameters

NameType
yUInt64

Returns

Bool

Deprecated

Use greaterThanOrEqual instead.

Checks if a UInt64 is greater than or equal to another one.

Defined in

lib/int.ts:515


isConstant

isConstant(): boolean

Returns

boolean

Inherited from

CircuitValue.isConstant

Defined in

lib/circuit-value.ts:171


leftShift

leftShift(bits): UInt64

Performs a left shift operation on the provided UInt64 element. This operation is similar to the << shift operation in JavaScript, where bits are shifted to the left, and the overflowing bits are discarded.

It’s important to note that these operations are performed considering the big-endian 64-bit representation of the number, where the most significant (64th) bit is on the left end and the least significant bit is on the right end.

Parameters

NameTypeDescription
bitsnumberAmount of bits to shift the UInt64 element to the left. The amount should be between 0 and 64 (or else the shift will fail).

Returns

UInt64

Example

const x = UInt64.from(0b001100); // 12 in binary
const y = x.leftShift(2); // left shift by 2 bits
y.assertEquals(0b110000); // 48 in binary

Defined in

lib/int.ts:322


lessThan

lessThan(y): Bool

Checks if a UInt64 is less than another one.

Parameters

NameType
yUInt64

Returns

Bool

Defined in

lib/int.ts:457


lessThanOrEqual

lessThanOrEqual(y): Bool

Checks if a UInt64 is less than or equal to another one.

Parameters

NameType
yUInt64

Returns

Bool

Defined in

lib/int.ts:401


lt

lt(y): Bool

Parameters

NameType
yUInt64

Returns

Bool

Deprecated

Use lessThan instead.

Checks if a UInt64 is less than another one.

Defined in

lib/int.ts:449


lte

lte(y): Bool

Parameters

NameType
yUInt64

Returns

Bool

Deprecated

Use lessThanOrEqual instead.

Checks if a UInt64 is less than or equal to another one.

Defined in

lib/int.ts:381


mod

mod(y): UInt64

Integer remainder.

x.mod(y) returns the value z such that 0 <= z < y and x - z is divisible by y.

Parameters

NameType
ynumber | UInt64

Returns

UInt64

Defined in

lib/int.ts:186


mul

mul(y): UInt64

Multiplication with overflow checking.

Parameters

NameType
ynumber | UInt64

Returns

UInt64

Defined in

lib/int.ts:193


not

not(): UInt64

Bitwise NOT gate on Field elements. Similar to the [bitwise NOT ~ operator in JavaScript](https://developer.mozilla.org/en-US/docs/ Web/JavaScript/Reference/Operators/Bitwise_NOT).

Note: The NOT gate operates over 64 bit for UInt64 types.

A NOT gate works by returning 1 in each bit position if the corresponding bit of the operand is 0, and returning 0 if the corresponding bit of the operand is 1.

NOT is implemented as a subtraction of the input from the all one bitmask

You can find more details about the implementation in the Mina book

Returns

UInt64

Example

// NOTing 4 bits with the unchecked version
let a = UInt64.from(0b0101);
let b = a.not(false);

console.log(b.toBigInt().toString(2));
// 1111111111111111111111111111111111111111111111111111111111111010

Defined in

lib/int.ts:269


rightShift

rightShift(bits): UInt64

Performs a left right operation on the provided UInt64 element. This operation is similar to the >> shift operation in JavaScript, where bits are shifted to the right, and the overflowing bits are discarded.

It’s important to note that these operations are performed considering the big-endian 64-bit representation of the number, where the most significant (64th) bit is on the left end and the least significant bit is on the right end.

Parameters

NameTypeDescription
bitsnumberAmount of bits to shift the UInt64 element to the right. The amount should be between 0 and 64 (or else the shift will fail).

Returns

UInt64

Example

const x = UInt64.from(0b001100); // 12 in binary
const y = x.rightShift(2); // left shift by 2 bits
y.assertEquals(0b000011); // 48 in binary

Defined in

lib/int.ts:343


rotate

rotate(bits, direction?): UInt64

A (left and right) rotation operates similarly to the shift operation (<< for left and >> for right) in JavaScript, with the distinction that the bits are circulated to the opposite end of a 64-bit representation rather than being discarded. For a left rotation, this means that bits shifted off the left end reappear at the right end. Conversely, for a right rotation, bits shifted off the right end reappear at the left end.

It’s important to note that these operations are performed considering the big-endian 64-bit representation of the number, where the most significant (64th) bit is on the left end and the least significant bit is on the right end. The direction parameter is a string that accepts either 'left' or 'right', determining the direction of the rotation.

To safely use rotate(), you need to make sure that the value passed in is range-checked to 64 bits; for example, using rangeCheck64.

You can find more details about the implementation in the Mina book

Parameters

NameTypeDefault valueDescription
bitsnumberundefinedamount of bits to rotate this UInt64 element with.
direction"left" | "right"'left'left or right rotation direction.

Returns

UInt64

Example

const x = UInt64.from(0b001100);
const y = x.rotate(2, 'left');
const z = x.rotate(2, 'right'); // right rotation by 2 bits
y.assertEquals(0b110000);
z.assertEquals(0b000011);

Defined in

lib/int.ts:301


sub

sub(y): UInt64

Subtraction with underflow checking.

Parameters

NameType
ynumber | UInt64

Returns

UInt64

Defined in

lib/int.ts:211


toBigInt

toBigInt(): bigint

Turns the UInt64 into a BigInt.

Returns

bigint

Defined in

lib/int.ts:51


toConstant

toConstant(): UInt64

Returns

UInt64

Inherited from

CircuitValue.toConstant

Defined in

lib/circuit-value.ts:159


toFields

toFields(): Field[]

Returns

Field[]

Inherited from

CircuitValue.toFields

Defined in

lib/circuit-value.ts:151


toJSON

toJSON(): any

Returns

any

Inherited from

CircuitValue.toJSON

Defined in

lib/circuit-value.ts:155


toString

toString(): string

Turns the UInt64 into a string.

Returns

string

Defined in

lib/int.ts:44


toUInt32

toUInt32(): UInt32

Turns the UInt64 into a UInt32, asserting that it fits in 32 bits.

Returns

UInt32

Defined in

lib/int.ts:58


toUInt32Clamped

toUInt32Clamped(): UInt32

Turns the UInt64 into a UInt32, clamping to the 32 bits range if it's too large.

UInt64.from(4294967296).toUInt32Clamped().toString(); // "4294967295"

Returns

UInt32

Defined in

lib/int.ts:70


xor

xor(x): UInt64

Bitwise XOR gadget on Field elements. Equivalent to the bitwise XOR ^ operator in JavaScript. A XOR gate works by comparing two bits and returning 1 if two bits differ, and 0 if two bits are equal.

This gadget builds a chain of XOR gates recursively.

You can find more details about the implementation in the Mina book

Parameters

NameTypeDescription
xUInt64UInt64 element to XOR.

Returns

UInt64

Example

let a = UInt64.from(0b0101);
let b = UInt64.from(0b0011);

let c = a.xor(b);
c.assertEquals(0b0110);

Defined in

lib/int.ts:236


MAXINT

Static MAXINT(): UInt64

Creates a UInt64 with a value of 18,446,744,073,709,551,615.

Returns

UInt64

Defined in

lib/int.ts:124


check

Static check(x): void

Parameters

NameType
xUInt64

Returns

void

Overrides

CircuitValue.check

Defined in

lib/int.ts:79


checkConstant

Static Private checkConstant(x): Field

Parameters

NameType
xField

Returns

Field

Defined in

lib/int.ts:101


empty

Static empty\<T>(): InstanceType\<T>

Type parameters

NameType
Textends AnyConstructor

Returns

InstanceType\<T>

Inherited from

CircuitValue.empty

Defined in

lib/circuit-value.ts:255


from

Static from(x): UInt64

Creates a new UInt64.

Parameters

NameType
xstring | number | bigint | Field | UInt64 | UInt32

Returns

UInt64

Defined in

lib/int.ts:116


fromFields

Static fromFields\<T>(this, xs): InstanceType\<T>

Type parameters

NameType
Textends AnyConstructor

Parameters

NameType
thisT
xsField[]

Returns

InstanceType\<T>

Inherited from

CircuitValue.fromFields

Defined in

lib/circuit-value.ts:175


fromJSON

Static fromJSON\<T>(x): InstanceType\<T>

Decodes a JSON-like object into this structure.

Type parameters

NameType
Textends AnyConstructor

Parameters

NameType
xstring

Returns

InstanceType\<T>

Overrides

CircuitValue.fromJSON

Defined in

lib/int.ts:97


fromObject

Static fromObject\<T>(this, value): InstanceType\<T>

Type parameters

NameType
Textends AnyConstructor

Parameters

NameType
thisT
valueNonMethods\<InstanceType\<T>>

Returns

InstanceType\<T>

Inherited from

CircuitValue.fromObject

Defined in

lib/circuit-value.ts:96


sizeInFields

Static sizeInFields(): number

Returns

number

Inherited from

CircuitValue.sizeInFields

Defined in

lib/circuit-value.ts:103


toAuxiliary

Static toAuxiliary(): []

Returns

[]

Inherited from

CircuitValue.toAuxiliary

Defined in

lib/circuit-value.ts:125


toConstant

Static toConstant\<T>(this, t): InstanceType\<T>

Type parameters

NameType
Textends AnyConstructor

Parameters

NameType
thisT
tInstanceType\<T>

Returns

InstanceType\<T>

Inherited from

CircuitValue.toConstant

Defined in

lib/circuit-value.ts:214


toFields

Static toFields\<T>(this, v): Field[]

Type parameters

NameType
Textends AnyConstructor

Parameters

NameType
thisT
vInstanceType\<T>

Returns

Field[]

Inherited from

CircuitValue.toFields

Defined in

lib/circuit-value.ts:108


toInput

Static toInput(x): HashInput

Parameters

NameType
xUInt64

Returns

HashInput

Overrides

CircuitValue.toInput

Defined in

lib/int.ts:83


toJSON

Static toJSON(x): string

Encodes this structure into a JSON-like object.

Parameters

NameType
xUInt64

Returns

string

Overrides

CircuitValue.toJSON

Defined in

lib/int.ts:90