# Lookups and LogUp ## What is Lookup? A lookup refers to the process of searching for or retrieving specific values from a table 𝑇. The table 𝑇 consists of distinct values arranged in rows, denoted as 𝑖 = 0, … , 𝑁 βˆ’ 1. The values in the table represent permissible or legal values for a certain variable. A list of lookups 𝐹 is given, represented by $f{_j}$, where 𝑗 = 0, … , π‘š βˆ’ 1. These lookups are instances of the variable generated during the execution of a particular program. The goal is to show that all the lookups in 𝐹 are contained in the table 𝑇, expressed as 𝐹 βŠ† 𝑇. In other words, given sequences < $w{_i}$ > and < $t{_j}$ >, < $w{_𝑖}$ > βŠ† < $t{_j}$ > as sets if and only if βˆƒ < $m{_j}$ > such that: $∏{_𝑖}$(X - $w{_𝑖}$) = $∏{_j}$(X - $t{_j}$)$^m$$^{_j}$, The conditions π‘š < 𝑁 and, in most cases, π‘š β‰ͺ 𝑁 signify that the number of lookups is significantly smaller than the number of distinct values in the table. This is a typical scenario, where the set of possible values 𝑁 is much larger than the specific instances of the variable observed during the program's execution π‘š. ## Multiset Equality Checks The Grand Product Check involves examining given commitments to polynomials 𝑓 and 𝑔 over a finite field 𝐹 and a subset 𝐻 = {$x{_1}$, … , $x{_n}$} βŠ‚ 𝐹. This check ensures that the product of values of 𝑓 and 𝑔 over 𝐻 aligns, determining whether: $∏{_𝑖}{_∈}{_[}{_𝑛}{_]}$ $a{_𝑖}$ = $∏{_𝑖}{_∈}{_[}{_𝑛}{_]}$ $b{_𝑖}$ where π‘Žπ‘– = 𝑓($x{_𝑖}$) and $b{_𝑖}$ = 𝑔($x{_𝑖}$). Grand Product Check is useful because with one randomness it could be transformed into a more powerful primitive known as the β€œthe multiset equality check”. Multiset equality check involves the comparison of two sequences, denoted as < 𝑀 >= ($w{_𝑖}$, … , $w{_n}$) and < 𝑑 >= (𝑑, … ,$t{_n}$), to verify if they are permutations of each other. Unlike standard set equality, multisets allow for repeated elements. Two sequences 𝑀 and 𝑑 are permutations of one another if and only if: $∏{_𝑖}$(X - $w{_𝑖}$) = $∏{_j}$(X - $t{_j}$) over a field 𝐹. The equation essentially states that the product of differences between π‘₯ and the elements of the first sequence is equal to the product of differences between π‘₯ and the elements of the second sequence. Bayer and Groth's 2013 work focus on the reduction of polynomial identity to the grand product form using a random variable Ξ± chosen from a finite field 𝐹. This grand product check is expressed as: $∏{_𝑖}$(a - $w{_𝑖}$) = $∏{_j}$(a - $t{_j}$) using a random 𝛼 ∈ 𝐹. By introducing a random variable 𝛼, the Schwarz-Zippel Lemma implies that the grand product check fails with high probability unless < $w{_𝑖}$ >, < $t{_j}$ > are multiset equal. ## Standard Permutation Check through Polynomial Commitment ![screely-1708413688427](https://hackmd.io/_uploads/rknGQA-3p.png) Let us $L{_k}$ denotes the π‘˜-th Lagrange interpolation. These conditions serve as checks to ensure the integrity and correctness of the polynomial commitments and evaluations in the protocol. The commitment and opening steps are designed to convince the verifier that the prover knows valid evaluations of the polynomials at specific points (𝛾 and 𝑀𝛾) without revealing the entire polynomials. The verifier then verifies these claims based on the received information. $L{_4}$(π‘₯)(𝑍(π‘₯) βˆ’ 1) = 0 ensures that the prover follows the protocol correctly, and the second equation involves a relationship between the committed polynomials 𝑍(π‘₯), 𝑓(π‘₯), and 𝑑(π‘₯) at a specific point 𝑀𝛾. ### Example: Given the following table of two functions evaluated at 𝑀$^0$, 𝑀$^1$, 𝑀$^2$, 𝑀$^3$: ![image](https://hackmd.io/_uploads/BkIVd0-3p.png) To prove that 𝑓 and 𝑑 are the permutation of each other, we do the followings. Let’s say $L{_4}$(𝑀$^0$) = 0, $L{_4}$(𝑀$^1$) = 0, $L{_4}$(𝑀$^2$) = 0, $L{_4}$(𝑀$^3$) = 1 where $L{_4}$ denotes the 4-th Lagrange interpolation. Hence, the expressions for 𝑧(𝑀$^𝑖$) involve a parameter 𝛽. Namely, ![image](https://hackmd.io/_uploads/SJZfFAZ3p.png) ${L{_4}(π‘₯)(𝑧(π‘₯) βˆ’ 1) = 0}$ and ${𝑧^β€² = 𝑧.{𝑓^β€²+𝛽 \over 𝑑^β€²+𝛽}}$ are the constraints where (𝑧’, 𝑓’,𝑑’) represent the next step of (𝑧, 𝑓,𝑑) accordingly (i.e., grand product). ## Plookup (Permutation Lookup) Plookup has been designed to improve the efficiency and scalability of zero knowledge proofs by enabling a more efficient way to verify that elements belong to a set or to verify the correctness of various operations (like arithmetic operations). It helps to reduce the computational and storage requirements for these proofs, making them more practical for use particularly in blockchain applications. ![image](https://hackmd.io/_uploads/ryj_oRWha.png) Incorporating a sorted union operation into Plookup extends its functionality to efficiently handle scenarios where inputs need to be verified against multiple lookup tables or when ensuring the uniqueness of elements across these tables is crucial. This addition can significantly enhance the protocol's performance for zero-knowledge proof systems. ![Untitled](https://hackmd.io/_uploads/BkNvh0W3T.png) The prover's computational complexity is stated as 𝑂(𝑁 π‘™π‘œπ‘”π‘) field operations, where 𝑁 represents the size of the public lookup table 𝑇. This computational complexity indicates that the efficiency of the protocol is related to the size of the public table 𝑇, making it relatively efficient even as the table size grows. The statement also highlights the protocol's capacity to be generalized to accommodate multiple lookup tables and vector lookups. ## Flookup (Function Lookup) Flookup is a variant or an extension of the Plookup, aimed at enhancing the efficiency and capabilities of SNARKs. While Plookup focuses on efficiently verifying the existence of elements or the correctness of operations against a public lookup table, Flookup extends this concept to more complex scenarios involving function evaluations and the handling of dynamic or more sophisticated data structures within zero-knowledge proofs. The main objective of Flookup is to provide an efficient and succinct proof that the values of a committed polynomial are indeed part of a large table. The protocol leverages pairings to extract the vanishing polynomial of a relevant subset of the table. Flookup introduces a new polynomial IOP (Interactive Oracle Proof) for the proofs which involve interactions between the prover and verifier, with the prover providing responses to verifier queries. The protocol involves an initial preprocessing step with a complexity of 𝑂(π‘π‘™π‘œπ‘”$^2$ 𝑁) where the lookup table is generated, the table is encoded, and polynomial commitments are calculated. This preprocessing step is where pairings are computed, and other necessary information is prepared for subsequent proofs. After the preprocessing, the prover operates in quasi-linear time, with a complexity of 𝑂(π‘šπ‘™π‘œπ‘”$^2$ π‘š), where π‘š represents the number of elements or operations the prover is working with in the context of the proof. This represents a significant improvement over previous quadratic prover complexity. The efficiency is particularly notable when considering large domains. Namely, the quasi-linear complexity ensures that the prover's workload increases only slightly faster than the size of the dataset, making Flookup scalable and practical for large-scale applications. ## LogUp LogUp is a new type of a lookup argument based on the principle of logarithmic derivatives. It employs logarithmic derivatives to transform the verification of set inclusion into a check for the equality of rational functions, which significantly reduces the computational requirements. LogUp utilizes the logarithmic derivative to transform products into sums, leveraging the relationship between zeros of a polynomial and the poles of its logarithmic derivative. Therefore, it is more efficient compared to multivariate Plookup variants. It also performs favourably against Plookup's bounded multiplicity optimization for large batch sizes and can be extended to vector-valued lookups and adapted for range proofs. ## Logarithmic Derivative The logarithmic derivative of a function 𝑝(π‘₯) is denoted as π·π‘™π‘œπ‘”(𝑝(π‘₯))and is defined as the ratio of the derivative of 𝑝(π‘₯) to 𝑝(π‘₯). Namely, ${𝐷_{π‘™π‘œπ‘”}(𝑝(π‘₯))= {𝑝′(π‘₯) \over 𝑝(π‘₯)}.}$ This concept simplifies certain mathematical transformations by: - Derivative of a logarithm of a function ${𝑓(π‘₯): [log(𝑓(π‘₯))]’ = {1 \over 𝑓(π‘₯)} βˆ— 𝑓’(π‘₯)}$ - Turning products into sums: The logarithmic derivative of the product of two functions is the sum of their logarithmic derivatives: 𝐷$_{π‘™π‘œπ‘”}$(𝑝(π‘₯)π‘ž(π‘₯)) = 𝐷$_{π‘™π‘œπ‘”}$(𝑝(π‘₯)) + 𝐷$_{π‘™π‘œπ‘”}$(π‘ž(π‘₯)) ## What is LogUp? Given a polynomial 𝑝(π‘₯) = ∏ (𝑋 βˆ’ 𝑧𝑖) 𝑁 𝑖=1 is transformed into a sum of reciprocals βˆ‘ 1 π‘‹βˆ’π‘§π‘– 𝑁 𝑖=1 , where each term has poles corresponding to the zeros of the original polynomial with the same multiplicity. For sequences of field elements < π‘Ž >= (π‘Ž$_1$, … , π‘Ž$_N$) and < 𝑑 >= (𝑑$_1$, … ,𝑑$_M$) , the set inclusion {π‘Žπ‘– :𝑖 = 1, … , 𝑁} βŠ† {𝑑$_j$ :𝑗 = 1, … , 𝑀} is verified if and only if there exists a sequence of field elements < π‘š >= (π‘š$_1$, … , π‘š$_M$) (the multiplicities) such that: ![image](https://hackmd.io/_uploads/rktEod4np.png) This demonstrates how zeros of the polynomial 𝑝(𝑋) are converted into poles in its logarithmic derivative, and how multiplication of zeros translates into the multiplication of poles, with π‘š multiples of a zero leading to ${π‘š \over π‘‹βˆ’π‘€}$ in the logarithmic derivative. Namely, ${(𝑋 βˆ’ 𝑀)^{m} β†’ {m \over 𝑋 βˆ’ 𝑀 }}$ #### Example: Given the following table of two functions evaluated at 𝑀$_0$, 𝑀$_1$, 𝑀$_2$, 𝑀$_3$: ![image](https://hackmd.io/_uploads/r1dMaONhp.png) Let’s say 𝐿$_4$(𝑀$_0$) = 0, 𝐿$_4$(𝑀$_1$) = 0, 𝐿$_4$(𝑀$_2$) = 0, 𝐿$_4$(𝑀$_3$) = 1. To prove that 𝑓 and 𝑑 are the permutation of each other, we do the followings. Let us first evaluate 𝑧 with these 𝑀 values. ![Untitled](https://hackmd.io/_uploads/HktDlYN2T.png) 𝐿$_4$(π‘₯)𝑧(π‘₯) = 0 and 𝑧′ = 𝑧 + ${1 \over (𝑓′+𝛽)}$ βˆ’ ${1 \over (𝑑′+𝛽)}$ are the constraints where (𝑧’, 𝑓’,𝑑’) represent represent the next step of (𝑧, 𝑓,𝑑) accordingly. ### Logup for Multicolumn Permutation We can also use LogUp multicolumn permutations. All columns are combined with randomly generated values. For example, the following table has (4, 45, 440) in both tables. ![image](https://hackmd.io/_uploads/H1ZQbtN3T.png) To prove that they are permutations of each other we need to check the followings: - 𝐿$_4$(π‘₯)𝑧(π‘₯) = 0 where 𝐿$_4$(𝑀$^0$) = 0, 𝐿$_4$(𝑀$^1$) = 0, 𝐿$_4$(𝑀$^2$) =0, 𝐿$_4$(𝑀$^3$) = 1. - 𝑧′ = 𝑧 +1(𝑓$_1$β€²+𝛼𝑓$_2$β€²+𝛼$^2$𝑓$_3$β€²+𝛽)βˆ’1(𝑑$_1$β€²+𝛼𝑑$_2$β€²+𝛼$^2$𝑑$_3$β€²+𝛽) ## Proof of Membership through LogUp In the following example, we note that the column π‘š is added to the table to illustrate the number of occurrences. This is one of the key points that make LogUp more efficient than the others. ![image](https://hackmd.io/_uploads/HJv8ztVhT.png) To prove that their outputs are exactly the same, we must have the following constraints: - ${SUM_1 + SUM_2 = 0}$ - ${𝑧^β€²1 = 𝑧1 . (1 βˆ’ 𝐿_4)}$ βˆ’ ${1 \over 𝑓_1β€²+𝛼𝑓_2β€²+𝛼^2 𝑓_3β€²+𝛽}$ where $𝐿_4(𝑀^0)$ = 0, $𝐿_4(𝑀^1)$ = 0, $𝐿_4(𝑀^2)$ = 0, $𝐿_4(𝑀^3)$ = 1. - ${𝑧^β€²2 = 𝑧2}$ . $(1 βˆ’ 𝐿_8)$ βˆ’ ${π‘š \over 𝑑_1β€²+𝛼𝑑^2β€²+𝛼^2 𝑑_3β€²+𝛽}$ where $𝐿_8(𝑀^0)$ = 0, $𝐿_8(𝑀^1)$ = 0, …, $𝐿_8(𝑀^7)$ = 1. ## References - Bayer, S., Groth, J. (2013). Zero-Knowledge Argument for Polynomial Evaluation with Application to Blacklists. In: Johansson, T., Nguyen, P.Q. (eds) Advances in Cryptology – EUROCRYPT 2013. EUROCRYPT 2013. Lecture Notes in Computer Science, vol 7881. Springer, Berlin, Heidelberg. - Ariel Gabizon and Zachary J. Williamson. Plookup: A simplified polynomial protocol for lookup tables. Cryptology ePrint Archive, Report 2020/315, 2020. Available online: https://eprint. iacr.org/2020/315.https://doi.org/10.1007/978-3-642-38348-9_38 - Ulrich HabΓΆck. Multivariate lookups based on logarithmic derivatives. IACR Cryptology ePrint Archive 2022: 1530 (2022) - A. Gabizon and D. Khovratovich. Flookup: Fractional decomposition-based lookups in quasilinear time independent of table size. IACR Cryptology ePrint Archive, page 1447, 2022. - Liam Eagen, Dario Fiore, Ariel Gabizon. cq: Cached quotients for fast lookups. IACR Cryptology ePrint Archive. 2022: 1763 (2022) - Shahar Papini, Ulrich HabΓΆck. Improving logarithmic derivative lookups using GKR. IACR Cryptology ePrint Archive. 2023: 1284 (2023) - Halo2 Circuit Aggregation. https://github.com/scroll-tech/halo2/pull/71 (accessed Feb 2024) - Onur Kilic. Bench-logup-gate. https://github.com/kilic/bench-logup-gate (accessed Feb 2024) - Halo2 Circuit Aggregation. https://github.com/scroll-tech/halo2/pull/49 (accessed Feb 2024