Starknet 백서

Starknet

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 73쪽 중 52쪽

t_on_queries` generates the proof `FriProof` using the queries. The struct `FriProof` contains the Merkle decommitments for each layer with respect to the query positions. ```rust theme={null} pub struct FriProof<H: MerkleHasher> { pub first_layer: FriLayerProof<H>, pub inner_layers: Vec<FriLayerProof<H>>, pub last_layer_poly: LinePoly, } ``` For our example, the components of `FriProof` will be as follows: * `first_layer`: The decommitments to query positions for $h_0$, $h_1$, and $h_2$. * `inner_layers`: There will be two inner layer proofs, i.e., one for the decommitments of $g_0$ and another for decommitments of $g_1$. * `last_layer_poly`: This will be the $g_2$ polynomial represented in coefficient form. 4. Return the following objects: * `proof`: The `FriProof` struct with all layer decommitments. * `query_positions_by_log_size`: The query mapping from domain log sizes to their respective query positions. Now let us look at the key function `decommit_on_queries` in detail. ```rust theme={null} pub fn decommit_on_queries(self, queries: &Queries) -> FriProof<MC::H> { let Self { config: _, first_layer, inner_layers, last_layer_poly, } = self; let first_layer_proof = first_layer.decommit(queries); let inner_layer_proofs = inner_layers .into_iter() .scan( queries.fold(CIRCLE_TO_LINE_FOLD_STEP), |layer_queries, layer| { let layer_proof = layer.decommit(layer_queries); *layer_queries = layer_queries.fold(FOLD_STEP); Some(layer_proof) }, ) .collect(); FriProof { first_layer: first_layer_proof, inner_layers: inner_layer_proofs, last_layer_poly, } } ``` The function `decommit_on_queries` generates the `FriProof` struct by decommitting all layers. Suppose there is a single query corresponding to point $P_0 = (x_0, y_0) \in H_0$ and let $P_i = \pi^i(x_i, y_i) \in H_i$. 1. **Decommit First Layer**: This provides Merkle tree decommitments for queried positions with respect to the first layer. This provides evaluations $h_0(P_0), h_0(-P_0)$, $h_1(P_1), h_1(-P_1)$, and $h_2(P_2), h_2(-P_2)$ along with their Merkle decommitments in the Merkle tree containing the first layer. 2. **Process Inner Layers with Folding**: We process the decommitment layer by layer. For our example, this proceeds as follows: * For the first inner layer: Provide the evaluation $g_0(x_0), g_0(-x_0)$ along with their Merkle decommitments. * For the second inner layer: Provide the evaluation $g_1(x_1), g_1(-x_1)$ along with their Merkle decommitments. 3. **Assemble Final Proof**: Combines all layer decommitments with the last layer polynomial $g_2$ into `FriProof`. # FRI Verifier Source: https://docs.starknet.io/learn/S-two-book/how-it-works/circle-fri/fri_verifier In this section, we describe the implementation of the FRI verifier in S-two, continuing the example from the technical overview and prover documentation. The verifier's role is to check that all folding steps have been performed correctly by the prover. The `FriVerifier` struct verifies the FRI proof generated by the prover. ```rust theme={null} pub struct FriVerifier<MC: MerkleChannel> { config: FriConfig, // TODO(andrew): The first layer currently commits to all input polynomials. Consider allowing // flexibility to only commit to input polynomials on a per-log-size basis. This allows // flexibility for cases where committing to the first layer, for a specific log size, isn't // necessary. FRI would simply return more query positions for the "uncommitted" log sizes. first_layer: FriFirstLayerVerifier<MC::H>, inner_layers: Vec<FriInnerLayerVerifier<MC::H>>, last_layer_domain: LineDomain, last_layer_poly: LinePoly, /// The queries used for decommitment. Initialized when calling /// [`FriVerifier::sample_query_positions()`]. queries: Option<Queries>, } ``` The main components are: * **config**: The `FriConfig` containing protocol parameters. * **first\_layer**: The first layer verifier, which checks Merkle decommitments for all initial circle polynomials (i.e., $h_0$, $h_1$, $h_2$). * **inner\_layers**: A vector of inner layer verifiers, each corresponding to a folding round and its Merkle decommitment (i.e., two layers, corresponding to $g_0$ and $g_1$). * **last\_layer\_domain**: The "line" domain for the final layer polynomial (i.e., $I_2$). * **last\_layer\_poly**: The final "line" polynomial $g_2$ sent in clear by the prover. * **queries**: The set of queries used for spot-checking the folding identities. ## Initialization The `commit` function initializes the `FriVerifier` using the FRI proof, the Fiat-Shamir channel, and protocol parameters. It sets up the verifier for the query phase. ```rust theme={null} pub fn commit( channel: &mut MC::C, config: FriConfig, proof: FriProof<MC::H>, column_bounds: Vec<CirclePolyDegreeBound>, ) -> Result<Self, FriVerificationError> { assert!(column_bounds.is_sorted_by_key(|b| Reverse(*b))); MC::mix_root(channel, proof.first_layer.commitment); let max_column_bound = column_bounds[0]; let column_commitment_domains = column_bounds .iter() .map(|bound| { let commitment_domain_log_size = bound.log_degree_bound + config.log_blowup_factor; CanonicCoset::new(commitment_domain_log_size).circle_domain() }) .collect(); let first_layer = FriFirstLayerVerifier { column_bounds, column_commitment_domains, proof: proof.first_layer, folding_alpha: channel.draw_secure_felt(), }; let mut inner_layers = Vec::new(); let mut layer_bound = max_column_bound.fold_to_line(); let mut layer_domain = LineDomain::new(Coset::half_odds( layer_bound.log_degree_bound + config.log_blowup_factor, )); for (layer_index, proof) in proof.inner_layers.into_iter().enumerate() { MC::mix_root(channel, proof.commitment); inner_layers.push(FriInnerLayerVerifier { degree_bound: layer_bound, domain: layer_domain, folding_alpha: channel.draw_secure_felt(), layer_index, proof, }); layer_bound = layer_bound .fold(FOLD_STEP) .ok_or(FriVerificationError::InvalidNumFriLayers)?; layer_domain = layer_domain.double(); } if layer_bound.log_degree_bound != config.log_last_layer_degree_bound { return Err(FriVerificationError::InvalidNumFriLayers); } let last_layer_domain = layer_domain; let last_layer_poly = proof.last_layer_poly; if last_layer_poly.len() > (1 << config.log_last_layer_degree_bound) { return Err(FriVerificationError::LastLayerDegreeInvalid); } channel.mix_felts(&last_layer_poly); Ok(Self { config, first_layer, inner_layers, last_layer_domain, last_layer_poly, queries: None, }) } ``` The inputs are as follows: * `channel`: The Fiat-Shamir channel for randomness and transcript hashing. * `config`: The `FriConfig` with protocol parameters. * `proof`: The `FriProof` struct containing Merkle decommitments and the last layer polynomial. * `column_bounds`: The degree bounds for each committed circle polynomial, in descending order. At a high level, it proceeds as follows: 1. Initializes the first layer verifier with the Merkle decommitments for circle polynomials $h_0$, $h_1$, $h_2$, their respective domains $H_0$, $H_1$, $H_2$, their degree bounds, and folding randomness $\lambda_0$. 2. Initializes each inner layer verifier with its Merkle decommitment, domain, degree bounds, and folding randomness. For our example: * The first inner FRI verifier layer will store decommitments for $g_0$, its domain $I_0$, degree bound, and folding randomness $\lambda_1$. * Similarly, the second inner FRI verifier layer will store decommitments for $g_1$, its domain $I_1$, degree bound, and folding randomness $\lambda_2$. 3. Stores the last layer polynomial $g_2$ and its domain $I_2$. 4. Initializes the `queries` as `None` and prepares the verifier for the query phase. 5. Outputs the `FriVerifier` struct. ## Query generation The function `sample_query_positions` uses the Fiat-Shamir channel to generate random query positions for checking the folding equations. It maps each domain size to its respective query positions, ensuring that queries are adapted to the domain of each polynomial. ```rust theme={null} pub fn sample_query_positions(&mut self, channel: &mut MC::C) -> BTreeMap<u32, Vec<usize>> { let column_log_sizes = self .first_layer .column_commitment_domains .iter() .map(|domain| domain.log_size()) .collect::<BTreeSet<u32>>(); let max_column_log_size = *column_log_sizes.iter().max().unwrap(); let queries = Queries::generate(channel, max_column_log_size, self.config.n_queries); let query_positions_by_log_size = get_query_positions_by_log_size(&queries, column_log_sizes); self.queries = Some(queries); query_positions_by_log_size } } ``` It takes the following input: * `&mut self`: This will be used to update the `queries` in `FriVerifier`, which was initialized to `None`. * `channel`: The Fiat-Shamir channel. At a high level, it proceeds as follows: 1. Samples `n_queries` random positions on the largest domain using the `channel`. 2. Returns a mapping from domain log sizes to their respective query positions using the function `query_positions_by_log_size`. Suppose $s=1$ query is sampled at $P_0 = (x_0, y_0) \in H_0$. The function computes the corresponding positions $P_1 = \pi(P_0)$ in $H_1$ and $P_2 = \pi(P_1)$ in $H_2$, mapping each to the correct domain size. ## Verification The function `decommit` verifies the `FriVerifier` after it has been initialized with the `FriProof` by verifying the Merkle decommitments and folding equations for all layers. It ensures that the prover's folding steps were performed correctly and that the final polynomial is close to the expected polynomial space. ```rust theme={null} pub fn decommit( mut self, first_layer_query_evals: ColumnVec<Vec<SecureField>>, ) -> Result<(), FriVerificationError> { let queries = self.queries.take().expect("queries not sampled"); self.decommit_on_queries(&queries, first_layer_query_evals) } fn decommit_on_queries( self, queries: &Queries, first_layer_query_evals: ColumnVec<Vec<SecureField>>, ) -> Result<(), FriVerificationError> { let first_layer_sparse_evals = self.decommit_first_layer(queries, first_layer_query_evals)?; let inner_layer_queries = queries.fold(CIRCLE_TO_LINE_FOLD_STEP); let (last_layer_queries, last_layer_query_evals) = self.decommit_inner_layers(&inner_layer_queries, first_layer_sparse_evals)?; self.decommit_last_layer(last_layer_queries, last_layer_query_evals) } ``` It takes the following as input: * `mut self`: The `FriVerifier` struct after initialization using the `commit` function. * `first_layer_query_evals`: The evaluations of the circle polynomials at the sampled query points. It proceeds as follows: 1. **First Layer Verification:** * Verifies Merkle decommitments for $h_0$, $h_1$, $h_2$ at the queried points $P_0$, $P_1$, and $P_2$, respectively. * Extracts the necessary evaluations for folding into the next layer. 2. **Inner Layer Verification:** * For each inner layer, verifies Merkle decommitments for $g_0$, $g_1$ at the folded query points $x_0$ and $x_1$, respectively. * Checks the following two folding equations using the folding randomness and the evaluations from previous layers. $$ \begin{aligned} g_0(x_0) &= \lambda_0^2 \cdot \left( \frac{h_0(x_0,y_0) + h_0(x_0,-y_0)}{2} + \lambda_0 \cdot \frac{h_0(x_0,y_0) - h_0(x_0,-y_0)}{2 \cdot y_0} \right) \end{aligned} $$ $$ \begin{aligned} g_1(x_1) &= \frac{g_{0}(x_{0}) + g_{0}(-x_{0})}{2} + \lambda_1 \cdot \frac{g_{0}(x_{0}) - g_{0}(-x_{0})}{2 \cdot x_{0}} \\ &\quad + \lambda_1^2 \cdot \left( \frac{h_1(x_1,y_1) + h_1(x_1,-y_1)}{2} + \lambda_1 \cdot \frac{h_1(x_1,y_1) - h_1(x_1,-y_1)}{2 \cdot y_1} \right) \end{aligned} $$ where $P_0 = (x_0, y_0)$ and $P_1 = \pi((x_0, y_0)) = (x_1, y_1)$. 3. **Last Layer Verification:** * Checks that the final polynomial $g_2$ matches the evaluations at the last layer's query positions. 4. Returns success if all checks pass; otherwise, returns an error indicating which layer failed. # Introduction Source: https://docs.starknet.io/learn/S-two-book/how-it-works/circle-fri/index > This section introduces the Circle FRI protocol, which is used to check proximity to low-degree polynomials. We provide a technical overview, walk through a concrete example, and detail the implementation of both the prover and verifier. This section is organized as follows: * **[Technical Overview](/learn/S-two-book/how-it-works/circle-fri/overview)**: Explains the mathematical foundations and protocol steps of Circle FRI, including a multi-table example and security analysis. * **[FRI Prover](/learn/S-two-book/how-it-works/circle-fri/fri_prover)**: Describes the implementation of the prover, including protocol configuration, commitment, and decommitment phases. * **[FRI Verifier](/learn/S-two-book/how-it-works/circle-fri/fri_verifier)**: Details the verifier's implementation, covering query generation and verification logic. # Technical Overview Source: https://docs.starknet.io/learn/S-two-book/how-it-works/circle-fri/overview In this section, we describe a multi-table variant of the *circle FRI* low degree test. This variant supports domains of different sizes, thereby avoiding excessive padding overhead. This section does not provide a detailed analysis of how FRI works, but instead focuses on the protocol as implemented in S-two. Analyzing soundness and explaining why FRI works is out of scope. Interested readers are advised to consult ["A summary on the FRI low degree test"](https://eprint.iacr.org/2022/1216.pdf). ## Introduction Circle FRI tests the proximity of a function $f \in F^D$ over a [canonical coset](/learn/S-two-book/how-it-works/circle-group#canonic-coset) $D$ of size $|D|=2^{n + \beta}$ to some polynomial $p(x, y)$ from the [polynomial space](/learn/S-two-book/how-it-works/circle-fft/basis#dimension-gap) $L'_n(F)$. The function $f \in F^D$ is represented as a vector of evaluations over the domain $D$. Here: * $F$ is a field extension of $\mathsf{M31}$ * $\beta$ is the log of blowup $B = 2^\beta$ * $L'_n(F)$ is the space of polynomials interpolated by circle FFT, defined as follows: $$ L'_n(F) = F[x]^{< 2^{n-1}} + y \cdot F[x]^{< 2^{n-1}} $$ Let $\mathcal{L}_{n-1}(F) = F[x]^{< 2^{n-1}}$, then we can represent $L'_n(F)$ as: $$ L'_n(F) = \mathcal{L}_{n-1}(F) + y \cdot \mathcal{L}_{n-1}(F) $$ > **Why check proximity to a polynomial?** > > The prover sends evaluations of a function to the verifier. However, the verifier does not know if this function is a polynomial, or if it satisfies a pre-specified degree bound. FRI allows the verifier to check that the evaluations sent by the prover are indeed "close" to some polynomial of bounded degree. Here, the verifier only checks for proximity; that is, the verifier accepts even if the evaluations sent by the prover are "close enough" to those of a polynomial of bounded degree. Thus, the evaluations sent by the prover need not be exactly equal to evaluations of some polynomial of bounded degree. In S-two, we can represent the trace over multiple tables, with each trace table defined for a domain of different size. Thus, we are interested in circle FRI for the multi-table setting. We will now see an adaptation of circle FRI for the multi-table setting using an example. Consider three functions: $h_{0}$ defined over the domain $H_0$, $h_{1}$ defined over the domain $H_1$, and $h_{2}$ defined over the domain $H_2$: $$ h_{0} \in F^{H_0} \quad, \quad h_{1} \in F^{H_1} \quad, \quad h_{2} \in F^{H_2} $$ The domains $H_0, H_1$, and $H_2$ are canonical cosets which form a chain using the squaring map $\pi$: $$ H_0 \xrightarrow{\pi} H_1 \xrightarrow{\pi} H_2 $$ Suppose for the sake of our example, for $i$ in $\{0,1,2\}$ the domain $H_i = D_{3-i + \beta}$, where $D_{3-i + \beta}$ is a canonical coset of size $2^{3-i + \beta}$. For each $i$ in $\{0,1,2\}$, we need to check that the functions $h_{i} \in F^{H_i}$ are "close" to the polynomial space $L'_{3-i}(F)$. For example, for $i=0$, we need to check that the function $h_{0}$ defined over $H_0 = D_{3 + \beta}$ is close to the polynomial space $L'_{3}(F)$. Circle FRI follows a similar divide-and-conquer strategy as the [Circle FFT](/learn/S-two-book/how-it-works/circle-fft/algorithm) algorithm. The prover recursively decomposes the functions and folds the odd and even parts using randomness sent by the verifier. This reduction continues until the proximity test of the folded function to the polynomial space is small enough for the verifier to check directly; in this case, the prover sends the folded function directly to the verifier. We reduce the functions up to folded functions evaluated over a domain $H_r$. For the sake of our example, consider $r=2$. Then the sequence of domains for circle FRI in the multi-domain setting is as follows: <div> <img alt="Sequence of domains for Circle FRI" /> <span>Figure 1: Sequence of domains for Circle FRI</span> </div> As shown in the above diagram, we use two different maps, as in the circle FFT algorithm: the projection map $\pi_x$ and the squaring map $\pi$. Here, $I_i$ is the "line" domain; for every $i$ in $\{0,1,2\}$, $I_i = S_{3-i}$, where $S_{3-i}$ is the "line" domain of size $|S_{3-i}| = |D_{3-i}| / 2 = 2^{2-i+\beta}$. Using circle FRI, the prover will prove proximity of functions $h_{0}$ to polynomial space $L'_3(F)$, $h_{1}$ to space $L'_2(F)$, and $h_{2}$ to space $L'_1(F)$ by reducing these three checks into a single check i.e. checking proximity of function $g_2$ to the polynomial space $\mathcal{L}_0(F)$. The verifier will have oracle access to the evaluations $h_{0} \in F^{H_0}$, $h_{1} \in F^{H_1}$, $h_{2} \in F^{H_2}$. The protocol proceeds as follows. ## Protocol 1. *Commit phase*: Consists of $r+1 = 3$ rounds. * **Round 0**: The prover will decompose the function $h_0$ over the domain $H_0$ into two functions $h_{0,0}\;,\; h_{0,1}$ over the domain $I_0$ as follows $$ h_0(x, y) = h_{0,0}(x) + y \cdot h_{0,1}(x) $$ The prover will find the evaluations of functions $h_{0,0}\;,\; h_{0,1}$ over the domain $I_0$ using the evaluations of $h_0$ over domain $H_0$ as follows: $$ h_{0,0}(x) = \frac{h_0(x,y)+h_0(x,-y)}{2} \quad, \quad h_{0,1}(x) = \frac{h_0(x,y)-h_0(x,-y)}{2y}. $$ Note that this decomposition and the process of finding evaluations of the decomposed functions is very similar to the circle FFT algorithm. Now the prover will fold the evaluations of $h_{0,0}$ and $h_{0,1}$ over the domain $I_0$ using the randomness $\lambda_0 \in F$ from the verifier as follows: $$ g_0(x) = {\lambda_0}^2 \cdot (h_{0,0}(x) + \lambda_0 \cdot h_{0, 1}(x)) $$ The prover commits and gives the verifier oracle access to the evaluations $g_0 \in F^{I_0}$. * **Round 1**: The prover will decompose the function $h_1$ over the domain $H_1$ into two functions $h_{1,0}\;,\; h_{1,1}$ over the domain $I_1$, same as the decomposition of $h_0$ in **Round 0**. The prover will also decompose the function $g_0$ over domain $I_0$ into two functions $g_{0,0}$ and $g_{0,1}$ over the domain $I_1$ as follows: $$ g_0(x) = g_{0,0}(2x^2 - 1) + x \cdot g_{0,1}(2x^2 - 1) $$ The prover will find the evaluations of functions $g_{0,0}$ and $g_{0,1}$ over the domain $I_1$ using the evaluations of $g_0$ over domain $I_0$ as follows: $$ g_{0,0}(2x^2 - 1) = \frac{g_0(x)+g_0(-x)}{2} \quad, \quad g_{0,1}(2x^2 - 1) = \frac{g_0(x)-g_0(-x)}{2x}. $$ Now the prover will fold the evaluations of $h_{1,0}$, $h_{1,1}$, $g_{0,0}$, and $g_{0,1}$ over the domain $I_1$ using the randomness $\lambda_1 \in F$ from the verifier as follows: $$ g_1(x) = g_{0,0}(x) + \lambda_1 \cdot g_{0, 1}(x) + \lambda_1^2 \cdot (h_{1,0}(x) + \lambda_1 \cdot h_{1,1}(x)) $$ The prover commits and gives the verifier oracle access to the evaluations $g_1 \in F^{I_1}$. * **Round 2**: This round is very similar to **Round 1**. The prover will decompose $h_2$ into $h_{2,0}$ and $h_{2,1}$, then decompose the f
프로젝트로 돌아가기