Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FRI folded layers domain #368

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions fri/src/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,30 @@ where

// reduce the degree by folding_factor at each iteration until the remaining polynomial
// has small enough degree
let mut domain_offset = self.options.domain_offset();
for _ in 0..self.options.num_fri_layers(evaluations.len()) {
match self.folding_factor() {
2 => self.build_layer::<2>(channel, &mut evaluations),
4 => self.build_layer::<4>(channel, &mut evaluations),
8 => self.build_layer::<8>(channel, &mut evaluations),
16 => self.build_layer::<16>(channel, &mut evaluations),
2 => self.build_layer::<2>(channel, &mut evaluations, domain_offset),
4 => self.build_layer::<4>(channel, &mut evaluations, domain_offset),
8 => self.build_layer::<8>(channel, &mut evaluations, domain_offset),
16 => self.build_layer::<16>(channel, &mut evaluations, domain_offset),
_ => unimplemented!("folding factor {} is not supported", self.folding_factor()),
}

domain_offset = domain_offset.exp_vartime((self.folding_factor() as u32).into());
}

self.set_remainder(channel, &mut evaluations);
}

/// Builds a single FRI layer by first committing to the `evaluations`, then drawing a random
/// alpha from the channel and use it to perform degree-respecting projection.
fn build_layer<const N: usize>(&mut self, channel: &mut C, evaluations: &mut Vec<E>) {
fn build_layer<const N: usize>(
&mut self,
channel: &mut C,
evaluations: &mut Vec<E>,
domain_offset: E::BaseField,
) {
// commit to the evaluations at the current layer; we do this by first transposing the
// evaluations into a matrix of N columns, then hashing each row into a digest, and finally
// commiting to vector of these digests; we do this so that we could de-commit to N values
Expand All @@ -213,7 +221,7 @@ where
// draw a pseudo-random coefficient from the channel, and use it in degree-respecting
// projection to reduce the degree of evaluations by N
let alpha = channel.draw_fri_alpha();
*evaluations = apply_drp(&transposed_evaluations, self.domain_offset(), alpha);
*evaluations = apply_drp(&transposed_evaluations, domain_offset, alpha);
self.layers.push(FriLayer {
commitment: evaluation_vector_commitment,
evaluations: flatten_vector_elements(transposed_evaluations),
Expand Down
4 changes: 3 additions & 1 deletion fri/src/verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ where
let mut max_degree_plus_1 = self.max_poly_degree + 1;
let mut positions = positions.to_vec();
let mut evaluations = evaluations.to_vec();
let mut domain_offset = self.options.domain_offset();

for depth in 0..self.options.num_fri_layers(self.domain_size) {
// determine which evaluations were queried in the folded layer
Expand All @@ -275,7 +276,7 @@ where
// build a set of x coordinates for each row polynomial
#[rustfmt::skip]
let xs = folded_positions.iter().map(|&i| {
let xe = domain_generator.exp_vartime((i as u64).into()) * self.options.domain_offset();
let xe = domain_generator.exp_vartime((i as u64).into()) * domain_offset;
folding_roots.iter()
.map(|&r| E::from(xe * r))
.collect::<Vec<_>>().try_into().unwrap()
Expand All @@ -302,6 +303,7 @@ where
max_degree_plus_1 /= N;
domain_size /= N;
mem::swap(&mut positions, &mut folded_positions);
domain_offset = domain_offset.exp_vartime((N as u32).into());
}

// 2 ----- verify the remainder polynomial of the FRI proof -------------------------------
Expand Down