UInt32
Class: UInt32
A 32 bit unsigned integer with values ranging from 0 to 4,294,967,295.
Hierarchy
↳
UInt32
Table of contents
Constructors
Properties
Accessors
Methods
- add
- addMod32
- and
- assertEquals
- assertGreaterThan
- assertGreaterThanOrEqual
- assertGt
- assertGte
- assertLessThan
- assertLessThanOrEqual
- assertLt
- assertLte
- div
- divMod
- equals
- greaterThan
- greaterThanOrEqual
- gt
- gte
- isConstant
- leftShift
- lessThan
- lessThanOrEqual
- lt
- lte
- mod
- mul
- not
- rightShift
- rotate
- sub
- toBigint
- toConstant
- toFields
- toJSON
- toString
- toUInt64
- xor
- MAXINT
- check
- checkConstant
- empty
- from
- fromFields
- fromJSON
- fromObject
- sizeInFields
- toAuxiliary
- toConstant
- toFields
- toInput
- toJSON
Constructors
constructor
• new UInt32(x
)
Parameters
Name | Type |
---|---|
x | string | number | bigint | Field | UInt32 |
Overrides
Defined in
Properties
value
• value: Field
Defined in
NUM_BITS
▪ Static
NUM_BITS: number
= 32
Defined in
Accessors
one
• Static
get
one(): UInt32
Static method to create a UInt32 with value 0
.
Returns
Defined in
zero
• Static
get
zero(): UInt32
Static method to create a UInt32 with value 0
.
Returns
Defined in
Methods
add
▸ add(y
): UInt32
Addition with overflow checking.
Parameters
Name | Type |
---|---|
y | number | UInt32 |
Returns
Defined in
addMod32
▸ addMod32(y
): UInt32
Addition modulo 2^32. Check addMod32 for a detailed description.
Parameters
Name | Type |
---|---|
y | UInt32 |
Returns
Defined in
and
▸ and(x
): UInt32
Bitwise AND gadget on UInt32 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
Name | Type |
---|---|
x | UInt32 |
Returns
Example
let a = UInt32.from(3); // ... 000011
let b = UInt32.from(5); // ... 000101
let c = a.and(b, 2); // ... 000001
c.assertEquals(1);
Defined in
assertEquals
▸ assertEquals(x
): void
Parameters
Name | Type |
---|---|
x | UInt32 |
Returns
void
Inherited from
Defined in
assertGreaterThan
▸ assertGreaterThan(y
, message?
): void
Asserts that a UInt32 is greater than another one.
Parameters
Name | Type |
---|---|
y | UInt32 |
message? | string |
Returns
void
Defined in
assertGreaterThanOrEqual
▸ assertGreaterThanOrEqual(y
, message?
): void
Asserts that a UInt32 is greater than or equal to another one.
Parameters
Name | Type |
---|---|
y | UInt32 |
message? | string |
Returns
void
Defined in
assertGt
▸ assertGt(y
, message?
): void
Parameters
Name | Type |
---|---|
y | UInt32 |
message? | string |
Returns
void
Deprecated
Use assertGreaterThan instead.
Asserts that a UInt32 is greater than another one.
Defined in
assertGte
▸ assertGte(y
, message?
): void
Parameters
Name | Type |
---|---|
y | UInt32 |
message? | string |
Returns
void
Deprecated
Use assertGreaterThanOrEqual instead.
Asserts that a UInt32 is greater than or equal to another one.
Defined in
assertLessThan
▸ assertLessThan(y
, message?
): void
Asserts that a UInt32 is less than another one.
Parameters
Name | Type |
---|---|
y | UInt32 |
message? | string |
Returns
void
Defined in
assertLessThanOrEqual
▸ assertLessThanOrEqual(y
, message?
): void
Asserts that a UInt32 is less than or equal to another one.
Parameters
Name | Type |
---|---|
y | UInt32 |
message? | string |
Returns
void
Defined in
assertLt
▸ assertLt(y
, message?
): void
Parameters
Name | Type |
---|---|
y | UInt32 |
message? | string |
Returns
void
Deprecated
Use assertLessThan instead.
Asserts that a UInt32 is less than another one.
Defined in
assertLte
▸ assertLte(y
, message?
): void
Parameters
Name | Type |
---|---|
y | UInt32 |
message? | string |
Returns
void
Deprecated
Use assertLessThanOrEqual instead.
Asserts that a UInt32 is less than or equal to another one.
Defined in
div
▸ div(y
): UInt32
Integer division.
x.div(y)
returns the floor of x / y
, that is, the greatest
z
such that x * y <= x
.
Parameters
Name | Type |
---|---|
y | number | UInt32 |
Returns
Defined in
divMod
▸ divMod(y
): Object
Integer division with remainder.
x.divMod(y)
returns the quotient and the remainder.
Parameters
Name | Type |
---|---|
y | string | number | UInt32 |
Returns
Object
Name | Type |
---|---|
quotient | UInt32 |
rest | UInt32 |
Defined in
equals
▸ equals(x
): Bool
Parameters
Name | Type |
---|---|
x | UInt32 |
Returns
Inherited from
Defined in
greaterThan
▸ greaterThan(y
): Bool
Checks if a UInt32 is greater than another one.
Parameters
Name | Type |
---|---|
y | UInt32 |
Returns
Defined in
greaterThanOrEqual
▸ greaterThanOrEqual(y
): Bool
Checks if a UInt32 is greater than or equal to another one.
Parameters
Name | Type |
---|---|
y | UInt32 |
Returns
Defined in
gt
▸ gt(y
): Bool
Parameters
Name | Type |
---|---|
y | UInt32 |
Returns
Deprecated
Use greaterThan instead.
Checks if a UInt32 is greater than another one.
Defined in
gte
▸ gte(y
): Bool
Parameters
Name | Type |
---|---|
y | UInt32 |
Returns
Deprecated
Use greaterThanOrEqual instead.
Checks if a UInt32 is greater than or equal to another one.
Defined in
isConstant
▸ isConstant(): boolean
Returns
boolean
Inherited from
Defined in
leftShift
▸ leftShift(bits
): UInt32
Performs a left shift operation on the provided UInt32 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 32-bit representation of the number, where the most significant (32th) bit is on the left end and the least significant bit is on the right end.
The operation expects the input to be range checked to 32 bit.
Parameters
Name | Type | Description |
---|---|---|
bits | number | Amount of bits to shift the UInt32 element to the left. The amount should be between 0 and 32 (or else the shift will fail). |
Returns
Example
const x = UInt32.from(0b001100); // 12 in binary
const y = x.leftShift(2); // left shift by 2 bits
y.assertEquals(0b110000); // 48 in binary
Defined in
lessThan
▸ lessThan(y
): Bool
Checks if a UInt32 is less than another one.
Parameters
Name | Type |
---|---|
y | UInt32 |
Returns
Defined in
lessThanOrEqual
▸ lessThanOrEqual(y
): Bool
Checks if a UInt32 is less than or equal to another one.
Parameters
Name | Type |
---|---|
y | UInt32 |
Returns
Defined in
lt
▸ lt(y
): Bool
Parameters
Name | Type |
---|---|
y | UInt32 |
Returns
Deprecated
Use lessThan instead.
Checks if a UInt32 is less than another one.
Defined in
lte
▸ lte(y
): Bool
Parameters
Name | Type |
---|---|
y | UInt32 |
Returns
Deprecated
Use lessThanOrEqual instead.
Checks if a UInt32 is less than or equal to another one.
Defined in
mod
▸ mod(y
): UInt32
Integer remainder.
x.mod(y)
returns the value z
such that 0 <= z < y
and
x - z
is divisible by y
.
Parameters
Name | Type |
---|---|
y | number | UInt32 |
Returns
Defined in
mul
▸ mul(y
): UInt32
Multiplication with overflow checking.
Parameters
Name | Type |
---|---|
y | number | UInt32 |
Returns
Defined in
not
▸ not(): UInt32
Bitwise NOT gate on UInt32 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 32 bit for UInt32 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
Example
// NOTing 4 bits with the unchecked version
let a = UInt32.from(0b0101);
let b = a.not();
console.log(b.toBigInt().toString(2));
// 11111111111111111111111111111010
Defined in
rightShift
▸ rightShift(bits
): UInt32
Performs a left right operation on the provided UInt32 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 32-bit representation of the number, where the most significant (32th) bit is on the left end and the least significant bit is on the right end.
Parameters
Name | Type | Description |
---|---|---|
bits | number | Amount of bits to shift the UInt32 element to the right. The amount should be between 0 and 32 (or else the shift will fail). The operation expects the input to be range checked to 32 bit. |
Returns
Example
const x = UInt32.from(0b001100); // 12 in binary
const y = x.rightShift(2); // left shift by 2 bits
y.assertEquals(0b000011); // 48 in binary
Defined in
rotate
▸ rotate(bits
, direction?
): UInt32
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
Name | Type | Default value | Description |
---|---|---|---|
bits | number | undefined | amount of bits to rotate this UInt32 element with. |
direction | "left" | "right" | 'left' | left or right rotation direction. |
Returns
Example
const x = UInt32.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
sub
▸ sub(y
): UInt32
Subtraction with underflow checking.
Parameters
Name | Type |
---|---|
y | number | UInt32 |
Returns
Defined in
toBigint
▸ toBigint(): bigint
Turns the UInt32 into a BigInt.
Returns
bigint
Defined in
toConstant
▸ toConstant(): UInt32
Returns
Inherited from
Defined in
toFields
▸ toFields(): Field
[]
Returns
Field
[]
Inherited from
Defined in
toJSON
▸ toJSON(): any
Returns
any
Inherited from
Defined in
toString
▸ toString(): string
Turns the UInt32 into a string.
Returns
string
Defined in
toUInt64
▸ toUInt64(): UInt64
Turns the UInt32 into a UInt64.
Returns
Defined in
xor
▸ xor(x
): UInt32
Bitwise XOR gadget on UInt32 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
Name | Type | Description |
---|---|---|
x | UInt32 | UInt32 element to compare. |
Returns
Example
let a = UInt32.from(0b0101);
let b = UInt32.from(0b0011);
let c = a.xor(b);
c.assertEquals(0b0110);
Defined in
MAXINT
▸ Static
MAXINT(): UInt32
Creates a UInt32 with a value of 4,294,967,295.
Returns
Defined in
check
▸ Static
check(x
): void
Parameters
Name | Type |
---|---|
x | UInt32 |
Returns
void
Overrides
Defined in
checkConstant
▸ Static
Private
checkConstant(x
): Field
Parameters
Name | Type |
---|---|
x | Field |
Returns
Defined in
empty
▸ Static
empty\<T
>(): InstanceType
\<T
>
Type parameters
Name | Type |
---|---|
T | extends AnyConstructor |
Returns
InstanceType
\<T
>
Inherited from
Defined in
from
▸ Static
from(x
): UInt32
Creates a new UInt32.
Parameters
Name | Type |
---|---|
x | string | number | bigint | Field | UInt32 |
Returns
Defined in
fromFields
▸ Static
fromFields\<T
>(this
, xs
): InstanceType
\<T
>
Type parameters
Name | Type |
---|---|
T | extends AnyConstructor |
Parameters
Name | Type |
---|---|
this | T |
xs | Field [] |
Returns
InstanceType
\<T
>
Inherited from
Defined in
fromJSON
▸ Static
fromJSON\<T
>(x
): InstanceType
\<T
>
Decodes a JSON-like object into this structure.
Type parameters
Name | Type |
---|---|
T | extends AnyConstructor |
Parameters
Name | Type |
---|---|
x | string |
Returns
InstanceType
\<T
>
Overrides
Defined in
fromObject
▸ Static
fromObject\<T
>(this
, value
): InstanceType
\<T
>
Type parameters
Name | Type |
---|---|
T | extends AnyConstructor |
Parameters
Name | Type |
---|---|
this | T |
value | NonMethods \<InstanceType \<T >> |
Returns
InstanceType
\<T
>
Inherited from
Defined in
sizeInFields
▸ Static
sizeInFields(): number
Returns
number
Inherited from
Defined in
toAuxiliary
▸ Static
toAuxiliary(): []
Returns
[]
Inherited from
Defined in
toConstant
▸ Static
toConstant\<T
>(this
, t
): InstanceType
\<T
>
Type parameters
Name | Type |
---|---|
T | extends AnyConstructor |
Parameters
Name | Type |
---|---|
this | T |
t | InstanceType \<T > |
Returns
InstanceType
\<T
>
Inherited from
Defined in
toFields
▸ Static
toFields\<T
>(this
, v
): Field
[]
Type parameters
Name | Type |
---|---|
T | extends AnyConstructor |
Parameters
Name | Type |
---|---|
this | T |
v | InstanceType \<T > |
Returns
Field
[]
Inherited from
Defined in
toInput
▸ Static
toInput(x
): HashInput
Parameters
Name | Type |
---|---|
x | UInt32 |
Returns
HashInput
Overrides
Defined in
toJSON
▸ Static
toJSON(x
): string
Encodes this structure into a JSON-like object.
Parameters
Name | Type |
---|---|
x | UInt32 |
Returns
string