Skip to content

Commit

Permalink
fix implementing GrindingChallenger, CanSampleBits and CanObserve<T> …
Browse files Browse the repository at this point in the history
…for HashChallenger
  • Loading branch information
olegfomenko committed Jan 14, 2025
1 parent bd33b15 commit 7bb5f54
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
6 changes: 3 additions & 3 deletions challenger/src/grinding_challenger.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::cmp::min;
use p3_field::{Field, PrimeField, PrimeField32, PrimeField64};
use p3_maybe_rayon::prelude::*;
use p3_symmetric::CryptographicPermutation;
use p3_symmetric::{CryptographicHasher, CryptographicPermutation};
use tracing::instrument;

use crate::{CanObserve, CanSampleBits, DuplexChallenger, HashChallenger, MultiField32Challenger};
Expand Down Expand Up @@ -63,8 +63,8 @@ where

impl<F, P, const WIDTH: usize> GrindingChallenger for HashChallenger<F, P, WIDTH>
where
F: Field,
P: CryptographicPermutation<[F; WIDTH]>,
F: PrimeField,
P: CryptographicHasher<F, [F; WIDTH]> + Sync,
{
type Witness = F;

Expand Down
22 changes: 9 additions & 13 deletions challenger/src/hash_challenger.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use alloc::vec;
use alloc::vec::Vec;
use p3_field::Field;
use p3_symmetric::{CryptographicHasher, CryptographicPermutation};
use p3_field::{Field, PrimeField};
use p3_symmetric::CryptographicHasher;

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

Expand Down Expand Up @@ -83,23 +83,19 @@ where

impl<F, P, const OUT_LEN: usize> CanSampleBits<usize> for HashChallenger<F, P, OUT_LEN>
where
F: Field,
P: CryptographicPermutation<[F; OUT_LEN]>,
F: PrimeField,
P: CryptographicHasher<F, [F; OUT_LEN]>,
{
fn sample_bits(&mut self, bits: usize) -> usize {
let rand_f: F = self.sample();
let rand_usize = rand_f.as_canonical_u32() as usize;
let rand_usize = *rand_f
.as_canonical_biguint()
.to_u64_digits()
.first()
.unwrap() as usize;
rand_usize & ((1 << bits) - 1)
}
}
impl<T, P, const OUT_LEN: usize> CanObserve<T> for HashChallenger<T, P, OUT_LEN>
where
P: CryptographicPermutation<[T; OUT_LEN]>,
{
fn observe(&mut self, v: T) {
self.observe(v);
}
}

impl<T, H, const OUT_LEN: usize> CanObserve<Vec<T>> for HashChallenger<T, H, OUT_LEN>
where
Expand Down

0 comments on commit 7bb5f54

Please sign in to comment.