Skip to content

Commit

Permalink
feat: (temporary commit) make each hasher generic over a field
Browse files Browse the repository at this point in the history
  • Loading branch information
DrPeterVanNostrand committed Feb 14, 2022
1 parent 7cd0c6e commit 1cbb33f
Show file tree
Hide file tree
Showing 11 changed files with 2,115 additions and 502 deletions.
577 changes: 577 additions & 0 deletions filecoin-hashers/src/generic/blake2s.rs

Large diffs are not rendered by default.

91 changes: 91 additions & 0 deletions filecoin-hashers/src/generic/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#[cfg(feature = "blake2s")]
pub mod blake2s;
#[cfg(feature = "poseidon")]
pub mod poseidon;
#[cfg(feature = "sha256")]
pub mod sha256;

#[cfg(feature = "blake2s")]
pub use blake2s::{Blake2sDomain, Blake2sFunction, Blake2sHasher};
#[cfg(feature = "poseidon")]
pub use poseidon::{PoseidonDomain, PoseidonFunction, PoseidonHasher};
#[cfg(feature = "sha256")]
pub use sha256::{Sha256Domain, Sha256Function, Sha256Hasher};

// Rexport each hasher over the field `Fr` which is compatible with Groth16.
pub mod groth {
#[cfg(any(feature = "blake2s", feature = "poseidon", feature = "sha256"))]
use blstrs::Scalar as Fr;

// BLS12-381
#[cfg(feature = "blake2s")]
pub type Blake2sDomain = super::Blake2sDomain<Fr>;
#[cfg(feature = "blake2s")]
pub type Blake2sFunction = super::Blake2sFunction<Fr>;
#[cfg(feature = "blake2s")]
pub type Blake2sHasher = super::Blake2sHasher<Fr>;

#[cfg(feature = "poseidon")]
pub type PoseidonDomain = super::PoseidonDomain<Fr>;
#[cfg(feature = "poseidon")]
pub type PoseidonFunction = super::PoseidonFunction<Fr>;
#[cfg(feature = "poseidon")]
pub type PoseidonHasher = super::PoseidonHasher<Fr>;

#[cfg(feature = "sha256")]
pub type Sha256Domain = super::Sha256Domain<Fr>;
#[cfg(feature = "sha256")]
pub type Sha256Function = super::Sha256Function<Fr>;
#[cfg(feature = "sha256")]
pub type Sha256Hasher = super::Sha256Hasher<Fr>;
}

// Rexport each hasher over the fields `Fp` and `Fq` which are compatible with Halo2.
pub mod halo {
#[cfg(any(feature = "blake2s", feature = "poseidon", feature = "sha256"))]
use pasta_curves::{Fp, Fq};

// Pallas
#[cfg(feature = "blake2s")]
pub type Blake2sDomainPallas = super::Blake2sDomain<Fp>;
#[cfg(feature = "blake2s")]
pub type Blake2sFunctionPallas = super::Blake2sFunction<Fp>;
#[cfg(feature = "blake2s")]
pub type Blake2sHasherPallas = super::Blake2sHasher<Fp>;

#[cfg(feature = "poseidon")]
pub type PoseidonDomainPallas = super::PoseidonDomain<Fp>;
#[cfg(feature = "poseidon")]
pub type PoseidonFunctionPallas = super::PoseidonFunction<Fp>;
#[cfg(feature = "poseidon")]
pub type PoseidonHasherPallas = super::PoseidonHasher<Fp>;

#[cfg(feature = "sha256")]
pub type Sha256DomainPallas = super::Sha256Domain<Fp>;
#[cfg(feature = "sha256")]
pub type Sha256FunctionPallas = super::Sha256Function<Fp>;
#[cfg(feature = "sha256")]
pub type Sha256HasherPallas = super::Sha256Hasher<Fp>;

// Vesta
#[cfg(feature = "blake2s")]
pub type Blake2sDomainVesta = super::Blake2sDomain<Fq>;
#[cfg(feature = "blake2s")]
pub type Blake2sFunctionVesta = super::Blake2sFunction<Fq>;
#[cfg(feature = "blake2s")]
pub type Blake2sHasherVesta = super::Blake2sHasher<Fq>;

#[cfg(feature = "poseidon")]
pub type PoseidonDomainVesta = super::PoseidonDomain<Fq>;
#[cfg(feature = "poseidon")]
pub type PoseidonFunctionVesta = super::PoseidonFunction<Fq>;
#[cfg(feature = "poseidon")]
pub type PoseidonHasherVesta = super::PoseidonHasher<Fq>;

#[cfg(feature = "sha256")]
pub type Sha256DomainVesta = super::Sha256Domain<Fq>;
#[cfg(feature = "sha256")]
pub type Sha256FunctionVesta = super::Sha256Function<Fq>;
#[cfg(feature = "sha256")]
pub type Sha256HasherVesta = super::Sha256Hasher<Fq>;
}
Loading

0 comments on commit 1cbb33f

Please sign in to comment.