Skip to content

Commit 20fe6da

Browse files
committed
address feedback
1 parent c322612 commit 20fe6da

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

circuits/plonk-15-wires/src/nolookup/constraints.rs

+21-25
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ pub struct ConstraintSystem<F: FftField> {
173173
pub lookup_selectors: Vec<E<F, D<F>>>,
174174
}
175175

176-
/// Shifts represent the shifts required in the permutation argument of PLONK
176+
/// Shifts represent the shifts required in the permutation argument of PLONK.
177+
/// It also caches the shifted powers of omega for optimization purposes.
177178
pub struct Shifts<F> {
178179
/// The coefficients k that create a coset when multiplied with the generator of our domain.
179180
shifts: [F; PERMUTS],
@@ -197,11 +198,12 @@ where
197198
// sample the other shifts
198199
let mut i: u32 = 7;
199200
for idx in 1..(PERMUTS) {
200-
let mut o = Self::sample(&domain, &mut i);
201-
while shifts.iter().filter(|&r| o == *r).count() > 0 {
202-
o = Self::sample(&domain, &mut i);
201+
let mut shift = Self::sample(&domain, &mut i);
202+
// they have to be distincts
203+
while shifts.contains(&shift) {
204+
shift = Self::sample(&domain, &mut i);
203205
}
204-
shifts[idx] = o;
206+
shifts[idx] = shift;
205207
}
206208

207209
// create a map of cells to their shifted value
@@ -213,28 +215,23 @@ where
213215
}
214216

215217
/// sample coordinate shifts deterministically
216-
fn sample(domain: &D<F>, i: &mut u32) -> F {
218+
fn sample(domain: &D<F>, input: &mut u32) -> F {
217219
let mut h = Blake2b::new();
218-
h.update(
219-
&{
220-
*i += 1;
221-
*i
222-
}
223-
.to_be_bytes(),
224-
);
225-
let mut r = F::from_random_bytes(&h.finalize()[..31]).unwrap();
226-
while r.legendre().is_qnr() == false || domain.evaluate_vanishing_polynomial(r).is_zero() {
220+
221+
*input += 1;
222+
h.update(&input.to_be_bytes());
223+
224+
let mut shift = F::from_random_bytes(&h.finalize()[..31])
225+
.expect("our field elements fit in more than 31 bytes");
226+
227+
while !shift.legendre().is_qnr() || domain.evaluate_vanishing_polynomial(shift).is_zero() {
227228
let mut h = Blake2b::new();
228-
h.update(
229-
&{
230-
*i += 1;
231-
*i
232-
}
233-
.to_be_bytes(),
234-
);
235-
r = F::from_random_bytes(&h.finalize()[..31]).unwrap();
229+
*input += 1;
230+
h.update(&input.to_be_bytes());
231+
shift = F::from_random_bytes(&h.finalize()[..31])
232+
.expect("our field elements fit in more than 31 bytes");
236233
}
237-
r
234+
shift
238235
}
239236

240237
/// Returns the field element that represents a position
@@ -347,7 +344,6 @@ impl<F: FftField + SquareRootField> ConstraintSystem<F> {
347344
gates.append(&mut padding);
348345

349346
// sample the coordinate shifts
350-
// TODO(mimoo): should we check that the shifts are all different?
351347
let shifts = Shifts::new(&domain.d1);
352348

353349
// compute permutation polynomials

0 commit comments

Comments
 (0)