Skip to content

Commit

Permalink
Merge pull request #2 from anemoi-hash/refactor
Browse files Browse the repository at this point in the history
Bump arkworks dependencies and refactor behind common traits
  • Loading branch information
Nashtare authored Dec 14, 2023
2 parents e840cd7 + 02533a0 commit 647c921
Show file tree
Hide file tree
Showing 85 changed files with 5,115 additions and 17,483 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: CI
on:
push:
branches:
- main
pull_request:
types: [opened, repoened, synchronize]

Expand All @@ -26,7 +24,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --release --all-targets
args: --all-targets

clippy:
name: Clippy
Expand Down
18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ keywords = ["cryptography", "hash", "hash-function", "anemoi", "sponge", "compre
categories = ["cryptography"]

[dependencies]
ark-ff = { version="^0.3.0", default-features = false }
ark-bls12-377 = { version="^0.3.0", default-features = false, optional = true }
ark-bls12-381 = { version="^0.3.0", default-features = false, optional = true }
ark-bn254 = { version="^0.3.0", default-features = false, optional = true }
ark-ec = { version="^0.3.0", default-features = false }
ark-pallas = { version="^0.3.0", default-features = false, optional = true }
ark-std = { version="^0.3.0", default-features = false }
ark-ff = { version="^0.4.0", default-features = false }
ark-bls12-377 = { version="^0.4.0", default-features = false, optional = true }
ark-bls12-381 = { version="^0.4.0", default-features = false, optional = true }
ark-bn254 = { version="^0.4.0", default-features = false, optional = true }
ark-ec = { version="^0.4.0", default-features = false }
ark-pallas = { version="^0.4.0", default-features = false, optional = true }
ark-serialize = { version="^0.4.0", default-features = false }
ark-std = { version="^0.4.0", default-features = false }
getrandom = { version = "0.2", default-features = false, features = ["js"] }
rand_core = { version = "0.6.2", default-features = false, features = ["getrandom"] }
unroll = { version = "0.1.5" }

[dev-dependencies]
ark-serialize = { version="^0.3.0" }
ark-algebra-test-templates = { version="^0.3.0" }
ark-algebra-test-templates = { version="^0.4.0" }
criterion = "0.3"

[features]
Expand Down
10 changes: 5 additions & 5 deletions benches/bls12_377.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|bench| {
let v = [Felt::one(); anemoi_2_1::STATE_WIDTH];

bench.iter(|| anemoi_2_1::AnemoiHash::compress(black_box(&v)))
bench.iter(|| anemoi_2_1::AnemoiBls12_377_2_1::compress(black_box(&v)))
},
);

Expand All @@ -23,7 +23,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|bench| {
let v = [Felt::one(); anemoi_4_3::STATE_WIDTH];

bench.iter(|| anemoi_4_3::AnemoiHash::compress(black_box(&v)))
bench.iter(|| anemoi_4_3::AnemoiBls12_377_4_3::compress(black_box(&v)))
},
);

Expand All @@ -32,7 +32,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|bench| {
let v = [Felt::one(); anemoi_4_3::STATE_WIDTH];

bench.iter(|| anemoi_4_3::AnemoiHash::compress_k(black_box(&v), 4))
bench.iter(|| anemoi_4_3::AnemoiBls12_377_4_3::compress_k(black_box(&v), 4))
},
);

Expand All @@ -43,7 +43,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut rng = OsRng;
rng.fill_bytes(&mut data);

bench.iter(|| anemoi_2_1::AnemoiHash::hash(black_box(&data)))
bench.iter(|| anemoi_2_1::AnemoiBls12_377_2_1::hash(black_box(&data)))
},
);

Expand All @@ -54,7 +54,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut rng = OsRng;
rng.fill_bytes(&mut data);

bench.iter(|| anemoi_4_3::AnemoiHash::hash(black_box(&data)))
bench.iter(|| anemoi_4_3::AnemoiBls12_377_4_3::hash(black_box(&data)))
},
);
}
Expand Down
10 changes: 5 additions & 5 deletions benches/bls12_381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|bench| {
let v = [Felt::one(); anemoi_2_1::STATE_WIDTH];

bench.iter(|| anemoi_2_1::AnemoiHash::compress(black_box(&v)))
bench.iter(|| anemoi_2_1::AnemoiBls12_381_2_1::compress(black_box(&v)))
},
);

Expand All @@ -23,7 +23,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|bench| {
let v = [Felt::one(); anemoi_4_3::STATE_WIDTH];

bench.iter(|| anemoi_4_3::AnemoiHash::compress(black_box(&v)))
bench.iter(|| anemoi_4_3::AnemoiBls12_381_4_3::compress(black_box(&v)))
},
);

Expand All @@ -32,7 +32,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|bench| {
let v = [Felt::one(); anemoi_4_3::STATE_WIDTH];

bench.iter(|| anemoi_4_3::AnemoiHash::compress_k(black_box(&v), 4))
bench.iter(|| anemoi_4_3::AnemoiBls12_381_4_3::compress_k(black_box(&v), 4))
},
);

