Dusk-Poseidon
Reference implementation for the Poseidon Hashing algorithm.
Reference: 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 on field elements of the bls12-381 elliptic curve.
The hash uses the Hades design for its inner permutation and the SAFE framework for contstructing the sponge.
The library provides the two hashing techniques of Poseidon:
- The 'normal' hashing functionalities operating on
BlsScalar
. - The 'gadget' hashing functionalities that build a circuit which outputs the hash.
Example
use StdRng;
use SeedableRng;
use ;
use BlsScalar;
use Field;
// generate random input
let mut rng = seed_from_u64;
let mut input = ;
for scalar in input.iter_mut
// digest the input all at once
let hash = digest;
// update the input gradually
let mut hasher = new;
hasher.update;
hasher.update;
assert_eq!;
// create a hash used for merkle tree hashing with arity = 4
let merkle_hash = digest;
// which is different when another domain is used
assert_ne!;
Benchmarks
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
cargo bench --features=zk,cipher
in the repository.
Licensing
This code is licensed under Mozilla Public License Version 2.0 (MPL-2.0). Please see LICENSE for further info.
About
Implementation designed by the dusk team.
Contributing
- If you want to contribute to this repository/project please, check CONTRIBUTING.md
- If you want to report a bug or request a new feature addition, please open an issue on this repository.