Skip to content

Commit

Permalink
fixed HashChallenger: adding trait implementations for CanObserve and…
Browse files Browse the repository at this point in the history
… FieldChallenger
  • Loading branch information
olegfomenko committed Jan 10, 2025
1 parent b0591e9 commit 846bbfa
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
41 changes: 36 additions & 5 deletions challenger/src/hash_challenger.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use alloc::vec;
use alloc::vec::Vec;
use p3_field::Field;
use p3_symmetric::{CryptographicHasher, CryptographicPermutation};

use p3_symmetric::CryptographicHasher;

use crate::{CanObserve, CanSample};
use crate::{CanObserve, CanSample, CanSampleBits, FieldChallenger};

#[derive(Clone, Debug)]
pub struct HashChallenger<T, H, const OUT_LEN: usize>
Expand Down Expand Up @@ -54,7 +54,7 @@ where
}

impl<T, H, const N: usize, const OUT_LEN: usize> CanObserve<[T; N]>
for HashChallenger<T, H, OUT_LEN>
for HashChallenger<T, H, OUT_LEN>
where
T: Clone,
H: CryptographicHasher<T, [T; OUT_LEN]>,
Expand All @@ -81,6 +81,37 @@ where
}
}

impl<T, H, const OUT_LEN: usize> CanObserve<Vec<T>> for HashChallenger<T, H, OUT_LEN>
where
T: Clone,
H: CryptographicHasher<T, [T; OUT_LEN]>,
{
fn observe(&mut self, values: Vec<T>) {
for v in values {
self.observe(v);
}
}
}

impl<T, H, const OUT_LEN: usize> CanObserve<Vec<Vec<T>>> for HashChallenger<T, H, OUT_LEN>
where
T: Clone,
H: CryptographicHasher<T, [T; OUT_LEN]>,
{
fn observe(&mut self, values: Vec<Vec<T>>) {
for v in values {
self.observe(v);
}
}
}

impl<T, H, const OUT_LEN: usize> FieldChallenger<T> for HashChallenger<T, H, OUT_LEN>
where
T: Field,
H: CryptographicHasher<T, [T; OUT_LEN]> + Sync,
{
}

#[cfg(test)]
mod tests {
use p3_field::FieldAlgebra;
Expand Down Expand Up @@ -168,4 +199,4 @@ mod tests {
[F::from_canonical_u8(new_expected_sum)]
)
}
}
}
2 changes: 1 addition & 1 deletion challenger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub trait CanSampleBits<T> {
}

pub trait FieldChallenger<F: Field>:
CanObserve<F> + CanSample<F> + CanSampleBits<usize> + Sync
CanObserve<F> + CanSample<F> + Sync
{
fn observe_ext_element<EF: FieldExtensionAlgebra<F>>(&mut self, ext: EF) {
self.observe_slice(ext.as_base_slice());
Expand Down

0 comments on commit 846bbfa

Please sign in to comment.