Skip to main content
In the last section, we implemented a static lookup. A dynamic lookup is the same as a static lookup except that the values that are being looked up are not known before the proving process (i.e. they are not preprocessed columns but trace columns). In this section, we will implement one of the simplest dynamic lookups: a permutation check. A permutation check simply checks that two sets of values have the same elements, but not necessarily in the same order. For example, the values [1, 2, 3] and [3, 1, 2] are a permutation of each other, but [1, 2, 3] and [1, 2] are not. If you went through the previous section, you should have a good intuition for how to implement this. First create two LogUp columns where the first column contains the values in the original set of values with multiplicity 11 and the second column contains the values in the second set of values with multiplicity 1-1. Then, check that the claimed_sum, or the sum of the fractions in the two LogUp columns, is 00. We can optimize further by batching the two columns into a single LogUp column so that a LogUp column row looks something like 1col11col2\frac{1}{col_1} - \frac{1}{col_2}.
Looking at the code above, we can see that it looks very similar to the implementation in the previous section. Instead of creating a preprocessed column, we create a trace column that contains the values [0, 1 << log_size) in order. Then, we create a random permutation of the trace column values and set it as the second trace column. Note that this is equivalent to “looking up” all values in the first trace column once. And since all the values are looked up only once, we do not need a separate multiplicity column. Then, we create a LogUp column that contains the values 1original1permuted\frac{1}{original} - \frac{1}{permuted}.