Skip to content

Commit

Permalink
refactor: rename SynthChallenges to SynthChallengeGenerator
Browse files Browse the repository at this point in the history
Renaming the `SynthChallenges` struct int `SynthChallengeGenerator` in order
to make clear that those are not the actual challenges, but that it's an object
to generate challenges.
  • Loading branch information
vmx committed Dec 5, 2023
1 parent 3552c81 commit c0ad725
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
36 changes: 15 additions & 21 deletions storage-proofs-porep/src/stacked/vanilla/challenges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,8 @@ impl LayerChallenges {
let partition_challenge_count = self.challenges_count_all();
let replica_id: Fr = (*replica_id).into();
let comm_r: Fr = (*comm_r).into();
SynthChallenges::default(sector_nodes, &replica_id, &comm_r).gen_porep_partition_challenges(
partition_challenge_count,
seed,
k as usize,
)
SynthChallengeGenerator::default(sector_nodes, &replica_id, &comm_r)
.gen_porep_partition_challenges(partition_challenge_count, seed, k as usize)
}

/// Returns the synthetic challenge indexes of the porep challenges for partition `k`.
Expand All @@ -125,11 +122,8 @@ impl LayerChallenges {
let partition_challenge_count = self.challenges_count_all();
let replica_id: Fr = (*replica_id).into();
let comm_r: Fr = (*comm_r).into();
SynthChallenges::default(sector_nodes, &replica_id, &comm_r).gen_partition_synth_indexes(
partition_challenge_count,
seed,
k as usize,
)
SynthChallengeGenerator::default(sector_nodes, &replica_id, &comm_r)
.gen_partition_synth_indexes(partition_challenge_count, seed, k as usize)
}

/// Returns the entire synthetic challenge set.
Expand All @@ -142,7 +136,7 @@ impl LayerChallenges {
assert!(self.use_synthetic);
let replica_id: Fr = (*replica_id).into();
let comm_r: Fr = (*comm_r).into();
let synth = SynthChallenges::default(sector_nodes, &replica_id, &comm_r);
let synth = SynthChallengeGenerator::default(sector_nodes, &replica_id, &comm_r);
trace!(
"generating entire synthetic challenge set (num_synth_challenges = {})",
synth.num_synth_challenges,
Expand Down Expand Up @@ -204,7 +198,7 @@ pub(crate) mod synthetic {
ChaCha20::new(key.as_bytes().into(), CHACHA20_NONCE.into())
}

pub(crate) struct SynthChallenges {
pub(crate) struct SynthChallengeGenerator {
sector_nodes: usize,
replica_id: [u8; 32],
comm_r: [u8; 32],
Expand All @@ -218,9 +212,9 @@ pub(crate) mod synthetic {
i: usize,
}

impl Clone for SynthChallenges {
impl Clone for SynthChallengeGenerator {
fn clone(&self) -> Self {
let mut synth = SynthChallenges {
let mut synth = Self {
sector_nodes: self.sector_nodes,
replica_id: self.replica_id,
comm_r: self.comm_r,
Expand All @@ -233,7 +227,7 @@ pub(crate) mod synthetic {
}
}

impl Iterator for SynthChallenges {
impl Iterator for SynthChallengeGenerator {
type Item = usize;

// Generates and returns the next synthetic challenge.
Expand All @@ -250,7 +244,7 @@ pub(crate) mod synthetic {
}
}

impl SynthChallenges {
impl SynthChallengeGenerator {
pub fn new(
sector_nodes: usize,
replica_id: &Fr,
Expand All @@ -264,7 +258,7 @@ pub(crate) mod synthetic {
let replica_id = replica_id.to_repr();
let comm_r = comm_r.to_repr();
let chacha20 = chacha20_gen(&replica_id, &comm_r);
SynthChallenges {
Self {
sector_nodes,
replica_id,
comm_r,
Expand All @@ -280,7 +274,7 @@ pub(crate) mod synthetic {
}

/// Seeks to the `i`-th synthetic challenge; seeking to `i` results in the next call to
/// `SynthChallenges::next` returning the `i`-th synthetic challenge.
/// `SynthChallengeGenerator::next` returning the `i`-th synthetic challenge.
pub(super) fn seek(&mut self, i: usize) {
self.chacha20
.try_seek((i * SYNTH_CHALLENGE_SIZE) as u32)
Expand Down Expand Up @@ -351,7 +345,7 @@ pub(crate) mod synthetic {
}
}

use synthetic::SynthChallenges;
use synthetic::SynthChallengeGenerator;

#[cfg(test)]
mod test {
Expand Down Expand Up @@ -441,7 +435,7 @@ mod test {
let replica_id = Fr::from(thread_rng().next_u64());
let comm_r = Fr::from(thread_rng().next_u64());

let mut synth = SynthChallenges::default(sector_nodes, &replica_id, &comm_r);
let mut synth = SynthChallengeGenerator::default(sector_nodes, &replica_id, &comm_r);

// Test synthetic challenge generation.
let synth_challenges: Vec<usize> = synth.clone().collect();
Expand Down Expand Up @@ -487,7 +481,7 @@ mod test {
[176, 781, 801, 986, 290, 211, 692, 856, 986, 332];

let mut synth =
SynthChallenges::new(sector_nodes, &replica_id, &comm_r, num_synth_challenges);
SynthChallengeGenerator::new(sector_nodes, &replica_id, &comm_r, num_synth_challenges);

// Test synthetic challenge generation against hardcoded challenges.
let synth_challenges: Vec<usize> = synth.clone().collect();
Expand Down
5 changes: 3 additions & 2 deletions storage-proofs-porep/src/stacked/vanilla/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr
num_layers: usize,
path: PathBuf,
) -> Result<()> {
use crate::stacked::vanilla::challenges::synthetic::SynthChallenges;
use crate::stacked::vanilla::challenges::synthetic::SynthChallengeGenerator;

ensure!(
pub_inputs.tau.is_some(),
Expand All @@ -413,7 +413,8 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr
.as_ref()
.map(|tau| tau.comm_r.into())
.expect("unwrapping should not fail");
let synth_challenges = SynthChallenges::default(graph.size(), &replica_id, &comm_r);
let synth_challenges =
SynthChallengeGenerator::default(graph.size(), &replica_id, &comm_r);
assert_eq!(synth_proofs.len(), synth_challenges.num_synth_challenges);
for (challenge, proof) in synth_challenges.zip(synth_proofs) {
let proof_inner = proof.clone();
Expand Down

0 comments on commit c0ad725

Please sign in to comment.