Skip to content

Commit

Permalink
refactor: make prove_layers_generate operate on a single partition
Browse files Browse the repository at this point in the history
`prove_layers_generate()` now operates on a single partition. This makes it
clearer that Synthetic PoReps always operate on a single partition only.

With the challenge generation moved outside of this function, it's also a
clearer separation of concerns, as it now operates directly on the challenges
given, without know anything about how they were generated. This also useful
for the work of having small, special case binaries for certain operations.
  • Loading branch information
vmx committed Oct 2, 2023
1 parent 3f7c9eb commit 4f46216
Showing 1 changed file with 43 additions and 34 deletions.
77 changes: 43 additions & 34 deletions storage-proofs-porep/src/stacked/vanilla/proof.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -112,24 +112,27 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr
// If there are no synthetic vanilla proofs stored on disk yet, generate them. // If there are no synthetic vanilla proofs stored on disk yet, generate them.
if pub_inputs.seed.is_none() { if pub_inputs.seed.is_none() {
info!("generating synthetic vanilla proofs in a single partition"); info!("generating synthetic vanilla proofs in a single partition");
assert_eq!(partition_count, 1);


let vanilla_proofs = Self::prove_layers_generate( let comm_r = pub_inputs.tau.as_ref().expect("tau is set").comm_r;
// Derive the set of challenges we are proving over.
let challenges = layer_challenges.derive_synthetic(
graph.size(),
&pub_inputs.replica_id,
&comm_r,
);

let synth_proofs = Self::prove_layers_generate(
graph, graph,
pub_inputs, pub_inputs,
p_aux.comm_c, p_aux.comm_c,
t_aux, t_aux,
layer_challenges, challenges,
layers, layers,
partition_count,
)?; )?;


assert!(
vanilla_proofs.iter().skip(1).all(Vec::is_empty),
"synthetic proofs should be generated in a single partition",
);
let synth_proofs = &vanilla_proofs[0];
Self::write_synth_proofs( Self::write_synth_proofs(
synth_proofs, &synth_proofs,
pub_inputs, pub_inputs,
graph, graph,
layer_challenges, layer_challenges,
Expand All @@ -156,36 +159,53 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr
}) })
} }
} else { } else {
assert_eq!(t_aux.labels.len(), layers);
assert_eq!(
pub_inputs.tau.as_ref().expect("as_ref failure").comm_d,
t_aux.tree_d.as_ref().expect("failed to get tree_d").root()
);

info!("generating non-synthetic vanilla proofs"); info!("generating non-synthetic vanilla proofs");


let comm_r = pub_inputs.tau.as_ref().expect("tau is set").comm_r;
let seed = pub_inputs
.seed
.expect("seed must be set for non-synthetic vanilla proofs");

(0..partition_count)
.map(|k| {
trace!("proving partition {}/{}", k + 1, partition_count);

// Derive the set of challenges we are proving over.
let challenges = layer_challenges.derive(
graph.size(),
&pub_inputs.replica_id,
&comm_r,
&seed,
k as u8,
);

Self::prove_layers_generate( Self::prove_layers_generate(
graph, graph,
pub_inputs, pub_inputs,
p_aux.comm_c, p_aux.comm_c,
t_aux, t_aux,
layer_challenges, challenges,
layers, layers,
partition_count,
) )
})
.collect::<Result<Vec<Vec<Proof<Tree, G>>>>>()
} }
} }


#[allow(clippy::too_many_arguments)]
fn prove_layers_generate( fn prove_layers_generate(
graph: &StackedBucketGraph<Tree::Hasher>, graph: &StackedBucketGraph<Tree::Hasher>,
pub_inputs: &PublicInputs<<Tree::Hasher as Hasher>::Domain, <G as Hasher>::Domain>, pub_inputs: &PublicInputs<<Tree::Hasher as Hasher>::Domain, <G as Hasher>::Domain>,
comm_c: <Tree::Hasher as Hasher>::Domain, comm_c: <Tree::Hasher as Hasher>::Domain,
t_aux: &TemporaryAuxCache<Tree, G>, t_aux: &TemporaryAuxCache<Tree, G>,
layer_challenges: &LayerChallenges, challenges: Vec<usize>,
layers: usize, layers: usize,
partition_count: usize, ) -> Result<Vec<Proof<Tree, G>>> {
) -> Result<Vec<Vec<Proof<Tree, G>>>> { assert_eq!(t_aux.labels.len(), layers);
assert_eq!(
pub_inputs.tau.as_ref().expect("as_ref failure").comm_d,
t_aux.tree_d.as_ref().expect("failed to get tree_d").root()
);

let get_drg_parents_columns = |x: usize| -> Result<Vec<Column<Tree::Hasher>>> { let get_drg_parents_columns = |x: usize| -> Result<Vec<Column<Tree::Hasher>>> {
let base_degree = graph.base_graph().degree(); let base_degree = graph.base_graph().degree();


Expand Down Expand Up @@ -216,13 +236,6 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr
.collect() .collect()
}; };


(0..partition_count)
.map(|k| {
trace!("proving partition {}/{}", k + 1, partition_count);

// Derive the set of challenges we are proving over.
let challenges = pub_inputs.challenges(layer_challenges, graph.size(), Some(k));

THREAD_POOL.scoped(|scope| { THREAD_POOL.scoped(|scope| {
// Stacked commitment specifics // Stacked commitment specifics
challenges challenges
Expand All @@ -249,8 +262,7 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr
let rcp = { let rcp = {
let (c_x, drg_parents, exp_parents) = { let (c_x, drg_parents, exp_parents) = {
assert!(t_aux.tree_c.is_some()); assert!(t_aux.tree_c.is_some());
let tree_c = let tree_c = t_aux.tree_c.as_ref().expect("failed to get tree_c");
t_aux.tree_c.as_ref().expect("failed to get tree_c");
assert_eq!(comm_c, tree_c.root()); assert_eq!(comm_c, tree_c.root());


// All labels in C_X // All labels in C_X
Expand Down Expand Up @@ -299,8 +311,7 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr


for layer in 1..=layers { for layer in 1..=layers {
trace!(" encoding proof layer {}", layer,); trace!(" encoding proof layer {}", layer,);
let parents_data: Vec<<Tree::Hasher as Hasher>::Domain> = let parents_data: Vec<<Tree::Hasher as Hasher>::Domain> = if layer == 1 {
if layer == 1 {
let mut parents = vec![0; graph.base_graph().degree()]; let mut parents = vec![0; graph.base_graph().degree()];
graph.base_parents(challenge, &mut parents)?; graph.base_parents(challenge, &mut parents)?;


Expand Down Expand Up @@ -375,8 +386,6 @@ impl<'a, Tree: 'static + MerkleTreeTrait, G: 'static + Hasher> StackedDrg<'a, Tr
}) })
.collect() .collect()
}) })
})
.collect::<Result<Vec<Vec<Proof<Tree, G>>>>>()
} }


fn write_synth_proofs( fn write_synth_proofs(
Expand Down

0 comments on commit 4f46216

Please sign in to comment.