Day 26/100 of ZK 🔐
Today we focused on multilinear polynomials and implemented a basic multilinear extension (MLE) over a finite field.
A multilinear polynomial in k variables is one where each variable appears with degree at most 1. Formally, it looks like:
f(x₀, x₁, …, x_{k-1}) = Σ_{w ∈ {0,1}^k} c_w · (x₀^{w₀} x₁^{w₁} … x_{k-1}^{w_{k-1}})
Because each exponent is 0 or 1, the polynomial is completely determined by its values on the boolean hypercube {0,1}^k — exactly 2^k points. We store these 2^k evaluations in a Vec<u64> and treat them as the canonical representation of the MLE.
The multilinear extension property means we can evaluate the polynomial at any point in F_p^k (not just {0,1}^k) by interpolating the hypercube values. This is what makes MLEs powerful, they extend discrete table lookups into smooth, algebraic objects that play nicely with sum-check, Fiat-Shamir, and low-degree testing.
How evaluation works (bookkeeping method)
We start with the full table of 2^k values. For each variable r_i in the point:
* Split the table into two halves: low (where x_i = 0) and high (where x_i = 1)
* For each low entry, compute: low r_i × (high - low)
* This linearly interpolates between the low and high slices
* Repeat for the next variable on the now-halved table, until only one value remains
This is O(2^k) time but very cache-friendly and constant-factor efficient. The Lagrange method (summing f(w) × χ_w(r) over all w) is slower (also O(2^k)) but useful for verification.
How I implemented it
* Field: p = 2⁶¹ - 1 (fits in u64, fast reduction)
* Inline field ops: fadd, fsub, fmul (with u128 intermediate for mul), fpow (binary exponentiation), finv (a^{p-2}), fdiv
* MultilinearPoly holds evals Vec<u64> and num_vars = log₂(len)
* evaluate(point) uses the iterative binding loop (bookkeeping)
* bind_first(value) fixes the first variable and returns the reduced MLE
* add, scale do pointwise operations
* sum_over_hypercube() folds all evals (useful for sum-check round 0)
* lagrange_basis evaluate_lagrange for alternative interpolation check
* Demo shows 2-var and 3-var examples, boolean cube checks, binding, scaling, adding, and field sanity tests
In ZK this structure is critical: circuits get arithmetized into multilinear polynomials, sum-check proves sums over hypercubes efficiently, and random evaluation points let verifiers check low degree without reading the whole table.
#ZeroKnowledgeProof #BuildingInPublic #Math