Skip to content

Commit

Permalink
Refactor commit_inner_layers
Browse files Browse the repository at this point in the history
  • Loading branch information
alon-f committed Jan 14, 2025
1 parent 71516ef commit 21685f2
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions crates/prover/src/core/fri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ impl<'a, B: FriOps + MerkleOps<MC::H>, MC: MerkleChannel> FriProver<'a, B, MC> {

/// Builds and commits to the inner FRI layers (all layers except the first and last).
///
/// All `columns` must be provided in descending order by size.
/// All `columns` must be provided in descending order by size. Note there is at most one column
/// of each size.
///
/// Returns all inner layers and the evaluation of the last layer.
fn commit_inner_layers(
Expand All @@ -214,20 +215,26 @@ impl<'a, B: FriOps + MerkleOps<MC::H>, MC: MerkleChannel> FriProver<'a, B, MC> {
let mut layer_evaluation = LineEvaluation::new_zero(first_inner_layer_domain);
let mut columns = columns.iter().peekable();
let mut layers = Vec::new();
let mut folding_alpha = channel.draw_felt();
let folding_alpha = channel.draw_felt();

// Folding the max size column.
B::fold_circle_into_line(
&mut layer_evaluation,
columns.next().unwrap(),
folding_alpha,
twiddles,
);

while layer_evaluation.len() > config.last_layer_domain_size() {
// Check for circle polys in the first layer that should be combined in this layer.
while let Some(column) = columns.next_if(|c| folded_size(c) == layer_evaluation.len()) {
B::fold_circle_into_line(&mut layer_evaluation, column, folding_alpha, twiddles);
}

let layer = FriInnerLayerProver::new(layer_evaluation);
MC::mix_root(channel, layer.merkle_tree.root());
folding_alpha = channel.draw_felt();
let folded_layer_evaluation = B::fold_line(&layer.evaluation, folding_alpha, twiddles);
let folding_alpha = channel.draw_felt();
layer_evaluation = B::fold_line(&layer.evaluation, folding_alpha, twiddles);

layer_evaluation = folded_layer_evaluation;
// Check for circle polys in the first layer that should be combined in this layer.
if let Some(column) = columns.next_if(|c| folded_size(c) == layer_evaluation.len()) {
B::fold_circle_into_line(&mut layer_evaluation, column, folding_alpha, twiddles);
}
layers.push(layer);
}

Expand Down

0 comments on commit 21685f2

Please sign in to comment.