Expand All @@ -43,7 +43,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut rng = OsRng;
rng.fill_bytes(&mut data);

bench.iter(|| anemoi_2_1::AnemoiHash::hash(black_box(&data)))
bench.iter(|| anemoi_2_1::AnemoiBls12_381_2_1::hash(black_box(&data)))
},
);

Expand All @@ -54,7 +54,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut rng = OsRng;
rng.fill_bytes(&mut data);

bench.iter(|| anemoi_4_3::AnemoiHash::hash(black_box(&data)))
bench.iter(|| anemoi_4_3::AnemoiBls12_381_4_3::hash(black_box(&data)))
},
);
}
Expand Down
10 changes: 5 additions & 5 deletions benches/bn_254.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|bench| {
let v = [Felt::one(); anemoi_2_1::STATE_WIDTH];

bench.iter(|| anemoi_2_1::AnemoiHash::compress(black_box(&v)))
bench.iter(|| anemoi_2_1::AnemoiBn254_2_1::compress(black_box(&v)))
},
);

Expand All @@ -23,7 +23,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|bench| {
let v = [Felt::one(); anemoi_4_3::STATE_WIDTH];

bench.iter(|| anemoi_4_3::AnemoiHash::compress(black_box(&v)))
bench.iter(|| anemoi_4_3::AnemoiBn254_4_3::compress(black_box(&v)))
},
);

Expand All @@ -32,7 +32,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|bench| {
let v = [Felt::one(); anemoi_4_3::STATE_WIDTH];

bench.iter(|| anemoi_4_3::AnemoiHash::compress_k(black_box(&v), 4))
bench.iter(|| anemoi_4_3::AnemoiBn254_4_3::compress_k(black_box(&v), 4))
},
);

Expand All @@ -43,7 +43,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut rng = OsRng;
rng.fill_bytes(&mut data);

bench.iter(|| anemoi_2_1::AnemoiHash::hash(black_box(&data)))
bench.iter(|| anemoi_2_1::AnemoiBn254_2_1::hash(black_box(&data)))
},
);

Expand All @@ -54,7 +54,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut rng = OsRng;
rng.fill_bytes(&mut data);

bench.iter(|| anemoi_4_3::AnemoiHash::hash(black_box(&data)))
bench.iter(|| anemoi_4_3::AnemoiBn254_4_3::hash(black_box(&data)))
},
);
}
Expand Down
10 changes: 5 additions & 5 deletions benches/ed_on_bls12_377.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|bench| {
let v = [Felt::one(); anemoi_2_1::STATE_WIDTH];

bench.iter(|| anemoi_2_1::AnemoiHash::compress(black_box(&v)))
bench.iter(|| anemoi_2_1::AnemoiEdOnBls12_377_2_1::compress(black_box(&v)))
},
);

Expand All @@ -23,7 +23,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|bench| {
let v = [Felt::one(); anemoi_4_3::STATE_WIDTH];

bench.iter(|| anemoi_4_3::AnemoiHash::compress(black_box(&v)))
bench.iter(|| anemoi_4_3::AnemoiEdOnBls12_377_4_3::compress(black_box(&v)))
},
);

Expand All @@ -32,7 +32,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|bench| {
let v = [Felt::one(); anemoi_4_3::STATE_WIDTH];

bench.iter(|| anemoi_4_3::AnemoiHash::compress_k(black_box(&v), 4))
bench.iter(|| anemoi_4_3::AnemoiEdOnBls12_377_4_3::compress_k(black_box(&v), 4))
},
);

Expand All @@ -43,7 +43,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut rng = OsRng;
rng.fill_bytes(&mut data);

bench.iter(|| anemoi_2_1::AnemoiHash::hash(black_box(&data)))
bench.iter(|| anemoi_2_1::AnemoiEdOnBls12_377_2_1::hash(black_box(&data)))
},
);

Expand All @@ -54,7 +54,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut rng = OsRng;
rng.fill_bytes(&mut data);

bench.iter(|| anemoi_4_3::AnemoiHash::hash(black_box(&data)))
bench.iter(|| anemoi_4_3::AnemoiEdOnBls12_377_4_3::hash(black_box(&data)))
},
);
}
Expand Down
10 changes: 5 additions & 5 deletions benches/jubjub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|bench| {
let v = [Felt::one(); anemoi_2_1::STATE_WIDTH];

bench.iter(|| anemoi_2_1::AnemoiHash::compress(black_box(&v)))
bench.iter(|| anemoi_2_1::AnemoiJubjub_2_1::compress(black_box(&v)))
},
);

Expand All @@ -23,7 +23,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|bench| {
let v = [Felt::one(); anemoi_4_3::STATE_WIDTH];

bench.iter(|| anemoi_4_3::AnemoiHash::compress(black_box(&v)))
bench.iter(|| anemoi_4_3::AnemoiJubjub_4_3::compress(black_box(&v)))
},
);

Expand All @@ -32,7 +32,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|bench| {
let v = [Felt::one(); anemoi_4_3::STATE_WIDTH];

bench.iter(|| anemoi_4_3::AnemoiHash::compress_k(black_box(&v), 4))
bench.iter(|| anemoi_4_3::AnemoiJubjub_4_3::compress_k(black_box(&v), 4))
},
);

