1
1
use std:: sync:: mpsc:: channel;
2
2
3
- use crate :: merkle:: MerkleTree ;
4
3
use crossbeam_utils:: thread;
4
+ use rayon:: prelude:: * ;
5
5
use serde:: de:: Deserialize ;
6
6
use serde:: ser:: Serialize ;
7
7
use slog:: * ;
@@ -11,6 +11,7 @@ use crate::drgporep::{self, DrgPoRep};
11
11
use crate :: drgraph:: Graph ;
12
12
use crate :: error:: { Error , Result } ;
13
13
use crate :: hasher:: { Domain , HashFunction , Hasher } ;
14
+ use crate :: merkle:: MerkleTree ;
14
15
use crate :: parameter_cache:: ParameterSetIdentifier ;
15
16
use crate :: porep:: { self , PoRep } ;
16
17
use crate :: proof:: ProofScheme ;
@@ -172,53 +173,50 @@ pub trait Layers {
172
173
> ] ,
173
174
layers : usize ,
174
175
total_layers : usize ,
175
- proofs : & ' a mut Vec < Vec < EncodingProof < Self :: Hasher > > > ,
176
176
partition_count : usize ,
177
- ) -> Result < & ' a Vec < Vec < EncodingProof < Self :: Hasher > > > > {
177
+ ) -> Result < Vec < Vec < EncodingProof < Self :: Hasher > > > > {
178
178
assert ! ( layers > 0 ) ;
179
179
180
- let new_priv_inputs = drgporep:: PrivateInputs {
181
- aux : & porep:: ProverAux {
182
- tree_d : aux[ 0 ] . clone ( ) ,
183
- tree_r : aux[ 1 ] . clone ( ) ,
184
- } ,
185
- } ;
180
+ let mut new_pp = None ;
186
181
187
- let mut partition_proofs = Vec :: with_capacity ( partition_count) ;
188
-
189
- for k in 0 ..partition_count {
190
- let drgporep_pub_inputs = drgporep:: PublicInputs {
191
- replica_id : pub_inputs. replica_id ,
192
- challenges : pub_inputs. challenges (
193
- pp. graph . size ( ) ,
194
- ( total_layers - layers) as u8 ,
195
- Some ( k) ,
196
- ) ,
197
- tau : Some ( tau[ 0 ] ) ,
198
- } ;
199
- let drg_proof = DrgPoRep :: prove ( & pp, & drgporep_pub_inputs, & new_priv_inputs) ?;
182
+ ( 0 ..layers)
183
+ . map ( |layer| {
184
+ let pp = match new_pp {
185
+ Some ( ref new_pp) => new_pp,
186
+ None => pp,
187
+ } ;
188
+ let inner_layers = layers - layer;
200
189
201
- partition_proofs. push ( drg_proof) ;
202
- }
190
+ let new_priv_inputs = drgporep:: PrivateInputs {
191
+ aux : & porep:: ProverAux {
192
+ tree_d : aux[ layer] . clone ( ) ,
193
+ tree_r : aux[ layer + 1 ] . clone ( ) ,
194
+ } ,
195
+ } ;
196
+ let layer_diff = total_layers - inner_layers;
197
+
198
+ let partition_proofs: Vec < _ > = ( 0 ..partition_count)
199
+ . into_par_iter ( )
200
+ . map ( |k| {
201
+ let drgporep_pub_inputs = drgporep:: PublicInputs {
202
+ replica_id : pub_inputs. replica_id ,
203
+ challenges : pub_inputs. challenges (
204
+ pp. graph . size ( ) ,
205
+ layer_diff as u8 ,
206
+ Some ( k) ,
207
+ ) ,
208
+ tau : Some ( tau[ layer] ) ,
209
+ } ;
203
210
204
- proofs. push ( partition_proofs) ;
205
-
206
- let pp = & Self :: transform ( pp, total_layers - layers, total_layers) ;
207
-
208
- if layers != 1 {
209
- Self :: prove_layers (
210
- pp,
211
- pub_inputs,
212
- & tau[ 1 ..] ,
213
- & aux[ 1 ..] ,
214
- layers - 1 ,
215
- total_layers,
216
- proofs,
217
- partition_count,
218
- ) ?;
219
- }
211
+ DrgPoRep :: prove ( pp, & drgporep_pub_inputs, & new_priv_inputs)
212
+ } )
213
+ . collect :: < Result < Vec < _ > > > ( ) ?;
220
214
221
- Ok ( proofs)
215
+ new_pp = Some ( Self :: transform ( pp, layer_diff, total_layers) ) ;
216
+
217
+ Ok ( partition_proofs)
218
+ } )
219
+ . collect :: < Result < Vec < _ > > > ( )
222
220
}
223
221
224
222
fn extract_and_invert_transform_layers < ' a > (
@@ -418,26 +416,23 @@ impl<'a, L: Layers> ProofScheme<'a> for L {
418
416
priv_inputs : & ' b Self :: PrivateInputs ,
419
417
partition_count : usize ,
420
418
) -> Result < Vec < Self :: Proof > > {
421
- let mut proofs = Vec :: with_capacity ( pub_params . layers ) ;
419
+ assert ! ( partition_count > 0 ) ;
422
420
423
- Self :: prove_layers (
421
+ let proofs = Self :: prove_layers (
424
422
& pub_params. drg_porep_public_params ,
425
423
pub_inputs,
426
424
& priv_inputs. tau ,
427
425
& priv_inputs. aux ,
428
426
pub_params. layers ,
429
427
pub_params. layers ,
430
- & mut proofs,
431
428
partition_count,
432
429
) ?;
433
430
434
- assert ! ( partition_count > 0 ) ;
435
431
let mut proof_columns = vec ! [ Vec :: new( ) ; partition_count] ;
436
432
437
- // TODO: Avoid all the cloning
438
- for partition_proofs in & proofs {
439
- for ( j, proof) in partition_proofs. iter ( ) . enumerate ( ) {
440
- proof_columns[ j] . push ( proof. clone ( ) ) ;
433
+ for partition_proofs in proofs. into_iter ( ) {
434
+ for ( j, proof) in partition_proofs. into_iter ( ) . enumerate ( ) {
435
+ proof_columns[ j] . push ( proof) ;
441
436
}
442
437
}
443
438
0 commit comments