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 31e8dbc commit 4e670fb
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions crates/prover/src/core/fri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,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 @@ -217,23 +218,29 @@ impl<'a, B: FriOps + MerkleOps<MC::H>, MC: MerkleChannel> FriProver<'a, B, MC> {
let mut columns = columns.iter().peekable();
let mut layers = Vec::new();

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

while layer_evaluation.len() > config.last_layer_domain_size() {
let layer = FriInnerLayerProver::new(layer_evaluation);
MC::mix_root(channel, layer.merkle_tree.root());
let folding_alpha = channel.draw_felt();
layer_evaluation = B::fold_line(&layer.evaluation, folding_alpha, twiddles);

// 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()) {
if let Some(column) = columns.next_if(|c| folded_size(c) == layer_evaluation.len()) {
B::fold_circle_into_line(
&mut layer_evaluation,
column,
circle_poly_folding_alpha,
twiddles,
);
}

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

layer_evaluation = folded_layer_evaluation;
layers.push(layer);
}

Expand Down

0 comments on commit 4e670fb

Please sign in to comment.