Home

Awesome

Poseidon and Poseidon2 for Noir

License: MIT

This repository contains the following Noir crates in the respective folders:

Poseidon and Poseidon2, in contrast to traditional hash constructions like SHA-256, utilize low-degree round functions with the $x^d$ S-box to minimize the necessary constraints inside a zk-circuit. In the case of Noir's native curve BN254, the exponent in the round function is $d=5$. The implementations utilize modern optimizations (in contrast to the existing Poseidon implementation in Noir's standard library) with all advances in cryptanalysis in mind.

You can see the designs and the difference of Poseidon and Poseidon2 in the following picture: Poseidon2Design

we obtained the picture from the Poseidon2 Paper

For a more in-depth discussions of the two algorithms, have a look in the sub-folders.

Performance

Similar to the Poseidon implementation in Noir's standard library, we provide a Poseidon implementation for state sizes $t \in [2, 16]$. Poseidon2 has an internal state size $t\in \{2,3,4t^\prime,\dots,24\} \text{ for } t^\prime \in \mathbb{N}$, therefore we provide an implementation for state sizes $t \in \{2,3,4,8,12,16\}$. The following table shows the constraints obtained by nargo info for our implementations and the corresponding hashes from the standard library.

#Poseidon (stdlib)PoseidonPoseidon2
2586586586
3218320982094
4235323052313
528332507-
630592795-
735323031-
8387732833139
940763551-
1041233835-
1149484135-
12475144513995
1355394783-
1463885131-
1558135495-
16658158754883

Usage

Have a look in the respective sub-folders for instructions on how to use the libraries and installation.

Testing

We provide a justfile in the root of the repository. Write just in your terminal to execute the tests. In case you do not have an installation of just, you can cd into the directories and write

nargo test

Disclaimer

This is experimental software and is provided on an "as is" and "as available" basis. We do not give any warranties and will not be liable for any losses incurred through any use of this code base.