bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 73쪽 중 50쪽
er_components)**: Details the `ComponentProvers` struct and its specialized functions for computing composition polynomials during the proving process, including the main `compute_composition_polynomial` function.
# Technical Overview
Source: https://docs.starknet.io/learn/S-two-book/how-it-works/air/overview
As shown in an earlier section (refer to [Components](/learn/S-two-book/air-development/components/index)), S-two represents the trace using multiple tables where each table is referred to as a *component*. An AIR in S-two is a collection of multiple components. Components can interact with one another, and the consistency of these interactions is verified using [*logUp*](https://eprint.iacr.org/2022/1530.pdf).
For example, in the [hash function example](/learn/S-two-book/air-development/components/index#hash-function-example), the scheduling component and computing component interact with each other, where both the components lookup the input and output pair. The consistency of this interaction is then verified by adding logUp constraints to each component.
Each component consists of a trace table of a specific height along with a set of constraints. These constraints include computation constraints as well as lookup constraints (refer to [Lookups](/learn/S-two-book/how-it-works/lookups)).
This section provides an overview of how these components are converted into a composition polynomial. This composition polynomial is then used by a polynomial commitment scheme to commit and generate evaluation proofs.
## AIR to Composition Polynomial
This section explains how a composition polynomial is computed using an example.
Consider an AIR composed of two components with trace tables: $\mathscr{T}_0$ and $\mathscr{T}_1$. The component table $\mathscr{T}_0$ is defined over the trace domain $D_{n_0}$, which is a [canonic coset](/learn/S-two-book/how-it-works/circle-group#canonic-coset) of size $N_0 = 2^{n_0}$. Similarly, component table $\mathscr{T}_1$ is defined over the trace domain $D_{n_1}$ of size $N_1 = 2^{n_1}$.
The prover interpolates the trace polynomials for each component and then evaluates the trace polynomials over an evaluation domain that is a blowup factor $B = 2^\beta$ times larger than the trace domain. Thus, the evaluation domain for component table $\mathscr{T}_0$ is $D_{n_0 + \beta}$ of size $2^{n_0 + \beta}$. Similarly, the evaluation domain for component table $\mathscr{T}_1$ is $D_{n_1 + \beta}$ of size $2^{n_1 + \beta}$. Both interpolation and evaluation use [circle FFT](/learn/S-two-book/how-it-works/circle-fft/index). The prover then commits to the evaluations of trace polynomials from all components using a single [Merkle tree](/learn/S-two-book/how-it-works/vcs/index).
Both component tables define computation constraints and lookup constraints for their specific component. The component constraints are proven table-wise, each with its separate domain quotient, which are then combined into a single cross-domain composition polynomial. Suppose the component tables $\mathscr{T}_0$ and $\mathscr{T}_1$ have a total of $c_0$ and $c_1$ constraints, respectively.
The verifier sends $\gamma \in \mathsf{QM31}$ to the prover. We use the same $\gamma$ to combine all constraints across different component tables. First, $\gamma$ is used to compute the random linear combination of all constraints on component $\mathscr{T}_0$ to obtain the component-level composition polynomial $p_0$. Then, the prover uses the same $\gamma$ to compute the component-level composition polynomial $p_1$ for component $\mathscr{T}_1$.
The prover then computes the quotient for component table $\mathscr{T}_0$ as $q_0 = p_0 / v_{n_0}$, where $v_{n_0}$ is the vanishing polynomial for trace domain $D_{n_0}$. Similarly, the prover computes the quotient for component table $\mathscr{T}_1$ as $q_1 = p_1 / v_{n_1}$.
Finally, the prover computes the cross-domain composition polynomial as
$$
q = q_0 + \gamma^{c_0} \cdot q_1
$$
where $c_0$ is the total number of constraints of the component table $\mathscr{T}_0$.
The next section examines how these concepts are implemented.
# Prover Components
Source: https://docs.starknet.io/learn/S-two-book/how-it-works/air/prover_components
The `ComponentProvers` struct is similar to the `Components` struct but implements additional functions required by the prover, such as computing the composition polynomial. It is a collection of prover components as follows:
```rust theme={null}
pub struct ComponentProvers<'a, B: Backend> {
pub components: Vec<&'a dyn ComponentProver<B>>,
pub n_preprocessed_columns: usize,
}
```
Here, `components` is a collection of objects that implement the `ComponentProver` trait. The `ComponentProver` trait is a wrapper around the `Component` trait with an additional function shown as follows:
```rust theme={null}
pub trait ComponentProver<B: Backend>: Component {
/// Evaluates the constraint quotients of the component on the evaluation domain.
/// Accumulates quotients in `evaluation_accumulator`.
fn evaluate_constraint_quotients_on_domain(
&self,
trace: &Trace<'_, B>,
evaluation_accumulator: &mut DomainEvaluationAccumulator<B>,
);
}
```
We can convert the `ComponentProvers` into a `Components` struct as follows:
```rust theme={null}
pub fn components(&self) -> Components<'_> {
Components {
components: self
.components
.iter()
.map(|c| *c as &dyn Component)
.collect_vec(),
n_preprocessed_columns: self.n_preprocessed_columns,
}
}
```
The main function defined on the `ComponentProvers` struct to compute the composition polynomial is implemented as follows:
```rust theme={null}
pub fn compute_composition_polynomial(
&self,
random_coeff: SecureField,
trace: &Trace<'_, B>,
) -> SecureCirclePoly<B> {
let total_constraints: usize = self.components.iter().map(|c| c.n_constraints()).sum();
let mut accumulator = DomainEvaluationAccumulator::new(
random_coeff,
self.components().composition_log_degree_bound(),
total_constraints,
);
for component in &self.components {
component.evaluate_constraint_quotients_on_domain(trace, &mut accumulator)
}
accumulator.finalize()
}
```
Let us examine the above function for our [example AIR containing two components](/learn/S-two-book/how-it-works/air/overview#air-to-composition-polynomial). It takes the following three inputs:
* `&self`: This is the `ComponentProvers` on which the function is called.
* `random_coeff`: This is an element from the `SecureField` (i.e. $\mathsf{QM31}$). In our example, this is represented as $\gamma$.
* `trace`: The `Trace` struct which contains all the polynomials that make up the entire trace including all the components. For efficiency, it stores each polynomial in both coefficients and evaluations form.
```rust theme={null}
pub struct Trace<'a, B: Backend> {
/// Polynomials for each column.
pub polys: TreeVec<ColumnVec<&'a CirclePoly<B>>>,
/// Evaluations for each column (evaluated on their commitment domains).
pub evals: TreeVec<ColumnVec<&'a CircleEvaluation<B, BaseField, BitReversedOrder>>>,
}
```
Now let us examine the body of the function. First, we compute `total_constraints` and initialize an `accumulator`. The `total_constraints` determine the number of powers of $\gamma$ (`random_coeff`) required for the random linear combination.
For each component, we call `evaluate_constraint_quotients_on_domain`, which computes and accumulates the evaluations of that component's quotients on their respective evaluation domains within the accumulator. For the $0$th component, we add the evaluations of the quotient $q_0$ over its evaluation domain $D_{n_0 + \beta}$ to the `accumulator`. Similarly, for the $1$st component, we add the evaluations of the quotient $q_1$ over its evaluation domain $D_{n_1 + \beta}$ to the `accumulator`.
After adding all component quotient evaluations to the accumulator, we call the `finalize()` function, which:
1. Combines the accumulated evaluations at different domain sizes to compute the evaluations of the quotient composition polynomial $q$ over the domain $D_{n + \beta}$ where $n = \max{(n_1, n_2)}$.
2. Interpolates $q$ over $D_{n + \beta}$ using [circle FFT](/learn/S-two-book/how-it-works/circle-fft/index) to convert it into coefficient representation.
Note that the output is a [`SecureCirclePoly`](/learn/S-two-book/how-it-works/circle-polynomials/secure-evals-and-poly#secure-circle-polynomials) since the evaluations of $q$ are in the secure field $\mathsf{QM31}$ (as $\gamma$ is randomly sampled from $\mathsf{QM31}$).
# Algorithm
Source: https://docs.starknet.io/learn/S-two-book/how-it-works/circle-fft/algorithm
In this section, we will go through the Circle FFT algorithm specifically, to interpolate a bivariate polynomial given the evaluations over a circle domain. We will also go over a concrete example which will help us understand the algorithm.
Circle FFT follows a divide-and-conquer strategy, as in the classical Cooley–Tukey FFT. We recursively reduce the task of interpolating a polynomial over some domain to interpolating a lower degree polynomial over a smaller domain. Thus at each recursive layer, we have "smaller" polynomials and their evaluations over "smaller" domains. Let us first go over this sequence of domains for the Circle FFT algorithm.
## Sequence of Domains for Circle FFT
In Circle FFT, we use a 2-to-1 map to halve the domain size at each recursive layer. The domain used here is the [circle domain](/learn/S-two-book/how-it-works/circle-group#circle-domain) $D_n$ of size $|D_n| = 2^n$.
$D_n = q + \langle g_{n-1} \rangle \cup -q + \langle g_{n-1} \rangle$
This section describes two specific 2-to-1 maps that are central to the Circle FFT construction:
1. **Projection map $\pi_x$**: The projection map $\pi_x$ projects the points $(x,y)$ and $(x,-y)$ to the same $x$-coordinate i.e.
$\pi_x: D_n \rightarrow S_n, \quad \pi_x((x, y)) = x$
where $S_n$ is the set containing all the $x$-coordinates from $D_n$. This can be interpreted as saying that two points are considered equivalent if they differ only by sign. Since $\pi_x$ maps two points from $D_n$ to a single element in $S_n$, the size of $S_n$ will be half the size of $D_n$.
2. **Squaring map $\pi$**: The squaring map $\pi$ is a 2-to-1 map defined by:
$\pi: S_n \rightarrow S_{n-1}, \quad \pi(x) = 2x^2 - 1$
This is obtained using the doubling map and the equality $y^2 = 1 - x^2$ to compute the $x$-coordinate:
$\pi(x, y) = (x, y) + (x, y) = (x^2 - y^2, 2xy) = (2x^2-1, 2xy)$
In Circle FFT, we use both the projection map $\pi_x$ and the squaring map $\pi$ to construct the sequence of domains. The sequence of domains for Circle FFT is shown as follows:
$D_n \xrightarrow{\pi_x} S_n \xrightarrow{\pi} S_{n-1} \xrightarrow{\pi} \cdots \xrightarrow{\pi} S_1$
Now that we know the sequence of domains, let us dive into the Circle FFT algorithm.
## Circle FFT
The Circle FFT interpolates a bivariate polynomial $p(x,y)$ from the [polynomial space](/learn/S-two-book/how-it-works/circle-polynomials/evals-and-poly#polynomials-over-the-circle) $L_N(F)$, given the evaluations over a circle domain $D_n$ of size $N=2^n$. The algorithm is a three step process described as follows.
#### Step 1: Decompose $p(x, y)$ into sub-polynomials
In the first step, we decompose the bivariate polynomial $p(x, y)$ over $D_n$ using the projection map $\pi_x$ into two univariate polynomials $p_0(x)$ and $p_1(x)$ as follows:
$p(x, y) = p_0(\pi_x(x, y)) + y \cdot p_1(\pi_x(x, y)) = p_0(x) + y \cdot p_1(x)$
Now to continue with the FFT algorithm, we want to compute the evaluations of $p_0(x)$ and $p_1(x)$ over the smaller domain $S_n = \pi_x(D_n)$, given the evaluations of $p(x, y)$ over $D_n$. This is done using the following equations:
$$
p_0(x) = \frac{p(x, y) + p(x, -y)}{2}, \quad
p_1(x) = \frac{p(x, y) - p(x, -y)}{2 \cdot y}
$$
Substituting all evaluations of $p(x, y)$ over $D_n$ in the above equations, gives the evaluations of $p_0(x)$ and $p_1(x)$ over the domain $S_n$.
<Callout type="info">
To compute the evaluations of $p_1(x)$ over the domain $S_n$, we subtract the evaluations i.e. compute $p(x, y) - p(x, -y)$ and then divide by $2 \cdot y$. These values $y$ are the $y$-coordinates of the points in the circle domain $D_n$. They are also referred to as *circle twiddles* and they only depend on the circle domain $D_n$. Therefore they can be precomputed before the start of the FFT algorithm. We will look into these in detail in the next section.
</Callout>
> **Example**: To make all the calculations easier we will work on a concrete example over the Mersenne prime $p = 2^5 - 1 = 31$. Thus all calculations are over $\mathbb{F}_{31}$, i.e, modulo $31$. We are given the evaluations $\vec{v} = [13, 16, 9, 30, 29, 27, 13, 21]$ of $p(x, y)$ over the circle domain
>
> <br />
>
> $D_3 = [(7, 18), (13, 7), (24, 13), (18, 24), (7, 13), (13, 24), (24, 18), (18, 7)]$
>
> <br />
>
> and we want to compute the coefficients of $p(x, y)$ i.e. interpolate $p(x, y)$ given its evaluations $\vec{v}$ over $D_3$.
>
> <br />
>
> <br />
>
> **Step 1**: First, decompose the polynomial $p(x, y)$ using the map $\pi_x(x, y) = x$:
>
> <br />
>
> $p(x, y) = p_0(\pi_x(x, y)) + y \cdot p_1(\pi_x(x, y)) = p_0(x) + y \cdot p_1(x)$
>
> <br />
>
> Given the evaluations $\vec{v}$ of $p(x, y)$ over the circle domain $D_3$ we aim to compute the evaluations of $p_0$ and $p_1$ over the smaller domain $S_3$:
>
> <br />
>
> $S_3 = \pi_x(D_3) = [7, 13, 24, 18]$
>
> <br />
>
> For $(x, y)=(7, 18)$ and $(x, -y) = (7, 13)$ in $D_3$, substituting them into the following equations give:
>
> <br />
>
> $p_0(x) = \frac{p(x, y) + p(x, -y)}{2} = \frac{p(7, 18) + p(7, 13)}{2} = \frac{13 + 29}{2} = 21$
>
> <br />
>
> $p_1(x) = \frac{p(x, y) - p(x, -y)}{2 \cdot y} = \frac{p(7, 18) - p(7, 13)}{2 \cdot 18} = \frac{13 - 29}{2 \cdot 18} = 3$
>
> <br />
>
> Repeating this process for other pairs $(x, y)$ and $(x, -y)$ in $D_3$, we obtain:
>
> <br />
>
> $\vec{v_0} = [21, 6, 11, 10], \quad \vec{v_1} = [3, 28, 7, 6]$
#### Step 2: Recursively apply FFT to sub-polynomials
Given the evaluations of $p_0(x)$ and $p_1(x)$ over $S_n$, we now compute their coefficients.
This step mirrors the recursive structure of the Cooley–Tukey FFT. Each polynomial is recursively split using the squaring map $\pi(x) = 2x^2 - 1$, and the process continues over successively smaller domains.
We begin by decomposing $p_0(x)$ using the squaring map $\pi$ as follows:
$p_0(x) = p_{00}(\pi(x)) + x \cdot p_{01}(\pi(x))$
We compute the evaluations of $p_{00}(x)$ and $p_{01}(x)$ over $S_{n-1} = \pi(S_n)$ using the following equations.
$$
p_{00}(\pi(x)) = \frac{p_0(x) + p_0(-x)}{2}, \quad
p_{01}(\pi(x)) = \frac{p_0(x) - p_0(-x)}{2 \cdot x}
$$
This recursive process continues until we reach the base case: all evaluations of the polynomial over the domain are same. At that level, the coefficient is simply the evaluation of the constant polynomial.
Finally, we reconstruct the coefficients of $p_0(x)$ by working backward through the recursive calls, using the decomposition equation at each level. The same process applies to compute the coefficients of $p_1(x)$.
<Callout type="info">
Similar to *circle twiddles*, to compute the evaluations of $p_{01}(x)$ over $S_{n-1}$ we divide by the values $x$ which are the values from the domain $S_n$. These values $x$ are referred to as *line twiddles*. For the next recursive layer, we divide by values from $S_{n-1}$ i.e. $\pi(x)$ and for the next recursive layer we divide by $\pi^2(x)$ and so on. Thus the line twiddles is a vector of values $x, \pi(x), \pi^2(x), \ldots$ and so on. These only depend on the initial domain $D_n$ and thus can be precomputed before the start of the algorithm.
</Callout>
> **Step 2**: Given the evaluations of $p_0$ and $p_1$ over $S_3 = [7, 13, 24, 18]$:
>
> <br />
>
> $\vec{v_0} = [21, 6, 11, 10], \quad \vec{v_1} = [3, 28, 7, 6]$
>
> <br />
>
> we recursively apply the FFT algorithm to compute the coefficients of $p_0$ and $p_1$.
>
> <br />
>
> At each layer, we decompose the polynomial using the polynomial map $\pi(x)$. For example, the decomposition of $p_0(x)$ is:
>
> <br />
>
> $p_0(x) = p_{00}(\pi(x)) + x \cdot p_{01}(\pi(x))$
>
> <br />
>
> Omitting the intermediate steps of the recursive calls, we eventually obtain the coefficients of $p_0(x)$ and $p_1(x)$ as follows:
>
> <br />
>
> $p_0(x) = 12 + 26 \cdot x + \pi(x) + 28 \cdot x \cdot \pi(x)$
>
> <br />
>
> $p_1(x) = 11 + 26 \cdot x + 14 \cdot \pi(x) + 20 \cdot x \cdot \pi(x)$
#### Step 3: Combine the coefficients
Finally, we combine the coefficients of $p_0(x)$ and $p_1(x)$ to compute the coefficients of the original bivariate polynomial $p(x, y)$, using the decomposition:
$p(x, y) = p_0(x) + y \cdot p_1(x)$
> **Step 3**: Given the coefficients of $p_0(x)$ and $p_1(x)$:
>
> <br />
>
> $p_0(x) = 12 + 26 \cdot x + \pi(x) + 28 \cdot x \cdot \pi(x)$
>
> <br />
>
> $p_1(x) = 11 + 26 \cdot x + 14 \cdot \pi(x) + 20 \cdot x \cdot \pi(x)$
>
> <br />
>
> we reconstruct the original polynomial $p(x, y)$ using the decomposition:
>
> <br />
>
> $p(x, y) = p_0(x) + y \cdot p_1(x)$
>
> <br />
>
> Substituting the expressions for $p_0$ and $p_1$, we get:
>
> <br />
>
> $p(x, y) = 12 + 26 \cdot x + \pi(x) + 28 \cdot x \cdot \pi(x) + y \cdot (11 + 26 \cdot x + 14 \cdot \pi(x) + 20 \cdot x \cdot \pi(x))$
>
> <br />
>
> $p(x, y) = 12 + 26 \cdot x + \pi(x) + 28 \cdot x \cdot \pi(x) + \quad \quad \quad \quad \quad \quad$
>
> <br />
>
> $\quad \quad \quad \quad \quad \quad 11 \cdot y + 26 \cdot x \cdot y + 14 \cdot y \cdot \pi(x) + 20 \cdot x \cdot y \cdot \pi(x)$
This completes an overview of the interpolation algorithm using Circle FFT. In the next section, we will see how the twiddle values are computed and stored for Circle FFT.
# Basis for Circle FFT
Source: https://docs.starknet.io/learn/S-two-book/how-it-works/circle-fft/basis
The circle FFT algorithm outputs coefficients $c_j$ with respect to some basis $b_j^{(n)}(x, y)$ such that:
$p(x, y) = \sum_{j = 0}^{2^n - 1} c_j \cdot b_j^{(n)}(x, y)$
In the concrete example (covered in the [Algorithm section](/learn/S-two-book/how-it-works/circle-fft/algorithm)) of Circle FFT over twin-coset $D_3$, we saw that the algorithm computed the coefficient with respect to the following basis:
$b^{(3)}_j(x, y) = [1, x, \pi(x), x \cdot \pi(x), y, y \cdot x, y \cdot \pi(x), y \cdot x \cdot \pi(x)]$
Using induction on $n$, we can show that the Circle FFT algorithm outputs coefficients with respect to the following basis \[[Theorem 2, Circle STARKs](https://eprint.iacr.org/2024/278.pdf)]:
$b^{(n)}_j(x, y) := y^{j_0} \cdot x^{j_1} \cdot \pi(x)^{j_2} \cdot \pi^2(x)^{j_3} \cdots \pi^{n-2}(x)^{j_{n-1}}$
where $0 \leq j \leq 2^n - 1$ and $(j_0, \ldots, j_{n-1}) \in \{0, 1\}^n$ is the binary representation of $j$, i.e.,
$j = j_0 + j_1 \cdot 2 + \cdots + j_{n-1} \cdot 2^{n-1}$
# Dimension Gap
We will now explore the space of polynomials interpolated by the Circle FFT algorithm. Let the space spanned by the basis polynomials in $b^{(n)}(x, y)$ be $L'_N(F)$. The basis $b^{(n)}(x, y)$ has a total of $N=2^n$ elements and thus the dimension of the space $L'_N(F)$ is $N$. However, the space of bivariate polynomials over the circle curve is $L_N(F)$, which has dimension $N+1$ (as covered in the [section on polynomials over the circle](/learn/S-two-book/how-it-works/circle-polynomials/evals-and-poly#polynomials-over-the-circle)).
We can identify the missing highest total degree element in $L'_N(F)$ by examining the basis. The highest total degree element in basis $b^{(n)}(x, y)$ is:
$y \cdot x \cdot \pi(x) \cdot \pi^2(x) \cdot \pi^3(x) \cdots \pi^{n-2}(x)$
Using $deg(\pi^j(x) = 2^j)$, the highest degree of $X$ in the above term is:
$1 + 2 + 2^2 + 2^3 + \cdots + 2^{n-2} = 2^{n-1} - 1 = N/2 - 1$
Since the highest degree of $X$ in $L'_N(F)$ is $N/2 - 1$, we can represent the space $L'_N(F)$ as follows:
$L프로젝트로 돌아가기