poseidon
A Golang and Gnark implementation of the Poseidon hash function.
The Golang version is an adaption of the iden3
implementation, but with support for multiple curves.
The Gnark implementation is an adaption of the circom
implementation, available in both native field and emulated versions.
Usage
Standard:
poseidon.Hash[*fr.Element]([]*big.Int{in1, in2})
Gnark circuit:
poseidon.Hash(api, []frontend.Variable{in1, in2})
Gnark circuit using emulated field:
bnField, _ := emulated.NewField[sw_bn254.ScalarField](api)
poseidon.Hash(bnField, []*emulated.Element[sw_bn254.ScalarField]{in1, in2})
Constants
The constants were generated using a combination of a version of the
poseidon sage script
from the hadeshash project, and
triplewz's generator implementation forked to support multiple field elements
provided by gnark-crypto. The hadeshash script has a
minor modification
to round up the Rp
value to the nearest multiple of t
. The generated constants match the
constants in the circom library
for the BN254 curve.
You can regenerate the constants using make constants
. The repo currently has constants generated for:
Note that other alpha values are not yet supported in the hash implementations.