Skip to content

Commit 3b4d66d

Browse files
committed
fix(fri): fix bugs
1 parent f43ec89 commit 3b4d66d

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

  • plonkish/plonkish_backend/src/pcs/univariate

plonkish/plonkish_backend/src/pcs/univariate/fri.rs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,15 @@ where
269269
let mut roots = Vec::with_capacity(comms.len());
270270

271271
comms.iter().for_each(|comm| {
272-
let root = &comm.codeword_tree[comm.codeword_tree.len() - 1][0];
273-
roots.push(root);
272+
if comm.codeword.len() > 0 {
273+
let root = &comm.codeword_tree[comm.codeword_tree.len() - 1][0];
274+
roots.push(root.clone());
275+
} else {
276+
roots.push(Output::<H>::default());
277+
}
274278
});
275279

276-
transcript.write_commitments(roots).unwrap();
280+
transcript.write_commitments(roots.iter()).unwrap();
277281
Ok(comms)
278282
}
279283

@@ -287,6 +291,12 @@ where
287291
polys_vec
288292
.par_iter()
289293
.map(|poly| {
294+
if poly.coeffs().len() < 2 {
295+
return Ok(Self::Commitment {
296+
codeword: vec![],
297+
codeword_tree: vec![],
298+
});
299+
}
290300
let comm = Self::commit(pp, poly);
291301
comm
292302
})
@@ -306,6 +316,10 @@ where
306316
// let key = "RAYON_NUM_THREADS";
307317
// env::set_var(key, "8");
308318

319+
if comm.codeword.len() == 0 {
320+
return Ok(());
321+
}
322+
309323
open_helper(pp, poly, comm, point, eval, transcript).0
310324
}
311325

@@ -339,7 +353,16 @@ where
339353

340354
Ok(roots
341355
.iter()
342-
.map(|r| FriCommitment::from_root(r.clone()))
356+
.map(|r| {
357+
if *r != Output::<H>::default() {
358+
FriCommitment::from_root(r.clone())
359+
} else {
360+
Self::Commitment {
361+
codeword: vec![],
362+
codeword_tree: vec![],
363+
}
364+
}
365+
})
343366
.collect_vec())
344367
}
345368

@@ -350,6 +373,9 @@ where
350373
eval: &F,
351374
transcript: &mut impl TranscriptRead<Self::CommitmentChunk, F>,
352375
) -> Result<(), Error> {
376+
if comm.codeword.len() == 0 {
377+
return Ok(());
378+
}
353379
verify_helper(vp, comm, point, eval, transcript).0
354380
}
355381

@@ -906,7 +932,9 @@ fn commit_phase<F: PrimeField, H: Hash>(
906932

907933
new_oracle = &oracles[i];
908934
trees.push(merkelize::<F, H>(&new_oracle));
909-
root = trees[i][trees[i].len() - 1][0].clone();
935+
if trees[i].len() > 0 && trees[i][0].len() > 0 {
936+
root = trees[i][trees[i].len() - 1][0].clone();
937+
}
910938
}
911939

912940
transcript.write_commitment(&root).unwrap();

0 commit comments

Comments
 (0)