Skip to content

Commit

Permalink
chore: use new Winterfell release
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Kindi-0 committed Oct 28, 2024
1 parent ca5760c commit a323d76
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 45 deletions.
82 changes: 42 additions & 40 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ num = { version = "0.4", default-features = false, features = ["alloc", "libm"]
num-complex = { version = "0.4", default-features = false }
rand = { version = "0.8", default-features = false }
rand_core = { version = "0.6", default-features = false }
rand-utils = { git = "https://github.com/facebook/winterfell", branch = "next", package = "winter-rand-utils", optional = true }
rand-utils = { version = "0.10", package = "winter-rand-utils", optional = true }
serde = { version = "1.0", default-features = false, optional = true, features = ["derive"] }
sha3 = { version = "0.10", default-features = false }
winter-crypto = { git = "https://github.com/facebook/winterfell", branch = "next", default-features = false }
winter-math = { git = "https://github.com/facebook/winterfell", branch = "next", default-features = false }
winter-utils = { git = "https://github.com/facebook/winterfell", branch = "next", default-features = false }
winter-crypto = { version = "0.10", default-features = false }
winter-math = { version = "0.10", default-features = false }
winter-utils = { version = "0.10", default-features = false }

[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] }
getrandom = { version = "0.2", features = ["js"] }
hex = { version = "0.4", default-features = false, features = ["alloc"] }
proptest = "1.5"
rand_chacha = { version = "0.3", default-features = false }
rand-utils = { git = "https://github.com/facebook/winterfell", branch = "next", package = "winter-rand-utils" }
rand-utils = { version = "0.10", package = "winter-rand-utils" }
seq-macro = { version = "0.3" }

[build-dependencies]
Expand Down
16 changes: 16 additions & 0 deletions src/hash/blake/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use core::{
ops::Deref,
slice::from_raw_parts,
};
use std::vec::Vec;

use super::{Digest, ElementHasher, Felt, FieldElement, Hasher};
use crate::utils::{
Expand Down Expand Up @@ -114,6 +115,11 @@ impl Hasher for Blake3_256 {
Self::hash(prepare_merge(values))
}

fn merge_many(values: &[Self::Digest]) -> Self::Digest {
let bytes: Vec<u8> = values.iter().flat_map(|v| v.as_bytes()).collect();
Blake3Digest(blake3::hash(&bytes).into())
}

fn merge_with_int(seed: Self::Digest, value: u64) -> Self::Digest {
let mut hasher = blake3::Hasher::new();
hasher.update(&seed.0);
Expand Down Expand Up @@ -174,6 +180,11 @@ impl Hasher for Blake3_192 {
Blake3Digest(*shrink_bytes(&blake3::hash(bytes).into()))
}

fn merge_many(values: &[Self::Digest]) -> Self::Digest {
let bytes: Vec<u8> = values.iter().flat_map(|v| v.as_bytes()).collect();
Blake3Digest(*shrink_bytes(&blake3::hash(&bytes).into()))
}

fn merge(values: &[Self::Digest; 2]) -> Self::Digest {
Self::hash(prepare_merge(values))
}
Expand Down Expand Up @@ -242,6 +253,11 @@ impl Hasher for Blake3_160 {
Self::hash(prepare_merge(values))
}

fn merge_many(values: &[Self::Digest]) -> Self::Digest {
let bytes: Vec<u8> = values.iter().flat_map(|v| v.as_bytes()).collect();
Blake3Digest(*shrink_bytes(&blake3::hash(&bytes).into()))
}

fn merge_with_int(seed: Self::Digest, value: u64) -> Self::Digest {
let mut hasher = blake3::Hasher::new();
hasher.update(&seed.0);
Expand Down
7 changes: 7 additions & 0 deletions src/hash/rescue/rpo/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloc::vec::Vec;
use core::ops::Range;

use super::{
Expand Down Expand Up @@ -164,6 +165,12 @@ impl Hasher for Rpo256 {
RpoDigest::new(state[DIGEST_RANGE].try_into().unwrap())
}

fn merge_many(values: &[Self::Digest]) -> Self::Digest {
let elements: Vec<Felt> =
Self::Digest::digests_as_elements(values.iter()).copied().collect();
Self::hash_elements(&elements)
}

fn merge_with_int(seed: Self::Digest, value: u64) -> Self::Digest {
// initialize the state as follows:
// - seed is copied into the first 4 elements of the rate portion of the state.
Expand Down
7 changes: 7 additions & 0 deletions src/hash/rescue/rpx/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use alloc::vec::Vec;
use core::ops::Range;

use super::{
Expand Down Expand Up @@ -170,6 +171,12 @@ impl Hasher for Rpx256 {
RpxDigest::new(state[DIGEST_RANGE].try_into().unwrap())
}

fn merge_many(values: &[Self::Digest]) -> Self::Digest {
let elements: Vec<Felt> =
Self::Digest::digests_as_elements(values.iter()).copied().collect();
Self::hash_elements(&elements)
}

fn merge_with_int(seed: Self::Digest, value: u64) -> Self::Digest {
// initialize the state as follows:
// - seed is copied into the first 4 elements of the rate portion of the state.
Expand Down

0 comments on commit a323d76

Please sign in to comment.