Skip to content

Commit e064fa2

Browse files
committed
Correct randomness indexing
1 parent 485beec commit e064fa2

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

spartan_parallel/src/custom_dense_mlpoly.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ impl<S: SpartanExtensionField> DensePolynomialPqx<S> {
236236
let num_witness_secs = min(self.num_witness_secs, inst[0].len());
237237
let num_inputs = self.num_inputs[p];
238238

239+
// debug
240+
println!("[");
241+
inst.iter().for_each(|mat| println!("{:?}, ", mat[0][0]));
242+
println!("]");
243+
println!();
244+
239245
if sub_levels > 0 {
240246
let thread_split_inst = (0..num_threads)
241247
.map(|_| {
@@ -247,7 +253,7 @@ impl<S: SpartanExtensionField> DensePolynomialPqx<S> {
247253
inst = thread_split_inst
248254
.into_par_iter()
249255
.map(|mut chunk| {
250-
fold(&mut chunk, r_q, 0, 1, sub_levels, num_witness_secs, num_inputs);
256+
fold(&mut chunk, r_q, 0, 1, sub_levels, 0, num_witness_secs, num_inputs);
251257
chunk
252258
})
253259
.collect::<Vec<Vec<Vec<Vec<S>>>>>()
@@ -256,7 +262,7 @@ impl<S: SpartanExtensionField> DensePolynomialPqx<S> {
256262

257263
if final_levels > 0 {
258264
// aggregate the final result from sub-threads outputs using a single core
259-
fold(&mut inst, r_q, 0, dist_size, final_levels, num_witness_secs, num_inputs);
265+
fold(&mut inst, r_q, 0, dist_size, final_levels + sub_levels, sub_levels, num_witness_secs, num_inputs);
260266
}
261267

262268
if left_over_q_len > 0 {
@@ -329,20 +335,20 @@ impl<S: SpartanExtensionField> DensePolynomialPqx<S> {
329335
}
330336
}
331337

332-
fn fold<S: SpartanExtensionField>(proofs: &mut Vec<Vec<Vec<S>>>, r_q: &[S], idx: usize, step: usize, lvl: usize, w: usize, x: usize) {
333-
if lvl > 0 {
334-
fold(proofs, r_q, 2 * idx, step, lvl - 1, w, x);
335-
fold(proofs, r_q, 2 * idx + step, step, lvl - 1, w, x);
338+
fn fold<S: SpartanExtensionField>(proofs: &mut Vec<Vec<Vec<S>>>, r_q: &[S], idx: usize, step: usize, lvl: usize, final_lvl: usize, w: usize, x: usize) {
339+
if lvl > final_lvl {
340+
fold(proofs, r_q, 2 * idx, step, lvl - 1, final_lvl, w, x);
341+
fold(proofs, r_q, 2 * idx + step, step, lvl - 1, final_lvl, w, x);
336342

337-
let r1 = S::field_one() - r_q[lvl];
338-
let r2 = r_q[lvl];
343+
let r1 = S::field_one() - r_q[lvl - 1];
344+
let r2 = r_q[lvl - 1];
339345

340346
(0..w).for_each(|w| {
341347
(0..x).for_each(|x| {
342348
proofs[idx][w][x] = r1 * proofs[idx * 2][w][x] + r2 * proofs[idx * 2 + step][w][x];
343349
});
344350
});
345351
} else {
346-
// level 0. do nothing
352+
// base level. do nothing
347353
}
348354
}

0 commit comments

Comments
 (0)