Skip to content
← Writing

Degree Adjustment in SNARKs

On adjusting the degree of SNARK-related polynomials to fit our needs, and why the randomness matters.

· 5 min read · SNARKs, Polynomials

Notation

We will denote by F\mathbb{F} to a finite field and F∗\mathbb{F}^* to its respective multiplicative group. We will also denote as HH to a subgroup of F∗\mathbb{F}^*. Finally, we will denote by ZHZ_H to the polynomial over F\mathbb{F} that vanishes on HH and call it the vanishing polynomial.

Given a polynomial p∈F[X]p \in \mathbb{F}[X] and an evaluation domain HH, we will denote by p~\tilde{p} to the polynomial resulting from the interpolation of the set of points {(h,p(h)), for h∈H}\{(h, p(h)), \text{ for } h \in H\}.

Statement

Let d,D∈Nd,D \in \mathbb{N} such that D>dD > d and let f∈F[X]f \in \mathbb{F}[X]. Let g∈F[X]g \in \mathbb{F}[X] be the polynomial defined as:

g(X)=f(X)+XD−d⋅f(X).g(X) = f(X) + X^{D-d} \cdot f(X).

Then, if f~\tilde{f} has degree lower than dd then we have that g~\tilde{g} has degree lower than DD (Prove it! Hint: Divide ff by ZHZ_H).

In our context, it is always the case that DD is a power of two and dd is not. What we intend with this “degree adjustment” is to form a polynomial lower than a power of two from a polynomial for which this is not the case.

One can imagine D=8D = 8 and d=5d = 5 so that we adjust the degree to the “next” power of two.

To achieve the converse, we need to involve random coefficients α\alpha and β\beta and define g(X)g(X) in the following way:

g(X)=α⋅f(X)+β⋅XD−d⋅f(X).g(X) = \alpha \cdot f(X) + \beta \cdot X^{D-d} \cdot f(X).

Now, we can claim that f~\tilde{f} has degree lower than dd if and only if g~\tilde{g} has degree lower than DD.

Example: Randomness is Necessary

Let’s see why the converse is not true in the first definition of gg.

Let F=Z97\mathbb{F} = \mathbb{Z}_{97} (notably, 96=25⋅396 = 2^5 \cdot 3), let ω=8\omega = 8 be a primitive 1616-th root of unity and let:

H=⟨ω⟩={1,8,64,27,22,79,50,12,96,89,33,70,75,18,47,85}H = \langle \omega \rangle = \{ 1,8, 64, 27, 22, 79, 50, 12, 96, 89, 33, 70, 75, 18, 47, 85 \}

be the subset of F∗\mathbb{F}^*, generated by ω\omega, containing all the 1616-th roots of unity. We therefore have that ZH(X)=X16−1Z_H(X) = X^{16} - 1 is the vanishing polynomial on HH.

Assume that D=8D = 8 and d=5d = 5.

Now, let f(X)=ZH(X)+X14−X11+X8−X5f(X) = Z_H(X) + X^{14} - X^{11} + X^{8} - X^5. We therefore have that:

f(X)≡X14−X11+X8−X5(modZH(X)),f(X) \equiv X^{14} - X^{11} + X^{8} - X^5 \pmod{Z_H(X)},

so that f(X)f(X) behaves identical to X14−X11+X8−X5X^{14} - X^{11} + X^{8} - X^5 when evaluated on HH, implying that the interpolated polynomial f~\tilde{f} will be of degree 1414.

In this case, we have that:

g(X)= (ZH(X)+X14−X11+X8−X5)+X3⋅(ZH(X)+X14−X11+X8−X5)=(X3+1)ZH(X)+X17−X5= (X3+X+1)ZH(X)−X5+X,\begin{align*} g(X) = &~(Z_H(X) + X^{14} - X^{11} + X^{8} - X^5) \\& + X^3 \cdot (Z_H(X) + X^{14} - X^{11} + X^{8} - X^5) = \\&(X^3 + 1)Z_H(X) + X^{17} - X^{5} = \\ &~(X^3 + X + 1)Z_H(X) - X^{5} + X, \end{align*}

so that gg behaves identical to −X5+X-X^{5} + X when evaluated on HH, implying that the interpolated polynomial g~\tilde{g} is of degree 55.

Hence, g~\tilde{g} is a polynomial of degree 5<D5 < D even that f~\tilde{f} is of degree 14>d14 > d.

Randomness comes to the rescue!

Say that α=3\alpha = 3 and β=13\beta = 13.

In this case we have:

