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

naive FRI #1

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
book
book
157 changes: 157 additions & 0 deletions src/fri/naive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
## How does FRI work?
FRI protocol relies on a fact that if a source polynomial $p_0$ can be recursively folded into a constant polynomial, then $p_0$ has an expected upper bound degree. By folding, we mean each round halves the degree of $p_0$.
Copy link
Contributor

Choose a reason for hiding this comment

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

if a source polynomial $p_0$ can be recursively folded into a constant polynomial, then $p_0$ has an expected upper bound degree

I would remove the word "source" here because it's not clear what a "source polynomial" really is.

It's also not clear what that upper bound on the degree is. Perhaps rephrased like this:

The FRI protocol is an interactive protocol between a prover and a verifier in which the prover iteratively reduces the size of a (committed) polynomial via help from the verifier, until it reaches a constant degree. At the end of the protocol the verifier is convinced that the prover knows a polynomial of degree $d$ proportional to the number of reductions in the protocol. Thus, by fixing the number of rounds/reductions, a prover can convince a verifier that the polynomial they know has a specific upper bound on its degree.


Simply put, it is a protocol for verifier to quickly check if a polynomial has a upper degree bound claimed by prover.
Copy link
Contributor

Choose a reason for hiding this comment

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

for a verifier ... by a prover


This post will explain the intuition of the math behind how polynomial folding works through some simple calculation examples end to end. These examples will demonstrate a naive version of FRI protocol without the the uses of commitment, which will explained in another post.
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: "the the"

it'd be cool to incrementally build FRI here, so first fri is naive fri and doesn't use commitments, then get rid of g and h via the optimization, then add commitments, then add commitments that group some evaluations, then show how we can choose evaluations on each layer to reduce the number of queries, etc.


## What is folding?

The core of the protocol relies on a technique to recursively fold the original polynomial and derive a constant value at the end. Here is an example:

$$
\begin{align*}
p_0\text{ : } & 1 + 2x + 3x^2 & \\
p_1\text{ : } & 3 + 3y & \\
p_2\text{ : } & 6 &
\end{align*}
$$
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe use a list instead of align?



$p_0$ is the source polynomial. After a round of folding, it results in $p_1$. Then, the final round results in a constant polynomial $p_2$.

