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

Circle starks #924

Merged
merged 86 commits into from
Nov 4, 2024
Merged

Circle starks #924

merged 86 commits into from
Nov 4, 2024

Conversation

ColoCarletti
Copy link
Contributor

@ColoCarletti ColoCarletti commented Oct 4, 2024

Circle Starks

This PR introduces the foundational components necessary for the Circle Starks protocol implementation.

Key Features:

  • Mersenne-31 field: Incorporates the Mersenne-31 field, its quadratic and quartic extensions, along with all required operations.
  • Circle group: Defines the circle group and implements operations between its elements.
  • Sets and cosets: Generates sets and cosets to construct the necessary domains within the circle group.
  • CFFT: Implements the Circle Fast Fourier Transform (CFFT) for both interpolation and evaluation of the bivariate polynomial used in the Circle Starks protocol.

Type of change

  • New feature

Checklist

  • Linked to Github Issue
  • Unit tests added
  • This change requires new documentation.
    • Documentation has been added/updated.
  • This change is an Optimization
    • Benchmarks added/run

/// As a result we obtain the coefficients of the polynomial in the basis: {1, y, x, xy, 2xˆ2 -1, 2xˆ2y-y, 2xˆ3-x, 2xˆ3y-xy,...}
/// Note that eval has to be a vector of length a power of two 2^n.
#[cfg(feature = "alloc")]
pub fn interpolate_cfft(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an optimization, we could just send the twiddles as input to the function. This is useful when we have to interpolate multiple columns

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We believe that reusing twiddles for different polynomials within the same domain would be better handled by a dedicated function, rather than incorporating it here. Its implementation should depend on specific protocol requirements.

/// returns the evaluation of the polynomial on the points of the standard coset of size 2^n.
/// Note that coeff has to be a vector with length a power of two 2^n.
#[cfg(feature = "alloc")]
pub fn evaluate_cfft(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment to the one after this one. Twiddles could be given as inputs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the previous comment.

pub fn order_cfft_result_naive(
input: &mut [FieldElement<Mersenne31Field>],
) -> Vec<FieldElement<Mersenne31Field>> {
let mut result = Vec::new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can use interleave

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would not solve the memory usage problem. There is a way to do it in-place recursively, but we thought it would be better to implement that when we need to optimize.

Copy link
Collaborator

@ilitteri ilitteri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR is looking good! Left more comments.

As a side note, if we use an unwrap and we're 100% sure that it won't panic, let's add an explanation either as function docs (this is done under a /// # Panics section) or as a comment above the line.

math/src/circle/twiddles.rs Show resolved Hide resolved
math/src/circle/polynomial.rs Show resolved Hide resolved
math/src/circle/point.rs Outdated Show resolved Hide resolved
math/src/circle/point.rs Outdated Show resolved Hide resolved
math/src/circle/point.rs Outdated Show resolved Hide resolved
math/src/circle/point.rs Outdated Show resolved Hide resolved
math/src/circle/point.rs Outdated Show resolved Hide resolved
math/src/circle/point.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@ilitteri ilitteri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Great work!

@ColoCarletti ColoCarletti added this pull request to the merge queue Nov 4, 2024
Merged via the queue into main with commit 8dfddac Nov 4, 2024
8 checks passed
@ColoCarletti ColoCarletti deleted the circle-starks branch November 4, 2024 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants