liminal-ark-poseidon

Crates.ioliminal-ark-poseidon
lib.rsliminal-ark-poseidon
version0.1.0
sourcesrc
created_at2023-03-21 06:40:59.040013
updated_at2023-03-21 06:40:59.040013
descriptionAn instantiation of the Poseidon SNARK-friendly hash function.
homepagehttps://alephzero.org
repositoryhttps://github.com/Cardinal-Cryptography/aleph-node
max_upload_size
id815891
size289,262
cardinal-crate-owner (cardinal-crate-owner)

documentation

https://docs.rs/liminal-ark-poseidon

README

Liminal Arkworks Poseidon

This package contains two crates: a library exposing arkworks-based Poseidon hashing and a binary for regenerating parameters. Parameters are generated using https://github.com/penumbra-zone/poseidon377.

Library usage

The lib crate liminal-ark-poseidon provides two modules:

  • hash module that exposes <x>_to_one_hash method family for hashing raw field elements
  • circuit module that exposes <x>_to_one_hash method family for hashing circuit field elements; it is available only under circuit feature flag

Currently, <x> is one, two and four, i.e. we support 1:1, 2:1 and 4:1 hashing.

Example usage:

fn hash_outside_circuit(left: Fr, right: Fr) -> Fr {
    liminal_ark_poseidon::hash::two_to_one_hash([left, right])
}

fn hash_in_circuit(
    cs: ConstraintSystemRef<CircuitField>, 
    left: FpVar<CircuitField>,
    right: FpVar<CircuitField>,
) -> Result<FpVar<CircuitField>, SynthesisError> {
    liminal_ark_poseidon::circuit::two_to_one_hash(cs, [left, right])
}

Binary usage

If you need fresh parameters, you can regenerate parameters module by running:

cargo run --release --features paramgen

You can also manipulate security level with SECURITY_LEVEL env variable.

Commit count: 1074

cargo fmt