Hello, friends.
Today I offer you to familiarize yourself with Leo Operators Reference. It seems to be a lot of information, but these examples are very easy to understand. In the future it will help you to write your own applications more easily.
You can read previous installments on Leo Language by clicking on the links below:
LEO Part 1
LEO Part 2
LEO Part 3
Leo Operators Reference
The following lists show the standard and cryptographic operators supported by Leo. The Leo operators compile down to Aleo instructions opcodes executable by the Aleo Virtual Machine (AVM).
Table of Standard Operators
Table of Cryptographic Operators
Specification
The following is the specification for each operator in the Leo compiler.
abs
let a: i8 = -1i8;
let b: i8 = a.abs(); // 1i8
Description
Computes the absolute value of the input, checking for overflow, storing the result in the destination.
For integer types, a constraint is added to check for underflow. For cases where wrapping semantics are needed, see the abs_wrapped instruction. This underflow happens when the input is the minimum value of a signed integer type. For example, abs -128i8
would result in underflow, since 128
cannot be represented as an i8
.
Supported Types
abs_wrapped
let a: i8 = -128i8;
let b: i8 = a.abs_wrapped(); // -128i8
Description
Compute the absolute value of the input, wrapping around at the boundary of the type, and storing the result in the destination.
Supported Types
add
let a: u8 = 1u8;
let b: u8 = a + 1u8; // 2u8
let c: u8 = b.add(1u8); // 3u8
Description
Adds first
with second
, storing the outcome in destination
.
For integer types, a constraint is added to check for overflow. For cases where wrapping semantics are needed for integer types, see the add_wrapped instruction.
Supported Types
assert
let a: bool = true;
let b: bool = false;
assert(a); // will not halt
assert(b); // program halts
Description
Checks whether the expression evaluates to a true
boolean value, halting if evaluates to false
.
Supported Types
assert_eq
let a: u8 = 1u8;
let b: u8 = 2u8;
assert_eq(a, a); // will not halt
assert_eq(a, b); // program halts
Description
Checks whether first
and second
are equal, halting if they are not equal.
Supported Types
assert_neq
let a: u8 = 1u8;
let b: u8 = 2u8;
assert_neq(a, b); // will not halt
assert_neq(a, a); // program halts
Description
Checks whether first
and second
are not equal, halting if they are equal.
Supported Types
block.height
transition matches(height: u32) {
return then finalize(height);
}
finalize matches(height: u32) {
assert_eq(height, block.height);
}
Description
The block.height
operator is used to fetch the latest block height in a Leo program. It represents the number of blocks in the chain. In the above example, block.height
is used in a finalize
context to fetch the latest block height in a program.
Note:
- The
block.height
operator can only be used in afinalize
context. Using it outside afinalize
context will result in a compilation error. - The
block.height
operator doesn't take any parameters.
div
let a: u8 = 4u8;
let b: u8 = a / 2u8; // 2u8
let c: u8 = b.div(2u8); // 1u8
Description
Performs division of the first operand by the second, storing the result in the destination. The operation halts if division by zero is attempted.
For integer types, this operation performs truncated division. Truncated division rounds towards zero, regardless of the sign of the operands. This means it cuts off any digits after the decimal, leaving the largest whole number less than or equal to the result.
For example:
7 / 3
yields2
, not2.3333
.-7 / 3
yields-2
, not-2.3333
.
The operation halts if there is an underflow. Underflow occurs when dividing the minimum value of a signed integer type by -1. For example, -128i8 / -1i8
would result in underflow, since 128 cannot be represented as an i8
.
For field types, division a / b
is well-defined for any field values a
and b
except when b = 0field
.
For cases where wrapping semantics are needed for integer types, see the div_wrapped instruction.
Supported Types
div_wrapped
let a: i8 = -128i8;
let b: i8 = a.div_wrapped(-1i8); // -128i8
Description
Divides first
by second
, wrapping around at the boundary of the type, and storing the outcome in destination
.
Supported Types
double
let a: group = (0, 4)group;
let b: group = a.double();
Description
Doubles the input, storing the outcome in destination
.
Supported Types
gt
let a: bool = 2u8 > 1u8; // true
let b: bool = 1u8.gt(1u8); // false
Description
Checks if first
is greater than second
, storing the result in destination
.
Supported Types
gte
let a: bool = 2u8 >= 1u8; // true
let b: bool = 1u8.gte(1u8); // true
Description
Checks if first
is greater than or equal to second
, storing the result in destination
.
Supported Types
inv
let a: field = 1field.inv();
Description
Computes the multiplicative inverse of the input, storing the outcome in destination
.
Supported Types
eq
let a: bool = 1u8 == 1u8; // true
let b: bool = 1u8.eq(2u8); // false
Description
Compares first
and second
, storing the result in destination
.
Supported Types
neq
let a: bool = 1u8 != 1u8; // false
let b: bool = 1u8.neq(2u8); // true
Description
Returns true if first
is not equal to second
, storing the result in destination
.
Supported Types
lt
let a: bool = 1u8 < 2u8; // true
let b: bool = 1u8.lt(1u8); // false
Description
Checks if first
is less than second
, storing the outcome in destination
.
Supported Types
lte
let a: bool = 1u8 <= 2u8; // true
let b: bool = 1u8.lte(1u8); // true
Description
Checks if first
is less than or equal to second
, storing the outcome in destination
.
Supported Types
mod
let a: u8 = 3u8.mod(2u8); // 1u8
Description
Takes the modulus of first
with respect to second
, storing the outcome in destination
. Halts if second
is zero.
The semantics of this operation are consistent with the mathematical definition of modulo operation.
Supported Types
mul
let a: u8 = 2u8 * 2u8; // 4u8
let b: u8 = a.mul(2u8); // 8u8
Description
Multiplies first
with second
, storing the outcome in destination
.
For integer types, a constraint is added to check for overflow/underflow. For cases where wrapping semantics are needed for integer types, see the mul_wrapped instruction.
Supported Types
mul_wrapped
let a: u8 = 128u8.mul_wrapped(2u8); // 0u8
Description
Multiplies first
with second
, wrapping around at the boundary of the type, and storing the outcome in destination
.
Supported Types
nand
let a: bool = true.nand(false); // true
Description
Returns false only if first
and second
are true, storing the outcome in destination
.
Supported Types
neg
let a: i8 = -1i8.neg(); // 1i8
Description
Negates first
, storing the outcome in destination
.
For signed integer types, calling neg
on the minimum value is an invalid operation. For example, the input -128i8
would not be valid since 128
cannot be represented as an i8
.
Supported Types
nor
let a: bool = false.nor(false); // true
Description
Returns true when neither first
nor second
is true, storing the outcome in destination
.
Supported Type
not
let a: bool = true.not(); // false
Description
Perform a NOT operation on an integer (bitwise) or boolean input, storing the outcome in destination
.
Supported Types
or
let a: bool = true || false; // true
let b: bool = false.or(false); // false
Description
Performs an OR operation on integer (bitwise) or boolean first
and second
, storing the outcome in destination
.
Supported Types
pow
let a: u8 = 2u8 ** 2u8; // 4u8
let b: u8 = a.pow(2u8); // 16u8
Description
Raises first
to the power of second
, storing the outcome in destination
.
For integer types, a constraint is added to check for overflow/underflow. For cases where wrapping semantics are needed for integer types, see the pow_wrapped instruction.
Supported Types
Magnitude
can be a U8
, U16
, or U32
.
pow_wrapped
let a: u8 = 16u8.pow_wrapped(2u8); // 0u8
Description
Raises first
to the power of second
, wrapping around at the boundary of the type, storing the outcome in destination
.
Supported Types
Magnitude
can be a U8
, U16
, or U32
.
rem
let a: u8 = 3u8 % 2u8; // 1u8
let b: u8 = 4u8.rem(2u8); // 0u8
Description
Computes the truncated remainder of first
divided by second
, storing the outcome in destination
. Halts on division by zero.
A constraint is added to check for underflow. This underflow happens when the associated division operation, div, underflows.
For cases where wrapping semantics are needed for integer types, see the rem_wrapped instruction.
Supported Types
rem_wrapped
let a: i8 = -128i8;
let b: i8 = a.rem_wrapped(-1i8); // 0i8
Description
Computes the truncated remainder of first
divided by second
, wrapping around at the boundary of the type, and storing the outcome in destination.
Supported Types
shl
let a: u8 = 1u8 << 1u8; // 2u8
let b: u8 = a.shl(1u8); // 4u8
Description
Shifts first
left by second
bits, storing the outcome in destination
.
Supported Types
Magnitude
can be a U8
, U16
, or U32
.
shl_wrapped
let a: u8 = 128u8.shl_wrapped(1u8); // 0u8
Description
Shifts first
left by second
bits, wrapping around at the boundary of the type, storing the outcome in destination
.
Supported Types
Magnitude
can be a U8
, U16
, or U32
.
shr
let a: u8 = 4u8 >> 1u8; // 2u8
let b: u8 = a.shr(1u8); // 1u8
Description
Shifts first
right by second
bits, storing the outcome in destination
.
Supported Types
Magnitude
can be a U8
, U16
, or U32
.
shr_wrapped
let a: u8 = 128u8.shr_wrapped(7u8); // 1u8
Description
Shifts first
right by second
bits, wrapping around at the boundary of the type, storing the outcome in destination
.
Supported Types
Magnitude
can be a U8
, U16
, or U32
.
square
let a: field = 1field.square(); // 1field
Description
Squares the input, storing the outcome in destination
.
Supported Types
square_root
let a: field = 1field.square_root(); // 1field
Description
Computes the square root of the input, storing the outcome in destination
.
Supported Types
sub
let a: u8 = 2u8 - 1u8; // 1u8
let b: u8 = a.sub(1u8); // 0u8
Description
Computes first - second
, storing the outcome in destination
.
Supported Types
sub_wrapped
let a: u8 = 0u8.sub_wrapped(1u8); // 255u8
Description
Computes first - second
, wrapping around at the boundary of the type, and storing the outcome in destination
.
Supported Types
ternary
let a: u8 = true ? 1u8 : 2u8; // 1u8
Description
Selects first
, if condition
is true, otherwise selects second
, storing the result in destination
.
Supported Types
xor
let a: bool = true.xor(false); // true
Description
Performs a XOR operation on integer (bitwise) or boolean first
and second
, storing the outcome in destination
.
Supported Types
group::GEN
let g: group = group::GEN; // the group generator
Description
Returns the generator of the algebraic group that the group
type consists of.
The compilation of Leo is based on an elliptic curve, whose points form a group, and on a specified point on that curve, which generarates a subgroup, whose elements form the type group
.
This is a constant, not a function. Thus, it takes no inputs, and just returns an output.
It is an associated constant, whose name is GEN
and whose associated type is group
.
Supported Types
ChaCha::rand_DESTINATION
let result: address = ChaCha::rand_address();
let result: bool = ChaCha::rand_bool();
let result: field = ChaCha::rand_field();
let result: group = ChaCha::rand_group();
let result: i8 = ChaCha::rand_i8();
let result: i16 = ChaCha::rand_i16();
let result: i32 = ChaCha::rand_i32();
let result: i64 = ChaCha::rand_i64();
let result: i128 = ChaCha::rand_i128();
let result: u8 = ChaCha::rand_u8();
let result: u16 = ChaCha::rand_u16();
let result: u32 = ChaCha::rand_u32();
let result: u64 = ChaCha::rand_u64();
let result: u128 = ChaCha::rand_u128();
let result: scalar = ChaCha::rand_scalar();
Description
Returns a random value with the destination type. Must be used in a finalize context
Supported Types
BHP256::commit_to_DESTINATION
let salt: scalar = ChaCha::rand_scalar();
let a: address = BHP256::commit_to_address(1u8, salt);
let b: field = BHP256::commit_to_field(2i64, salt);
let c: group = BHP256::commit_to_group(1field, salt);
Description
Computes a Bowe-Hopwood-Pedersen commitment on inputs of 256-bit chunks in first
, and some randomness in second
, storing the commitment in destination
. Randomness should always be a Scalar
value, and the produced commitment can be an Address
, Field
or, Group
value.
The instruction will halt if the given input is smaller than 129 bits.
Supported Types
BHP512::commit_to_DESTINATION
let salt: scalar = ChaCha::rand_scalar();
let a: address = BHP512::commit_to_address(1u8, salt);
let b: field = BHP512::commit_to_field(2i64, salt);
let c: group = BHP512::commit_to_group(1field, salt);
Description
Computes a Bowe-Hopwood-Pedersen commitment on inputs of 512-bit chunks in first
, and some randomness in second
, storing the commitment in destination
. Randomness should always be a Scalar
value, and the produced commitment will always be a Group
value.
The instruction will halt if the given input is smaller than 171 bits.
Supported Types
BHP768::commit_to_DESTINATION
let salt: scalar = ChaCha::rand_scalar();
let a: address = BHP768::commit_to_address(1u8, salt);
let b: field = BHP768::commit_to_field(2i64, salt);
let c: group = BHP768::commit_to_group(1field, salt);
Description
Computes a Bowe-Hopwood-Pedersen commitment on inputs of 768-bit chunks in first
, and some randomness in second
, storing the commitment in destination
. Randomness should always be a Scalar
value, and the produced commitment will always be a Group
value.
The instruction will halt if the given input is smaller than 129 bits.
Supported Types
BHP1024::commit_to_DESTINATION
let salt: scalar = ChaCha::rand_scalar();
let a: address = BHP1024::commit_to_address(1u8, salt);
let b: field = BHP1024::commit_to_field(2i64, salt);
let c: group = BHP1024::commit_to_group(1field, salt);
Description
Computes a Bowe-Hopwood-Pedersen commitment on inputs of 1024-bit chunks in first
, and some randomness in second
, storing the commitment in destination
. Randomness should always be a Scalar
value, and the produced commitment will always be a Group
value.
The instruction will halt if the given input is smaller than 171 bits.
Supported Types
Pedersen64::commit_to_DESTINATION
let salt: scalar = ChaCha::rand_scalar();
let a: address = Pedersen64::commit_to_address(1u8, salt);
let b: field = Pedersen64::commit_to_field(2i64, salt);
let c: group = Pedersen64::commit_to_group(1field, salt);
Description
Computes a Pedersen commitment up to a 64-bit input in first
, and some randomness in second
, storing the commitment in destination
. Randomness should always be a Scalar
value, and the produced commitment will always be a Group
value.
The instruction will halt if the given Struct
value exceeds the 64-bit limit.
Supported Types
Pedersen128::commit_to_DESTINATION
let salt: scalar = ChaCha::rand_scalar();
let a: address = Pedersen64::commit_to_address(1u8, salt);
let b: field = Pedersen64::commit_to_field(2i64, salt);
let c: group = Pedersen64::commit_to_group(1field, salt);
Description
Computes a Pedersen commitment up to a 128-bit input in first
, and some randomness in second
, storing the commitment in destination
. Randomness should always be a Scalar
value, and the produced commitment will always be a Group
value.
The instruction will halt if the given Struct
value exceeds the 128-bit limit.
Supported Types
BHP256::hash_to_DESTINATION
let result: address = BHP256::hash_to_address(1u8);
let result: field = BHP256::hash_to_field(2i64);
let result: group = BHP256::hash_to_group(1field);
let result: scalar = BHP256::hash_to_scalar(1field);
let result: i8 = BHP256::hash_to_i8(1field);
let result: i16 = BHP256::hash_to_i16(1field);
let result: i32 = BHP256::hash_to_i32(1field);
let result: i64 = BHP256::hash_to_i64(1field);
let result: i128 = BHP256::hash_to_i128(1field);
let result: u8 = BHP256::hash_to_u8(1field);
let result: u16 = BHP256::hash_to_u16(1field);
let result: u32 = BHP256::hash_to_u32(1field);
let result: u64 = BHP256::hash_to_u64(1field);
let result: u128 = BHP256::hash_to_u128(1field);
Description
Computes a Bowe-Hopwood-Pedersen hash on inputs of 256-bit chunks in first
, storing the hash in destination
. The produced hash will always be an arithmetic (U8
, U16
, U32
, U64
, U128
, I8
, I16
, I32
,I64
,I128
, Field
, Group
, or Scalar
) or Address
value, as specified via hash_to_DESTINATION
at the end of the function.
The instruction will halt if the given input is smaller than 129 bits.
Supported Types
BHP512::hash_to_DESTINATION
let result: address = BHP512::hash_to_address(1u8);
let result: field = BHP512::hash_to_field(2i64);
let result: group = BHP512::hash_to_group(1field);
let result: scalar = BHP512::hash_to_scalar(1field);
let result: i8 = BHP512::hash_to_i8(1field);
let result: i16 = BHP512::hash_to_i16(1field);
let result: i32 = BHP512::hash_to_i32(1field);
let result: i64 = BHP512::hash_to_i64(1field);
let result: i128 = BHP512::hash_to_i128(1field);
let result: u8 = BHP512::hash_to_u8(1field);
let result: u16 = BHP512::hash_to_u16(1field);
let result: u32 = BHP512::hash_to_u32(1field);
let result: u64 = BHP512::hash_to_u64(1field);
let result: u128 = BHP512::hash_to_u128(1field);
Description
Computes a Bowe-Hopwood-Pedersen hash on inputs of 512-bit chunks in first
, storing the hash in destination
. The produced hash will always be an arithmetic (U8
, U16
, U32
, U64
, U128
, I8
, I16
, I32
,I64
,I128
, Field
, Group
, or Scalar
) or Address
value, as specified via hash_to_DESTINATION
at the end of the function.
The instruction will halt if the given input is smaller than 171 bits.
Supported Types
BHP768::hash_to_DESTINATION
let result: address = BHP768::hash_to_address(1u8);
let result: field = BHP768::hash_to_field(2i64);
let result: group = BHP768::hash_to_group(1field);
let result: scalar = BHP768::hash_to_scalar(1field);
let result: i8 = BHP768::hash_to_i8(1field);
let result: i16 = BHP768::hash_to_i16(1field);
let result: i32 = BHP768::hash_to_i32(1field);
let result: i64 = BHP768::hash_to_i64(1field);
let result: i128 = BHP768::hash_to_i128(1field);
let result: u8 = BHP768::hash_to_u8(1field);
let result: u16 = BHP768::hash_to_u16(1field);
let result: u32 = BHP768::hash_to_u32(1field);
let result: u64 = BHP768::hash_to_u64(1field);
let result: u128 = BHP768::hash_to_u128(1field);
Description
Computes a Bowe-Hopwood-Pedersen hash on inputs of 768-bit chunks in first
, storing the hash in destination
. The produced hash will always be an arithmetic (U8
, U16
, U32
, U64
, U128
, I8
, I16
, I32
,I64
,I128
, Field
, Group
, or Scalar
) or Address
value, as specified via hash_to_DESTINATION
at the end of the function.
The instruction will halt if the given input is smaller than 129 bits.
Supported Types
BHP1024::hash_to_DESTINATION
let result: address = BHP1024::hash_to_address(1u8);
let result: field = BHP1024::hash_to_field(2i64);
let result: group = BHP1024::hash_to_group(1field);
let result: scalar = BHP1024::hash_to_scalar(1field);
let result: i8 = BHP1024::hash_to_i8(1field);
let result: i16 = BHP1024::hash_to_i16(1field);
let result: i32 = BHP1024::hash_to_i32(1field);
let result: i64 = BHP1024::hash_to_i64(1field);
let result: i128 = BHP1024::hash_to_i128(1field);
let result: u8 = BHP1024::hash_to_u8(1field);
let result: u16 = BHP1024::hash_to_u16(1field);
let result: u32 = BHP1024::hash_to_u32(1field);
let result: u64 = BHP1024::hash_to_u64(1field);
let result: u128 = BHP1024::hash_to_u128(1field);
Description
Computes a Bowe-Hopwood-Pedersen hash on inputs of 1024-bit chunks in first
, storing the hash in destination
. The produced hash will always be an arithmetic (U8
, U16
, U32
, U64
, U128
, I8
, I16
, I32
,I64
,I128
, Field
, Group
, or Scalar
) or Address
value, as specified via hash_to_DESTINATION
at the end of the function.
The instruction will halt if the given input is smaller than 171 bits.
Supported Types
Pedersen64::hash_to_DESTINATION
let result: address = Pedersen64::hash_to_address(1u8);
let result: field = Pedersen64::hash_to_field(2i64);
let result: group = Pedersen64::hash_to_group(1field);
let result: scalar = Pedersen64::hash_to_scalar(1field);
let result: i8 = Pedersen64::hash_to_i8(1field);
let result: i16 = Pedersen64::hash_to_i16(1field);
let result: i32 = Pedersen64::hash_to_i32(1field);
let result: i64 = Pedersen64::hash_to_i64(1field);
let result: i128 = Pedersen64::hash_to_i128(1field);
let result: u8 = Pedersen64::hash_to_u8(1field);
let result: u16 = Pedersen64::hash_to_u16(1field);
let result: u32 = Pedersen64::hash_to_u32(1field);
let result: u64 = Pedersen64::hash_to_u64(1field);
let result: u128 = Pedersen64::hash_to_u128(1field);
Description
Computes a Pedersen hash up to a 64-bit input in first
, storing the hash in destination
. The produced hash will always be an arithmetic (U8
, U16
, U32
, U64
, U128
, I8
, I16
, I32
,I64
,I128
, Field
, Group
, or Scalar
) or Address
value, as specified via hash_to_DESTINATION
at the end of the function.
The instruction will halt if the given Struct
value exceeds the 64-bit limit.
Supported Types
Pedersen128::hash_to_DESTINATION
let result: address = Pedersen128::hash_to_address(1u8);
let result: field = Pedersen128::hash_to_field(2i64);
let result: group = Pedersen128::hash_to_group(1field);
let result: scalar = Pedersen128::hash_to_scalar(1field);
let result: i8 = Pedersen128::hash_to_i8(1field);
let result: i16 = Pedersen128::hash_to_i16(1field);
let result: i32 = Pedersen128::hash_to_i32(1field);
let result: i64 = Pedersen128::hash_to_i64(1field);
let result: i128 = Pedersen128::hash_to_i128(1field);
let result: u8 = Pedersen128::hash_to_u8(1field);
let result: u16 = Pedersen128::hash_to_u16(1field);
let result: u32 = Pedersen128::hash_to_u32(1field);
let result: u64 = Pedersen128::hash_to_u64(1field);
let result: u128 = Pedersen128::hash_to_u128(1field);
Description
Computes a Pedersen hash up to a 128-bit input in first
, storing the hash in destination
. The produced hash will always be an arithmetic (U8
, U16
, U32
, U64
, U128
, I8
, I16
, I32
,I64
,I128
, Field
, Group
, or Scalar
) or Address
value, as specified via hash_to_DESTINATION
at the end of the function.
The instruction will halt if the given Struct
value exceeds the 64-bit limit.
Supported Types
Poseidon2::hash_to_DESTINATION
let result: address = Poseidon2::hash_to_address(1u8);
let result: field = Poseidon2::hash_to_field(2i64);
let result: group = Poseidon2::hash_to_group(1field);
let result: scalar = Poseidon2::hash_to_scalar(1field);
let result: i8 = Poseidon2::hash_to_i8(1field);
let result: i16 = Poseidon2::hash_to_i16(1field);
let result: i32 = Poseidon2::hash_to_i32(1field);
let result: i64 = Poseidon2::hash_to_i64(1field);
let result: i128 = Poseidon2::hash_to_i128(1field);
let result: u8 = Poseidon2::hash_to_u8(1field);
let result: u16 = Poseidon2::hash_to_u16(1field);
let result: u32 = Poseidon2::hash_to_u32(1field);
let result: u64 = Poseidon2::hash_to_u64(1field);
let result: u128 = Poseidon2::hash_to_u128(1field);
Description
Calculates a Poseidon hash with an input rate of 2, from an input in first
, storing the hash in destination
. The produced hash will always be an arithmetic (U8
, U16
, U32
, U64
, U128
, I8
, I16
, I32
,I64
,I128
, Field
, Group
, or Scalar
) or Address
value, as specified via hash_to_DESTINATION
at the end of the function.
Supported Types
Poseidon4::hash_to_DESTINATION
let result: address = Poseidon4::hash_to_address(1u8);
let result: field = Poseidon4::hash_to_field(2i64);
let result: group = Poseidon4::hash_to_group(1field);
let result: scalar = Poseidon4::hash_to_scalar(1field);
let result: i8 = Poseidon4::hash_to_i8(1field);
let result: i16 = Poseidon4::hash_to_i16(1field);
let result: i32 = Poseidon4::hash_to_i32(1field);
let result: i64 = Poseidon4::hash_to_i64(1field);
let result: i128 = Poseidon4::hash_to_i128(1field);
let result: u8 = Poseidon4::hash_to_u8(1field);
let result: u16 = Poseidon4::hash_to_u16(1field);
let result: u32 = Poseidon4::hash_to_u32(1field);
let result: u64 = Poseidon4::hash_to_u64(1field);
let result: u128 = Poseidon4::hash_to_u128(1field);
Description
Calculates a Poseidon hash with an input rate of 4, from an input in first
, storing the hash in destination
. The produced hash will always be an arithmetic (U8
, U16
, U32
, U64
, U128
, I8
, I16
, I32
,I64
,I128
, Field
, Group
, or Scalar
) or Address
value, as specified via hash_to_DESTINATION
at the end of the function.
Supported Types
Poseidon8::hash_to_DESTINATION
let result: address = Poseidon8::hash_to_address(1u8);
let result: field = Poseidon8::hash_to_field(2i64);
let result: group = Poseidon8::hash_to_group(1field);
let result: scalar = Poseidon8::hash_to_scalar(1field);
let result: i8 = Poseidon8::hash_to_i8(1field);
let result: i16 = Poseidon8::hash_to_i16(1field);
let result: i32 = Poseidon8::hash_to_i32(1field);
let result: i64 = Poseidon8::hash_to_i64(1field);
let result: i128 = Poseidon8::hash_to_i128(1field);
let result: u8 = Poseidon8::hash_to_u8(1field);
let result: u16 = Poseidon8::hash_to_u16(1field);
let result: u32 = Poseidon8::hash_to_u32(1field);
let result: u64 = Poseidon8::hash_to_u64(1field);
let result: u128 = Poseidon8::hash_to_u128(1field);
Description
Calculates a Poseidon hash with an input rate of 8, from an input in first
, storing the hash in destination
. The produced hash will always be an arithmetic (U8
, U16
, U32
, U64
, U128
, I8
, I16
, I32
,I64
,I128
, Field
, Group
, or Scalar
) or Address
value, as specified via hash_to_DESTINATION
at the end of the function.
Supported Types
Thank you for reading this article to the end, and sign up for notifications.
See below for all the official links to Aleo:
Website — https://www.aleo.org/
Discord — https://discord.gg/aleohq
Twitter — https://twitter.com/AleoHQ
GitHub — https://github.com/AleoHQ