g(X)= 3⋅(ZH(X)+X14−X11+X8−X5)+13⋅X3⋅(ZH(X)+X14−X11+X8−X5)=(13⋅X3+13⋅X+3)ZH(X)−10⋅X14+10⋅X11−10⋅X8−3⋅X5+13⋅X,\begin{align*} g(X) = &~3 \cdot (Z_H(X) + X^{14} - X^{11} + X^{8} - X^5) \\&+ 13 \cdot X^3 \cdot (Z_H(X) + X^{14} - X^{11} + X^{8} - X^5) \\ &= (13 \cdot X^3 + 13 \cdot X + 3)Z_H(X) \\&- 10 \cdot X^{14} + 10 \cdot X^{11} - 10 \cdot X^{8} - 3 \cdot X^5 + 13 \cdot X, \end{align*}

As it can be seen, thanks to the random values, now the high-degree terms do not cancel out and we find that g~\tilde{g} is a polynomial of degree 14{14}.

Try itSame field, domain and f as above (𝔽97, |H| = 16, D = 8, d = 5). Pick the challenges and see whether the degree check catches the cheating f.
g̃(X) =
deg g̃ =

Alternatives

The following alternatives also work! We should assume however that the Prover cannot predict the randomness in advance.

  • β=α2\beta = \alpha^2 (or in general β=f(α)\beta = f(\alpha))

    g(X)=α⋅f(X)+α2⋅XD−d⋅f(X).g(X) = \alpha \cdot f(X) + \alpha^2 \cdot X^{D-d} \cdot f(X).

    As far as α≠α2\alpha \neq \alpha^2 this alternative will also work and therefore we would save one random value in the process. However, notice that the probability of g~\tilde{g} being a low degree polynomial is of 1−2/∣F∣1 - 2/|\mathbb{F}|, since both α=0\alpha = 0 and α=1\alpha = 1 would make it fail.

    In general, all α\alpha‘s that make α=β=f(α)\alpha = \beta = f(\alpha) would make it fail.

  • Only α\alpha is used

    g(X)=α⋅f(X)+XD−d⋅f(X).g(X) = \alpha \cdot f(X) + X^{D-d} \cdot f(X).

    This should work as far α≠1\alpha \neq 1. The probability here is of 1−1/∣F∣1 - 1/|\mathbb{F}|.

  • Only β\beta is used

    g(X)=f(X)+β⋅XD−d⋅f(X).g(X) = f(X) + \beta \cdot X^{D-d} \cdot f(X).

    This should work as far β≠1\beta \neq 1. The probability here is of 1−1/∣F∣1 - 1/|\mathbb{F}|.

When Both Random Values are Needed?

Say that we have f1,f2∈F[X]f_1,f_2 \in \mathbb{F}[X] and we define:

g(X)=(α1⋅f1(X)+β1⋅XD−d1⋅f1(X))+(α2⋅f2(X)+β2⋅XD−d2⋅f2(X)).g(X) = (\alpha_1 \cdot f_1(X) + \beta_1 \cdot X^{D-d_1} \cdot f_1(X)) + (\alpha_2 \cdot f_2(X) + \beta_2 \cdot X^{D-d_2} \cdot f_2(X)).

Here we have that g~\tilde{g} is of degree lower than DD if and only if the degree of f1~<d1\tilde{f_1} < d_1 and the degree of f2~<d2\tilde{f_2} < d_2.

When we include in the definition of gg more than one ff polynomial, then both randomness are necessary to achieve the highest probability.

Conclusion

We arrive to the following conclusions:

  1. If only one ff polynomial is included in the definition of gg, then simply sample a random value α\alpha and define: g(X)=f(X)+α⋅XD−d⋅f(X).g(X) = f(X) + \alpha \cdot X^{D-d} \cdot f(X).
  2. If more than one ff polynomial is needed, then sample two random values αi,βi\alpha_i, \beta_i per ff polynomial and define: g(X)=∑i=1k(αi⋅fi(X)+βi⋅XD−di⋅fi(X)).g(X) = \sum_{i=1}^k (\alpha_i \cdot f_i(X) + \beta_i \cdot X^{D-d_i} \cdot f_i(X)). In such case, the αi\alpha_i‘s and βi\beta_i‘s must be sampled uniformly and independently (of each other) from F\mathbb{F}. This guarantees that g~\tilde{g} will be of low degree with probability 1−1/∣F∣1 - 1/|\mathbb{F}|, assuming that the f~\tilde{f}‘s are of low degree.

Break my circuit

You are the prover. The verifier doesn't run the program; it only checks the constraints. Each circuit here is missing one, which is the most common bug in real ZK systems. Find a witness that fools it.

circuit.circom

Public (verifier sees)

Witness (you choose)

Constraints · everything mod 97