pso-poseidon 0.1.0

Poseidon hash implementation compatible with Circom
Documentation

P.S.O. Poseidon

pso-poseidon is a Poseidon hash implementation in Rust created for PSO based on light-poseidon library.

Parameters

The library provides pre-generated parameters over the BN254 curve, however it can work with any parameters provided as long as developers take care of generating the round constants.

Parameters provided by the library are:

  • x^5 S-boxes
  • width - 2 ≤ t ≤ 13
  • inputs - 1 ≤ n ≤ 12
  • 8 full rounds and partial rounds depending on t: [56, 57, 56, 60, 60, 63, 64, 63, 60, 66, 60, 65]

Output type

Poseidon type implements two traits which serve the purpose of returning the calculated hash in different representations:

  • PoseidonHasher with the hash method which returns ff::PrimeField. Might be useful if you want to immediately process the result with an another library which works with ff::PrimeField types.

Examples

With PoseidonHasher trait and ff::PrimeField result:

use halo2_axiom::halo2curves::bn256::Fr;
use halo2_axiom::halo2curves::ff::PrimeField;
use light_poseidon::{Poseidon, PoseidonHasher, parameters::bn254_x5};

let mut poseidon = Poseidon::<Fr>::new_circom(2).unwrap();

let input1 = Fr::from_bytes(&[1u8; 32]).unwrap();
let input2 = Fr::from_bytes(&[2u8; 32]).unwrap();

let hash = poseidon.hash(&[input1, input2]).unwrap();

// Do something with `hash`.

Implementation

The implementation is compatible with the original SageMath implementation, but it was also inspired by the following ones:

Security

This library has been audited by Veridise. You can read the audit report here.