Skip to content

Commit

Permalink
Merge pull request #57 from Manta-Network/poseidon_optimization
Browse files Browse the repository at this point in the history
Feature: Parameter Generation for Poseidon Hash
  • Loading branch information
Boyuan Feng authored Jun 2, 2022
2 parents d21b0af + afd6931 commit 98d0091
Show file tree
Hide file tree
Showing 17 changed files with 2,706 additions and 474 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- run: rustup update nightly && rustup default nightly
- run: RUSTDOCFLAGS="-D warnings --cfg doc_cfg" cargo doc --workspace --all-features --no-deps --document-private-items
- run: RUSTDOCFLAGS="-D warnings --cfg doc_cfg" cargo +nightly doc --workspace --all-features --no-deps --document-private-items
compile-bench:
name: Compile Bench (${{ matrix.os }} + ${{ matrix.channel }})
strategy:
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@

_Rust Crates for the Manta Network Ecosystem_


1 change: 0 additions & 1 deletion manta-accounting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,3 @@ statrs = { version = "0.15.0", optional = true, default-features = false }

[dev-dependencies]
manta-crypto = { path = "../manta-crypto", default-features = false, features = ["getrandom"] }

10 changes: 5 additions & 5 deletions manta-crypto/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub trait BinaryHashFunction<COM = ()> {
}

/// Array Hash Function
pub trait ArrayHashFunction<COM, const ARITY: usize> {
pub trait ArrayHashFunction<const ARITY: usize, COM = ()> {
/// Input Type
type Input: ?Sized;

Expand Down Expand Up @@ -117,7 +117,7 @@ pub mod array {
#[inline]
pub fn as_unary<H, COM>(hasher: H) -> AsUnary<H, COM>
where
H: ArrayHashFunction<COM, 1>,
H: ArrayHashFunction<1, COM>,
{
AsUnary::new(hasher)
}
Expand All @@ -132,7 +132,7 @@ pub mod array {
#[derivative(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct AsUnary<H, COM = ()>
where
H: ArrayHashFunction<COM, 1>,
H: ArrayHashFunction<1, COM>,
{
/// Array Hasher
hasher: H,
Expand All @@ -143,7 +143,7 @@ pub mod array {

impl<H, COM> AsUnary<H, COM>
where
H: ArrayHashFunction<COM, 1>,
H: ArrayHashFunction<1, COM>,
{
/// Builds a new [`UnaryHashFunction`] implementation out of an [`ArrayHashFunction`]
/// implementation `hasher`.
Expand All @@ -158,7 +158,7 @@ pub mod array {

impl<H, COM> UnaryHashFunction<COM> for AsUnary<H, COM>
where
H: ArrayHashFunction<COM, 1>,
H: ArrayHashFunction<1, COM>,
{
type Input = H::Input;
type Output = H::Output;
Expand Down
3 changes: 3 additions & 0 deletions manta-crypto/src/merkle_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

//! Merkle Trees and Forests
// NOTE: clippy false-positive: https://github.com/rust-lang/rust-clippy/pull/8869
#![allow(clippy::derive_partial_eq_without_eq)]

// FIXME: Get rid of as many `pub(super)` declarations as we can.
// TODO: Should `Leaf` move into `Tree`/`Configuration` since we might want the tree to have
// special kinds of leaf input (metadata along with just the digest)?
Expand Down
12 changes: 6 additions & 6 deletions manta-pay/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,28 @@ pub type ProofSystem = groth16::Groth16<PairingCurve>;
pub struct PoseidonSpec<const ARITY: usize>;

/// Poseidon-2 Hash Parameters
pub type Poseidon2 = poseidon::Hasher<PoseidonSpec<2>, (), 2>;
pub type Poseidon2 = poseidon::Hasher<PoseidonSpec<2>, 2>;

/// Poseidon-2 Hash Parameters Variable
pub type Poseidon2Var = poseidon::Hasher<PoseidonSpec<2>, Compiler, 2>;
pub type Poseidon2Var = poseidon::Hasher<PoseidonSpec<2>, 2, Compiler>;

impl poseidon::arkworks::Specification for PoseidonSpec<2> {
type Field = ConstraintField;
const FULL_ROUNDS: usize = 8;
const PARTIAL_ROUNDS: usize = 57;
const PARTIAL_ROUNDS: usize = 55;
const SBOX_EXPONENT: u64 = 5;
}

/// Poseidon-4 Hash Parameters
pub type Poseidon4 = poseidon::Hasher<PoseidonSpec<4>, (), 4>;
pub type Poseidon4 = poseidon::Hasher<PoseidonSpec<4>, 4>;

/// Poseidon-4 Hash Parameters Variable
pub type Poseidon4Var = poseidon::Hasher<PoseidonSpec<4>, Compiler, 4>;
pub type Poseidon4Var = poseidon::Hasher<PoseidonSpec<4>, 4, Compiler>;

impl poseidon::arkworks::Specification for PoseidonSpec<4> {
type Field = ConstraintField;
const FULL_ROUNDS: usize = 8;
const PARTIAL_ROUNDS: usize = 60;
const PARTIAL_ROUNDS: usize = 56;
const SBOX_EXPONENT: u64 = 5;
}

Expand Down
Loading

0 comments on commit 98d0091

Please sign in to comment.