Catch up on Parts 1, 2, 3, and 4 before reading Part 5 in the How STARKs Work series.
Folding the proof
Our prover has been working extremely hard to process a huge amount of transactions. Computational work was spent on registering the transaction’s execution steps, verifying their validity, expanding their data, and amplifying invalid steps (if they exist) to make them detectable across the proof. The absence of misalignment anywhere throughout the proof would indicate that no errors or malicious actions have infiltrated this batch.
The proof we have now is extremely large. And now, just as we can expand the original sequence of steps using math, we can use more math to narrow down the sequence we ended up with.
Reducing proof length
The math in this part is beyond the scope of this article, but the important thing to understand in this phase is that we use math to compress the long sequence of numbers we received, and that, just like all previous steps so far, it’s done in a way that helps verify if any errors infiltrated our proof. We can refer to this process as “folding.”
There are many ways to “fold” the sequence of numbers, and the Prover “folds” the long sequence it generated in one of these ways. Then it repeats this step again and again, each time shrinking the sequence. Each folding creates a new, shorter sequence composed of entries that summarize the previous sequence. At each step, the new entries are the “sum” of 10 numbers in the folded sequence. If the initial sequence was a billion-numbers long, the first folding will be one-tenth the size (100 million), and each successive folding will reduce its length by another factor of 10. After 8 foldings, a sequence that started at length one billion will be 10 numbers long.
This process of folding, reducing the length of the proof, and checking the end result, is a mathematical protocol called FRI (Fast Reed-Solomon IOPP). FRI moves from a polynomial of one degree to another polynomial of half the degree, using half the number of points. (For those of you familiar with the Fast Fourier Transform, we “fold” the two sub-sequences of the first step of that algorithm; you’ll need to read the math papers for further details).
Ensuring Validity
In this “folding” process, we are not only reducing the length of the proof, but we’re also verifying that the proof doesn’t contain any errors. When the prover correctly writes down the transaction data and the math we apply to it, the resulting numbers will form a pattern. This emerging pattern can be thought of like a million-dimensional snowflake living in a billion-dimensional space. It’s not something we can comprehend, but math lets us deal with it abstractly. When we fold this sequence of numbers, or this million-dimensional snowflake, all possible folding patterns lead to a few final numbers that are all equal. In other words, in the case of a proof where all transactions and execution steps are valid, once the Prover is done folding the sequence over and over again, all 10 numbers in the final result would magically be the same. The Verifier can easily read these 10 numbers and check that they are the same. This is the easy test that saves us re-executing all 1 million transactions.
At least, that’s what happens if you start the process with a true snowflake, i.e., if the Prover didn’t try to cheat. But what if the Prover wasn’t operating with integrity?
What if the Prover is Darth Vader
So far, we’ve explained how an honest Prover, operated by someone like Luke Skywalker, would work. But what if Darth Vader operates the Prover? Mr. Vader will know that the Verifier will sample only a tiny amount of information. So why not fill in the numbers in the sequence however he wants to, just to make it look like the constraints are satisfied for the specific part that will be checked? After all, there are many different ways to fill in a Sudoku-like puzzle if you’re writing it fresh from the start. Do we have a way to expose a Prover that conducted this type of malicious move? We do.
Remember the multidimensional snowflake pattern that emerged from the sequence of numbers? If the Prover tries to cheat, it would not be able to create that magical snowflake, since it requires an honest, aligned sequence of numbers. Without alignment throughout the sequence, we will not get that snowflake. Then, when the Prover starts the folding process, instead of folding that aligned snowflake, it would be folding something that’s deformed and ugly, and doesn’t look like a million-dimensional snowflake. The folding process will nearly always lead to a bad outcome, with numbers that are not all the same. This result would indicate that something about the proof – either a step or the computation of it – is invalid. This is how the folding process reduces the proof’s length, in addition to helping us ensure the validity of the proof.
There’s one more small step before the proof is ready to be sent to the Verifier for checking. Interestingly, this step is crucial in making STARKs post-quantum secure. Any guess what it is? Part 6 will explain.