Roots of unity in modular arithmetic (or within finite fields) play a significant role in cryptography in general and are crucial for the Summa V2. Let's break down the idea of -th roots of unity in modular rings.
An intuitive example of modular arithmetic from our daily life is the "clock arithmetic". When we see "19:00" boarding time on a boarding pass, we know that it corresponds to "7" on the clock face. Formally, in this case we perform the modular reduction by the modulus 12:
,
because the clock face is only marked from 1 to 12.
An integer is an -th root of unity modulo if:
and for any .
In other words, is the lowest integer such that "wraps around" due to modular reduction to yield exactly . Integers smaller than don't yield modulo .
Let's observe a finite field of order : . Let's see that and are the 3rd roots of unity in such a field:
Let's consider a finite field that has -th roots of unity. Let be a primitive -th root of unity in , which means and no smaller positive power of equals 1.
The -th roots of unity in are .
Claim: (the sum of all the roots of unity in a finite field is equal to zero).
Proof:
Consider the sum . We can multiply by , noting that in a field so that such a multiplication preserves the equality:
Expanding the right hand side, we get:
Notice that if we were to expand further, every term except and would cancel out:
Since is a primitive -th root of unity, . So, . Therefore:
If the product of two factors is zero, at least one of them must be zero. We already established that , thus must be zero:
Therefore, .
Let's also check it on our previous toy example of and :
.
Let's see how we can take advantage of the sum of all roots of unity being zero when applied to the proof of solvency.
The desired commitment scheme for Summa should have the following properties:
We will demonstrate how a polynomial commitment can be used to achieve all of these properties.
Let's consider a polynomial that evaluates to a -th user balance at a "user's point" - some value that is designated for this specific user:
.
We can call it a user balance polynomial. It is quite easy to construct such a polynomial using the Lagrange interpolation. The formula for the polynomial that interpolates these data points is:
Where is the Lagrange basis polynomial defined as:
A polynomial constructed using the Lagrange interpolation is known to have the degree where is the number of users (therefore, the number of the balance evaluation points). The resulting polynomial should look like the following:
Let's choose the values as the -th degrees of an -th root of unity (assuming that we are perforing all the calculations in the prime field with a sufficiently large modulus):
, where is the -th primitive root of unity.
We choose a KZG commitment scheme to commit to this polynomial for the compatibility with Halo2 API (more on that later). In brief, a KZG commitment is a single finite field element that uniquely represents the polynomial .
It is impossible to reconstruct the polynomial from the commitment, so our requirement of user privacy is satisfied because it is impossible to infer any evaluations of the polynomial from the single-value commitment .
During the reveal (aka opening) phase, the committed value is used along with the claimed polynomial evaluation to provide a succinct proof , verifying that the value is indeed an evaluation of a polynomial at point and corresponds to the original commitment . Therefore, KZG commitment allows the Custodian to individually provide the opening proofs to each user to proof that the polynomial indeed evaluates to the user balance at the point :
More broadly, the KZG commitment allows the prover to open the polynomial at any point, and we will later see gow it benefits our case.
To prove the solvency of the Custodian, we need to find its total liabilities by summing up all the user balances and to prove to the public that the sum is less than the assets owned by the Custodian. An individual -th user balance is the evaluation of the polynomial at the value corresponding to the user:
Let's calculate the sum of all the user balances as the sum of the polynomial evaluations:
Therefore, the grand sum of the user balances is simply the constant coefficient of the polynomial times the number of users:
As it turns out, the Halo2 proving system is internally using the roots of unity as coordinates for the polynomial construction, and we will later see how we can take advantage of that.
Using the described polynomial construction technique and the KZG commitment, it is sufficient for the Custodian to "open" the KZG commitment at :
The total liabilities can then be calculated by multiplying the value by the number of users:
As described in the KZG section, individual users would receive the KZG opening proofs at their specific point and they would be able to check that
The caveat is that if two or more users have the same cryptocurrency balance, a malicious Custodian could give them the same KZG proof because the user index is a value defined by the Custodian. We will use the following technique to mitigate that:
To estimate the computational complexity of performing a Lagrange interpolation polynomial and then making KZG commitment to it, we need to consider both steps separately.
Lagrange Interpolation Polynomial:
KZG Commitment:
Combining both, the overall complexity for performing Lagrange interpolation and then making a KZG commitment can be estimated as , which is dominated by the term from the Lagrange interpolation for large . Lagrange interpolation can be optimized to sub-quadratic complexity. The key optimization involves recognizing and eliminating the redundant computations, particularly in the denominators of the Lagrange basis polynomials. Since each but one basis polynomials share a common denominator, this part can be computed more efficiently. Here's a brief outline of the optimization:
Compute the Product of All Terms: First, compute the product of all terms for to . This can be done in time using techniques similar to those in the Fast Fourier Transform (FFT).
Use Inverse Multiplication for Denominators: Instead of computing each denominator separately, we can compute the inverses of the terms and then use these inverses to quickly compute each denominator. This step also utilizes time.
Compute the Numerators Efficiently: The numerators of each Lagrange basis polynomial can be computed directly in linear time.
So, by adopting these optimizations, the computational complexity of Lagrange interpolation can be reduced to , which is significantly better than for large .
TODO add a "Motivation" section that explains why Merkle sum tree (MST) in Summa V1 was not sufficient and we have been searching for a better solution. In brief, MST involves hashing and contains entries, making it computationally demanding. In Summa V1 the MST inclusion proofs have to be wrapped inside a ZK-SNARK, so it is also computationally demanding to generate all of them at once for the entire user base of the Custodian that can be on the order of hundreds of millions of users. ↩︎