Skip to content

mdehoog/poseidon

Repository files navigation

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:

Curve Alpha Constants
BN254 5 constants/bn254.go
BLS12-381 5 constants/bls12_381.go
BW6-761 5 constants/bw6_761.go

Note that other alpha values are not yet supported in the hash implementations.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages