Reference implementation for the Poseidon Hashing algorithm.
Starkad and Poseidon: New Hash Functions for Zero Knowledge Proof Systems
This repository has been created so there's a unique library that holds the tools & functions required to perform Poseidon Hashes.
This hashes heavily rely on the Hades permutation, which is one of the key parts that Poseidon needs in order to work. This library uses the reference implementation of Dusk-Hades which has been designed & build by the Dusk-Network team.
The library provides the two hashing techniques of Poseidon:
The Sponge
technique in Poseidon allows to hash an unlimited amount of data
into a single Scalar
.
The sponge hash technique requires a padding to be applied before the data can
be hashed.
This is done to avoid hash collisions as stated in the paper of the Poseidon Hash
algorithm. See: https://eprint.iacr.org/2019/458.pdf.
The inputs of the sponge_hash
are always Scalar
or need to be capable of being represented
as it.
The module provides two sponge hash implementations:
Sponge hash using Scalar
as backend. Which hashes the inputted Scalar
s and returns a single
Scalar
.
Sponge hash gadget using dusk_plonk::Witness
as a backend. This technique is used/required
when you want to proof pre-images of unconstrained data inside Zero-Knowledge PLONK circuits.
This crate contains info about all the functions that the library provides as well as the documentation regarding the data structures that it exports. To check it, please feel free to go to the documentation page
There are benchmarks for sponge
and cipher
in their native form, operating on Scalar
, and as a zero-knowledge gadget, using Witness
.
To run all benchmarks on your machine, run
shell
cargo bench
in the repository.
To run a specific benchmark, run
shell
cargo bench --bench <name>
where you replace <name>
with the benchmark name. For example to run the benchmarks for the poseidon cipher encription from the file 'benches/cipher_encrypt.rs', you would need to run
shell
cargo bench --benches cipher_encrypt
This code is licensed under Mozilla Public License Version 2.0 (MPL-2.0). Please see LICENSE for further info.
Implementation designed by the dusk team.