Skip to content

Commit

Permalink
feat: recover compat poseidon (#186)
Browse files Browse the repository at this point in the history
* feat: recover compat poseidon
* feat: fix lint
* chore: pin `syn` version in `manta-pay`
* chore: re-order dependencies correctly
* chore: disable hakari
* feat: disable hakari on the CI on the main branch
* chore: enable hakari
* chore: fix typo in CI
* chore: sort dependencies in manta-pay

Signed-off-by: Brandon H. Gomes <[email protected]>
Co-authored-by: Brandon H. Gomes <[email protected]>
  • Loading branch information
Boyuan Feng and bhgomes authored Jul 28, 2022
1 parent 849a9bd commit d8d5862
Show file tree
Hide file tree
Showing 17 changed files with 490 additions and 31 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ env:
jobs:
workspace-hack-check:
name: Workspace Hack Check
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Deprecated

### Removed
- [\#168](https://github.com/Manta-Network/manta-rs/pull/168) Remove old Poseidon hash

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion manta-accounting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ manta-util = { path = "../manta-util", default-features = false, features = ["al
parking_lot = { version = "0.12.0", optional = true, default-features = false }
rand_chacha = { version = "0.3.1", optional = true, default-features = false }
statrs = { version = "0.15.0", optional = true, default-features = false }
workspace-hack = { version = "0.1.0", path = "../workspace-hack" }
workspace-hack = { version = "0.1", path = "../workspace-hack" }

[dev-dependencies]
manta-crypto = { path = "../manta-crypto", default-features = false, features = ["getrandom"] }
2 changes: 1 addition & 1 deletion manta-benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ manta-pay = { path = "../manta-pay", default-features = false, features = ["grot
wasm-bindgen = { version = "0.2.82", default-features = false }
wasm-bindgen-test = { version = "0.3.30", default-features = false }
web-sys = { version = "0.3.59", default-features = false, features = ["console"] }
workspace-hack = { version = "0.1.0", path = "../workspace-hack" }
workspace-hack = { version = "0.1", path = "../workspace-hack" }

[dev-dependencies]
criterion = { version = "0.3.4", default-features = false }
2 changes: 1 addition & 1 deletion manta-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ derivative = { version = "2.2.0", default-features = false, features = ["use_cor
manta-util = { path = "../manta-util", default-features = false, features = ["alloc"] }
rand = { version = "0.8.4", optional = true, default-features = false, features = ["alloc"] }
rand_core = { version = "0.6.3", default-features = false }
workspace-hack = { version = "0.1.0", path = "../workspace-hack" }
workspace-hack = { version = "0.1", path = "../workspace-hack" }

[dev-dependencies]
rand = "0.8.4"
2 changes: 1 addition & 1 deletion manta-parameters/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ std = ["anyhow?/std"]
anyhow = { version = "1.0.57", optional = true, default-features = false }
attohttpc = { version = "0.19.1", optional = true }
blake3 = { version = "1.3.1", default-features = false }
workspace-hack = { version = "0.1.0", path = "../workspace-hack" }
workspace-hack = { version = "0.1", path = "../workspace-hack" }

[dev-dependencies]
git2 = { version = "0.14.4", default-features = false }
Expand Down
5 changes: 3 additions & 2 deletions manta-pay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ groth16 = ["ark-groth16", "ark-snark", "arkworks"]
http = ["reqwest", "serde"]

# SCALE Codec and Type Info
scale = ["scale-codec", "scale-info"]
scale = ["scale-codec", "scale-info", "syn"]

# SCALE Codec and Type Info with the Standard Library Enabled
scale-std = ["scale", "scale-codec/std", "scale-info/std", "std"]
Expand Down Expand Up @@ -132,11 +132,12 @@ reqwest = { version = "0.11.9", optional = true, default-features = false, featu
scale-codec = { package = "parity-scale-codec", version = "3.1.2", optional = true, default-features = false, features = ["derive", "max-encoded-len"] }
scale-info = { version = "2.1.2", optional = true, default-features = false, features = ["derive"] }
serde_json = { version = "1.0.82", optional = true, default-features = false, features = ["alloc"] }
syn = { version = "=1.0.96", optional = true, default-features = false } # FIXME: Workaround until polkadot-v0.9.24 for https://github.com/paritytech/substrate/issues/11706
tempfile = { version = "3.3.0", optional = true, default-features = false }
tide = { version = "0.16.0", optional = true, default-features = false, features = ["h1-server"] }
tokio = { version = "1.20.1", optional = true, default-features = false }
tokio-tungstenite = { version = "0.17.2", optional = true, default-features = false, features = ["native-tls"] }
workspace-hack = { version = "0.1.0", path = "../workspace-hack" }
workspace-hack = { version = "0.1", path = "../workspace-hack" }
ws_stream_wasm = { version = "0.7.3", optional = true, default-features = false }

[dev-dependencies]
Expand Down
26 changes: 9 additions & 17 deletions manta-pay/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::crypto::{
ecc,
encryption::aes::{self, FixedNonceAesGcm},
key::Blake2sKdf,
poseidon::{self, arkworks::TwoPowerMinusOneDomainTag, hash::Hasher},
poseidon::compat as poseidon,
};
use alloc::vec::Vec;
use ark_ff::ToConstraintField;
Expand Down Expand Up @@ -118,36 +118,28 @@ impl<COM, const ARITY: usize> Constant<COM> for PoseidonSpec<ARITY> {
}

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

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

impl poseidon::Constants for PoseidonSpec<2> {
const WIDTH: usize = 3;
const FULL_ROUNDS: usize = 8;
const PARTIAL_ROUNDS: usize = 55;
}
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 SBOX_EXPONENT: u64 = 5;
}

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

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

impl poseidon::Constants for PoseidonSpec<4> {
const WIDTH: usize = 5;
const FULL_ROUNDS: usize = 8;
const PARTIAL_ROUNDS: usize = 56;
}
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 SBOX_EXPONENT: u64 = 5;
}

Expand Down
1 change: 1 addition & 0 deletions manta-pay/src/crypto/poseidon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Code Structure

* `compat.rs`: Contains legacy implementation for Poseidon hash that is kept for compatibility.
* `constants.rs`: Generates poseidon permutation round numbers.
* `lfsr.rs`: Implements linear feedback shift register as a random number generator.
* `matrix.rs`: Implements basic linear algebra.
Expand Down
Loading

0 comments on commit d8d5862

Please sign in to comment.