light-poseidon is a Poseidon hash implementation in Rust created for Light Protocol.
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:
Example with two simple big-endian byte inputs (converted to prime fields) and BN254-based parameters provided by the library:
```rust use lightposeidon::{PoseidonHasher, parameters::bn254x53::poseidonparameters}; use arkbn254::Fq; use arkff::{BigInteger, PrimeField};
let params = poseidon_parameters(); let mut poseidon = PoseidonHasher::new(params);
let input1 = Fq::frombebytesmodorder(&[1u8; 32]); let input2 = Fq::frombebytesmodorder(&[2u8; 32]);
let hash = poseidon.hash(&[input1, input2]);
// Do something with hash
.
println!("{:?}", hash.intorepr().tobytes_be());
// Should print:
// [
// 40, 7, 251, 60, 51, 30, 115, 141, 251, 200, 13, 46, 134, 91, 113, 170, 131, 90, 53,
// 175, 9, 61, 242, 164, 127, 33, 249, 65, 253, 131, 35, 116
// ]
```
The implementation is compatible with the original SageMath implementation, but it was also inspired by the following ones:
Licensed under Apache License, Version 2.0.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.