Hash methods
sha256
Given an array of bytes, returns the resulting sha256 hash.
fn sha256(_input : [u8]) -> [u8; 32]
example:
fn main() {
let x = [163, 117, 178, 149] // some random bytes
let hash = std::hash::sha256(x);
}
This is a black box function. Read this section to learn more about black box functions in Noir.
blake2s
Given an array of bytes, returns an array with the Blake2 hash
fn blake2s(_input : [u8]) -> [u8; 32]
example:
fn main() {
let x = [163, 117, 178, 149] // some random bytes
let hash = std::hash::blake2s(x);
}
This is a black box function. Read this section to learn more about black box functions in Noir.
pedersen
Given an array of Fields, returns the Pedersen hash.
fn pedersen(_input : [Field]) -> [Field; 2]
example:
fn main() {
let x = [163, 117, 178, 149] // some random bytes
let hash = std::hash::pedersen(x);
}
This is a black box function. Read this section to learn more about black box functions in Noir.
poseidon
Given an array of Fields, returns a new Field with the Poseidon Hash. Mind that you need to specify how many inputs are there to your Poseidon function.
// example for hash_1, hash_2 accepts an array of length 2, etc
fn hash_1(input: [Field; 1]) -> Field
example:
fn main()
{
let hash1 = std::hash::poseidon::bn254::hash_2([1, 2]);
constrain hash1 == 0x115cc0f5e7d690413df64c6b9662e9cf2a3617f2743245519e19607a4417189a;
}
mimc_bn254 and mimc
mimc_bn254
is mimc
, but with hardcoded parameters for the BN254 curve. You can use it by
providing an array of Fields, and it returns a Field with the hash. You can use the mimc
method if
you're willing to input your own constants:
fn mimc<N>(x: Field, k: Field, constants: [Field; N], exp : Field) -> Field
otherwise, use the mimc_bn254
method:
fn mimc_bn254<N>(array: [Field; N]) -> Field
example:
fn main() {
let x = [163, 117, 178, 149] // some random bytes
let hash = std::hash::mimc_bn254(x);
}
hash_to_field
fn hash_to_field<N>(_input : [Field; N]) -> Field {}
Calculates the blake2s
hash of the inputs and returns the hash modulo the field modulus to return a value which can be represented as a Field
.
This is a black box function. Read this section to learn more about black box functions in Noir.