Expand All @@ -43,7 +43,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut rng = OsRng;
rng.fill_bytes(&mut data);

bench.iter(|| anemoi_2_1::AnemoiHash::hash(black_box(&data)))
bench.iter(|| anemoi_2_1::AnemoiJubjub_2_1::hash(black_box(&data)))
},
);

Expand All @@ -54,7 +54,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut rng = OsRng;
rng.fill_bytes(&mut data);

bench.iter(|| anemoi_4_3::AnemoiHash::hash(black_box(&data)))
bench.iter(|| anemoi_4_3::AnemoiJubjub_4_3::hash(black_box(&data)))
},
);
}
Expand Down
10 changes: 5 additions & 5 deletions benches/pallas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|bench| {
let v = [Felt::one(); anemoi_2_1::STATE_WIDTH];

bench.iter(|| anemoi_2_1::AnemoiHash::compress(black_box(&v)))
bench.iter(|| anemoi_2_1::AnemoiPallas_2_1::compress(black_box(&v)))
},
);

Expand All @@ -23,7 +23,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|bench| {
let v = [Felt::one(); anemoi_4_3::STATE_WIDTH];

bench.iter(|| anemoi_4_3::AnemoiHash::compress(black_box(&v)))
bench.iter(|| anemoi_4_3::AnemoiPallas_4_3::compress(black_box(&v)))
},
);

Expand All @@ -32,7 +32,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|bench| {
let v = [Felt::one(); anemoi_4_3::STATE_WIDTH];

bench.iter(|| anemoi_4_3::AnemoiHash::compress_k(black_box(&v), 4))
bench.iter(|| anemoi_4_3::AnemoiPallas_4_3::compress_k(black_box(&v), 4))
},
);

Expand All @@ -43,7 +43,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut rng = OsRng;
rng.fill_bytes(&mut data);

bench.iter(|| anemoi_2_1::AnemoiHash::hash(black_box(&data)))
bench.iter(|| anemoi_2_1::AnemoiPallas_2_1::hash(black_box(&data)))
},
);

Expand All @@ -54,7 +54,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut rng = OsRng;
rng.fill_bytes(&mut data);

bench.iter(|| anemoi_4_3::AnemoiHash::hash(black_box(&data)))
bench.iter(|| anemoi_4_3::AnemoiPallas_4_3::hash(black_box(&data)))
},
);
}
Expand Down
10 changes: 5 additions & 5 deletions benches/vesta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|bench| {
let v = [Felt::one(); anemoi_2_1::STATE_WIDTH];

bench.iter(|| anemoi_2_1::AnemoiHash::compress(black_box(&v)))
bench.iter(|| anemoi_2_1::AnemoiVesta_2_1::compress(black_box(&v)))
},
);

Expand All @@ -23,7 +23,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|bench| {
let v = [Felt::one(); anemoi_4_3::STATE_WIDTH];

bench.iter(|| anemoi_4_3::AnemoiHash::compress(black_box(&v)))
bench.iter(|| anemoi_4_3::AnemoiVesta_4_3::compress(black_box(&v)))
},
);

Expand All @@ -32,7 +32,7 @@ fn criterion_benchmark(c: &mut Criterion) {
|bench| {
let v = [Felt::one(); anemoi_4_3::STATE_WIDTH];

bench.iter(|| anemoi_4_3::AnemoiHash::compress_k(black_box(&v), 4))
bench.iter(|| anemoi_4_3::AnemoiVesta_4_3::compress_k(black_box(&v), 4))
},
);

Expand All @@ -43,7 +43,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut rng = OsRng;
rng.fill_bytes(&mut data);

bench.iter(|| anemoi_2_1::AnemoiHash::hash(black_box(&data)))
bench.iter(|| anemoi_2_1::AnemoiVesta_2_1::hash(black_box(&data)))
},
);

Expand All @@ -54,7 +54,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut rng = OsRng;
rng.fill_bytes(&mut data);

bench.iter(|| anemoi_4_3::AnemoiHash::hash(black_box(&data)))
bench.iter(|| anemoi_4_3::AnemoiVesta_4_3::hash(black_box(&data)))
},
);
}
Expand Down
6 changes: 4 additions & 2 deletions src/bls12_377/anemoi_2_1/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use alloc::vec::Vec;
use super::DIGEST_SIZE;

use super::Felt;
use ark_ff::to_bytes;
use ark_serialize::CanonicalSerialize;

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
/// An Anemoi Digest for the Anemoi Hash over Felt
Expand Down Expand Up @@ -40,7 +40,9 @@ impl AnemoiDigest {

/// Returns an array of bytes corresponding to the digest
pub fn to_bytes(&self) -> [u8; 48] {
to_bytes![self.0[0]].unwrap()[..48].try_into().unwrap()
let mut bytes = [0u8; 48];
self.0[0].serialize_compressed(&mut bytes[..]).unwrap();
bytes
}
}

Expand Down
Loading

0 comments on commit 647c921

Please sign in to comment.