To see how this folding algorithm works, please refer to the [code](https://github.com/katat/fri/blob/ab5aad54b8fd1e37b881ed7558d6ad22b6911442/src/poly.rs#L77).
Copy link
Contributor

Choose a reason for hiding this comment

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

I think an english/math explanation would be better :p

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think your explanation using the $g_i(x)$ and $h_i(x)$ makes the connection easier to understand. I will use them to explain in english/math.


These folded polynomials have the following relationship with their source polynomials:

$$p_i\left(x^2\right)=\frac{p_{i-1}\left(x\right)+p_{i-1}\left(-x\right)}{2}+\beta_i \frac{p_{i-1}\left(x\right)-p_{i-1}\left(-x\right)}{2 x}$$
Copy link
Contributor

@mimoo mimoo Dec 12, 2023

Choose a reason for hiding this comment

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

this equation sorts of fall from the sky. I think it'd be better to explain the recipe of the reduction:

  1. if $p_i$ is of degree $d$, compute $g_i$ and $h_i$ as two degree $d/2$ polynomials, such that $p_i(x) = g_i(x^2) + x \cdot h_i(x^2)$
  2. get a random challenge $\beta_i$ from the verifier
  3. compute the next polynomial $p_{i+1}(x) := g_i(x^2) + \beta_i \cdot h_i(x^2)$

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. This is easier to explain on where the folded polynomial comes from.

The "fall from sky" equation is a step further and indeed difficult for others to reason where it is from without explaining the recipe of the reduction.



*For simplicity, the random number $\beta$ will be assumed as 1 in this post. We would touch the implication behind this random number in another post that explains the commitment.*

$p_0$ is the original polynomial, and $p_2$ is a constant polynomial that can't be folded anymore.
Copy link
Contributor

@mimoo mimoo Dec 12, 2023

Choose a reason for hiding this comment

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

I think I should be able to fold a constant polynomial without breaking the protocol (so FRI enforces an upper bound on the degree, but not a lower bound)


These folded polynomials can be traced back to their source polynomials. Thus, the evaluations in a folded polynomial can be accumulated from the corresponding source polynomial.
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure I understand this ^


These relationships can serve as a proof for verifier to the consistency among the evaluations. The consistency check implies if there is a $p_0$ exists that the prover claimed.
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure I get this one either ^


With the same folding setup, the final polynomial will be always the same value. Verifier can check against the same final value against the reduced values from different evaluation points.
Copy link
Contributor

Choose a reason for hiding this comment

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

what is a folding setup? you mean with the same polynomial and if the verifier sends the same randomness? I'm not sure I understand the paragraph here


If the final polynomial can be derived after expected rounds of folding, it implies the $p_0$ has an expected upper bound degree. In other words, if the final $p_k$ can be derived after $k=log(d)$ rounds of folding from $p_0$ which is of degree $d$, then $p_0$ has upper bound degree $d$.

More formally, there are two properties:
- the number of rounds $k=log(d)$ to derive the final polynomial implies the expected upper bound degree $d$
- the same final value can be re-used to check consistency of the evaluation claims across layers
Copy link
Contributor

Choose a reason for hiding this comment

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

(that second point is still not clear to me)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the final layer is a constant polynomial, the verifier can expect the derived value from above layers to be always that same constant value, no matter which evaluation point is used.

Take the folding example above, the derived value should equal to 6, which is the constant polynomial $p_2$.


We will refer this folding example again with some actual evaluations to demonstrate the interesting relationship among them.

## What is the problem?

Using the notation from [what is proving](https://nmohnblatt.github.io/zk-jargon-decoder/intro_to_zk/what_is_proving.html), we define the following:

$$
\mathcal{L}(\mathcal{R}_{\text{consistent-layers}})
$$

for instance, $\left(a_1, w_1\right) \in \mathcal{R}$, where $a_1$ can represent a FRI query and constant value from $p_2$, while $w_1$ represents the corresponding evaluations across layers.

So the problem is to do the check to see if $a_1$ is in $\mathcal{L}$. In other words, the verifier checks if the prover can provide $w_1$ satisfying the query $a_1$.
Copy link
Contributor

Choose a reason for hiding this comment

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

^ not sure how useful this notation is here, and also what is exactly the relation $\mathcal{R}_{\text{consistent-layers}}$

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I try to remark the problem that the FRI can help resolve in a compact way.
Obviously, it seems make it more confusing here :)

I think the relation $\mathcal{R}$ could be seen a success proof for a query.

I was trying to emphasis consistent-layers, as the prover should provide corresponding evaluations for the verifier to derive the final constant value across layers. But as you pointed out in the other comments, some of the these evaluations can be deduced from evaluations at previous layers.


## naive FRI

Let's assume prover is honest guy in this naive version of FRI. The goal is for verifier to do fast low degree test using the proof from prover.

### Hard honest work by prover

Prover can use the folded polynomial to obtain the evaluations for each layers. These evaluations of layers can serve as a proof for the verifier to sample for their consistency across layers.

Using the same polynomial example shown earlier, here are two simple calculation examples.

For evaluation point at *1*:

$$
\begin{align}
\text{Layer 1:} & \\
x_0&=1 \\
p_0(x_0) &= 1 + 2x_0 + 3x_0^2 \\
p_0(1) &= 6 \\
p_0(-1) &= 2 \\\\
\text{Layer 2:} & \\
x_1&=x_0^2 \\
p_1(x_1) &= 3 + 3x_1 \\
p_1(1^2) &= 6 \\
p_1(-1^2) &= 0 \\\\
\text{Layer 3:} & \\
x_2&=x_1^2 \\
p_2(x_2) &= 6 \\
p_2((1^2)^2) &= 6 \\\\
\end{align}
$$
Copy link
Contributor

Choose a reason for hiding this comment

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

a think a list would render better here as well, doesn't render super well at least on github

Copy link
Contributor

Choose a reason for hiding this comment

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

also I don't understand why you evaluate at 1 and -1 here? Aren't you just doing the reduction at this point? Why evaluate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is the prover need to evaluate the full domain and then commit the evaluations. Evaluating at 1 and -1 is an example of evaluating at point 1 and its symmetric point -1. Here I try to explain how these evaluations are done at the prover side.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, I guess it is part of committing to the polynomial at each layer (but you were not talking about commitments so far). Grouping v and -v under the same leaf is an optimization :o


Similarly, for evaluation point at *2*:

$$
\begin{align}
\text{Layer 1:} & \\
x_0&=2 \\
p_0(x_0) &= 1 + 2x_0 + 3x_0^2 \\
p_0(2) &= 17 \\
p_0(-2) &= 9 \\\\
\text{Layer 2:} & \\
x_1&=x_0^2 \\
p_1(x_1) &= 3 + 3x_1 \\
p_1(2^2) &= 15 \\
p_1(-2^2) &= 9 \\\\
\text{Layer 3:} & \\
x_2&=x_1^2 \\
p_2(x_2) &= 6 \\
p_2((2^2)^2) &= 6 \\\\
\end{align}
$$



In this manner, the prover can keep calculating for the whole domain. Then they would response the verifier query with the evaluations across layers for checking if an instance $a_i$ corresponding to the query is in the $\mathcal{L}\left(\mathcal{R}_{\text{consistent-layers }}\right)$
Copy link
Contributor

Choose a reason for hiding this comment

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

keep calculating for the whole domain

what do you mean by that?

also it's the first time you talk about the verifier doing queries here. I think the typical explanations of FRI (ethstark, thaler, etc.) are usually clearer because they explain the commit phase and then the query phase, but here it's not clear what the protocol to follow is

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was trying to focus on describing how the evaluations can be done using the polynomials in different layers at the prover side, with the intention to avoid touching the commitment part for now.

Then I plan to explain on why it is necessary to incorporate the challenge by verifier and commit to these evaluations in another post or later section. I guess this arrangement might help separate the concepts between the "basic core calculations" and the security component.

Maybe I should explain this intention in this section to give a better clue on the role of this part in the protocol.


### Consistency check

Supposed the verifier samples the evaluation point *2* as demonstrated in the example above, these evaluations across layers for that point will be provided by the prover.

Based on the relationship implied from the equation of folding polynomial, the verifier can check the consistency among the evaluations between layers. Let's review and put this equation into use:

$$p_i\left(x^2\right)=\frac{p_{i-1}\left(x\right)+p_{i-1}\left(-x\right)}{2}+\beta_i \frac{p_{i-1}\left(x\right)-p_{i-1}\left(-x\right)}{2 x}$$
Copy link
Contributor

@mimoo mimoo Dec 12, 2023

Choose a reason for hiding this comment

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

here again the equation falls out of the sky. IMO a first naive FRI that doesn't do that, and use g and h would be easier. And then you can move to an optimized version of FRI that gets rid of g and h. For example:

Notice that if the verifier chooses the points they want to query carefully, for example $v$ and $-v$, they don't need to directly query $g$ and $h$ but can infer their evaluations instead. This is because by querying only $p_0$ at these two points the verifier just has to solve this system of equation:

  • $p_0(v) = g_0(v^2) + v \cdot h_0(v^2)$
  • $p_0(-v) = g_0(v^2) - v \cdot h_0(v^2)$

which is possible as we have 2 linearly independent equations of 2 unknowns

then the next layer can be obtained locally without any further queries by the verifier: $p_1(v) = g_0(v) + \beta \cdot h_0(v)$

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIUC, the $g_0(v^2)$ and $h_0(v^2)$ can be obtained by solving the system of equation.

Then, does it mean that, in the equation $p_1(v) = g_0(v) + \beta \cdot h_0(v)$, $g_0(v)$ and $h_0(v)$ actually represent the same values of $g_0(v^2)$ and $h_0(v^2)$ respectively? I am confused by the use of $v$ and $v^2$ between the $p_0$ and $p_1$.

Another question is, in this method, in order for the verifier to check $p_2(v)$, do they require prover to send $p_1(-v)$, so they can solve for the $g_1(v)$ and $h_1(v)$?

Copy link
Contributor Author

@katat katat Dec 16, 2023

Choose a reason for hiding this comment

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

Yeah, the ethstark paper says the prover will send the $p_1(-v)$.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah at each layer you query both the evaluation at v and -v, BUT as an optimization the prover commits to both these optimization under the same leaf in the merkle tree



This equation is useful for the verifier to check the consistency of the evaluations across layers. That is, $p_i$ can be evaluated using two symmetric evaluations from its source polynomial $p_{i-1}$ by connecting the source domain $x$ and folded domain $x^2$.
Copy link
Contributor

Choose a reason for hiding this comment

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

what is a source domain and a folded domain? These seems like elements, not domains :o


Take the `query = 2` or $a_2$, which corresponds to the $x_0=2$ for example, the prover send the following evaluations as witness $w_2$:


$$
\begin{align}
\text{Layer 0:} & \quad p_0(2) = 17, \quad p_0(-2) = 9 \\
\text{Layer 1:} & \quad p_1(2^2) = 15, \quad p_1(-(2^2)) = -9 \\
\text{Layer 2:} & \quad p_2((2^2)^2) = 6
\end{align}
$$

Then the verifier recursively plug in these evaluations to the equation $p_i$:

$$
\begin{align}
\text{Check layer 2: } & \\
p_1(2^2) &= \frac{p_0(2) + p_0(-2)}{2} + \frac{p_0(2) - p_0(-2)}{2 \times 2} \\
& \\
&= \frac{17 + 9}{2} + \frac{17 - 9}{4} = 13 + 2 = 15 \\\\
\text{Check layer 3(final):} & \\
p_2((2^2)^2) &= \frac{p_1(2^2) + p_1(-2^2)}{2} + \frac{p_1(2^2) - p_1(-2^2)}{2 \times 2^2} \\
&= \frac{15 - 9}{2} + \frac{15 + 9}{2 \times 2^2} = 3 + 3 = 6 \end{align}
$$

Indeed, the value provided by prover, $p_2((2^2)^2)$, is consistent with the recursively accumulated sum from symmetric points on previous layers.

Therefore, $(a_2,w_2)$ is a pair in $\mathcal{R}_{\text {consistent-layers }}$. So through a single query, the prover tries to convince the verifier that $p_0$ has an expected degree bound. The verifier may want to sample more points to ensure the soundness, which we will try to answer what it means in FRI.

For the next, we will see how to deal with a malicious prover by improving this naive version.

*Keep in mind the verifier only knows the evaluations of these polynomials. Here the notation $p_i$, where the i represent the layer number, is just to relate to the evaluations at required points for checking consistency instead of doing the polynomial evaluation directly at verifier side.