Skip to content

Commit

Permalink
Add LinePoly docstrings. Improve efficiency. Add assert to the last l…
Browse files Browse the repository at this point in the history
…evel.
  • Loading branch information
schouhy committed Jul 22, 2024
1 parent 0d6d3a9 commit 5493b37
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion stwo_cairo_verifier/src/poly/line.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
use stwo_cairo_verifier::fields::SecureField;
use stwo_cairo_verifier::fields::m31::m31;

/// A univariate polynomial represented by its coefficients in the line part of the FFT-basis {bᵢ}
/// in bit reversed order. See Definition 4 of the Circle STARKs paper
/// https://eprint.iacr.org/2024/278. The line part of the FFT-basis is formed by the elements bᵢ
/// with i even.
///
/// Example: The line part of the FFT of order 4 in natural order is {b₀, b₂, b₄, b₆}, where
/// b₀ = 1, b₂ = x, b₄ = 2x² − 1, and b₆ = x(2x² − 1). The same basis but in bit
/// reversed order is {b₀, b₄, b₂, b₆}.
/// Then, the polynomial p represented by coeffs = [a₀, a₁, a₂, a₃] and log_size = 2 is
/// p = a₀ * b₀ + a₁ * b₄ + a₂ * b₂ + a₃ * b₆.
#[derive(Drop, Clone)]
pub struct LinePoly {
pub coeffs: Array<SecureField>,
Expand All @@ -13,12 +23,14 @@ pub impl LinePolyImpl of LinePolyTrait {
self.coeffs.len()
}

// TODO: Consider replacing with FFT.
fn eval_at_point(self: @LinePoly, mut x: SecureField) -> SecureField {
let mut mappings = array![];
let mut i = 0;
while i < *self.log_size {
mappings.append(x);
x = m31(2).into() * x * x - m31(1).into();
let x_square = x * x;
x = x_square + x_square - m31(1).into();
i += 1;
};

Expand All @@ -37,6 +49,7 @@ pub impl LinePolyImpl of LinePolyTrait {
level = new_level;
};

assert_eq!(level.len(), 1);
*level[0]
}
}
Expand Down

0 comments on commit 5493b37

Please sign in to comment.