Back to all posts

Circle STARKs: Part I, Mersenne

Circle STARKs

Introduction

In zero-knowledge proof systems, we (almost) always operate over a finite field and because the prover usually has to do a lot of field operations to generate the proof, we naturally want our field operations to be as fast as possible. With elliptic curve cryptography we are restricted to fields of "cryptographic size" e.g. around 256 bits for 128 bits of security. However, STARK-like techniques (Reed-Solomon IOPs) have no such direct dependency between the security parameter and field-size. We can therefore use much smaller fields.

By doing so we can use fields with very efficient arithmetic, such as small binary fields or small prime fields (think 32-bit or 64-bit). Some of the fastest such fields are small Mersenne prime fields, which have very simple modular reduction.

Unfortunately, until recently, the structure of these fields made them unsuitable for STARKs because they could not efficiently accommodate FRI/STIR. That has now changed. This is the beginning of a four part series explaining recent construction by Haböck, Levit and Papini dupped Circle STARKs, which enables the use of these particular fields for STARKs with greater efficiency. The series will be structured as follows:

Prerequisites for FRI and STARKs

This post is not aiming to explain the general workings of FRI, for that I recommend this blog post or this one, although we will cover Circle FRI and Circle STARKs in future parts of this series. For now it is sufficient to know that to instantiate FRI (and STARKs) you need:

  1. A finite field $\mathbb{F}$.

  2. A group $L_0$ of order $|L_0| = 2^k$: a smooth group with its operation defined over $\mathbb{F}$: \ It can be computed by a (small degree) polynomial/rational function over $\mathbb{F}$.

  3. A sequence of $k$ group homomorphisms $\phi_i : L_i \to L_{i+1}$ with small (order 2) kernel. \ Each of which can be expressed as (small degree) polynomials/rational functions over $\mathbb{F}$.

The homomorphisms define a sequence of smaller and smaller smooth groups $L_i = \phi_i(L_{i-1})$:

$$ \begin{aligned} &L_0 \\ &L_1 = \phi_1(L_0) \\ &L_2 = \phi_2(\phi_1(L_0)) \\ &\ \ \ \ \ \ \vdots \\ &L_{k} = \phi_{k}(\phi_{k - 1}(\ldots \phi_1(L_0) \ldots)) \end{aligned} $$

Here is a brief overview of the landscape of possible FRI instantiations:

1) Smooth Multiplicative Subgroup

Usable when the multiplicative subgroup $\mathbb{F}^*$ of $\mathbb{F}$ is smooth: $2^k {\large\vert} |\mathbb{F}^{*}|$

This is the original 2018 construction by Ben-Sasson, Bentov, Horesh and Riabzev.

2) Vector Spaces of Binary Fields

Usable when the field is a binary field $\mathbb{F}_{2^m}$.

Introduced in the 2019 DEEP-FRI paper by Ben-Sasson, Goldberg, Kopparty and Saraf.

3) Smooth Elliptic Curves (ECFFT)

Suitable for any large field $\mathbb{F}$.

This construction was introduced in 2021 and is split across two papers ECFFT Part I and ECFFT Part II by Ben-Sasson, Carmon, Kopparty and Levit.

4) Unit Circle (Circle STARK / Circle FRI)

Suitable for prime fields $\mathbb{F}_p$ where $2^k \mid p + 1$. Most notably Mersenne primes: $p = 2^k - 1$.

This technique was introduced this year, 2024, by Haböck, Levit and Papini

This will be the focus of this series.

Mersenne Prime Fields

The first two set of techniques has been widely deployed, for instance by the following teams:

These fields have been chosen because they enable fast arithmetic, and hence fast STARK proving. In the case of prime fields, the recent introduction of the fourth technique, Circle STARKs, will allow for even faster STARKs for a class of prime fields: Mersenne prime fields.

Circle STARKs are defined over fields $\mathbb{F} = \mathbb{Z} / (2^k - 1) \mathbb{Z}$ where $ 2^k - 1 $ is a prime number: the integers modulo a Mersenne prime $ 2^k - 1 $. In binary the prime is simply a string of $ k $ ones:

$$ 2^k - 1 = 1111\ldots 1111_2 $$

And it turns out modular reduction is as simple as ANDing with a mask, and adding the high bits shifted down e.g. for the 31-bit Mersenne prime $ 2^{31} - 1 $ the reduction can be implemented as:

#define MASK (0x7FFFFFFF) // 2^31 - 1 = 1111...1111

uint64_t reduce(uint64_t x) {
    return (x & MASK) + (x >> 31);
}

This takes a 64-bit integer and produces a partial reduced result, applying the reduction twice yields the fully reduced result. To see why this works, observe that if we define:

$$ \begin{align} \mathsf{low} &= x \ \text{\&} \ \texttt{MASK} = x \ \mathrm{mod} \ 2^{31} \\ \mathsf{high} &= x \ \texttt{>>} \ 31 = \lfloor x \ / \ 2^{31} \rfloor \end{align} $$

We can express $ x $ as:

$$ x = \mathsf{low} + 2^{31} \cdot \mathsf{high} $$

And therefore:

$$ x \equiv \mathsf{low} + (2^{31} \ \mathrm{mod} \ (2^{31} - 1)) \cdot \mathsf{high} \mod 2^{31} - 1 $$

Since $ 2^{31} \ \mathrm{mod} \ (2^{31} - 1) = 1$, we have:

$$ x \equiv \mathsf{low} + \mathsf{high} \mod 2^{31} - 1 $$

This is obviously very fast: requiring just a couple of cycles on any modern CPU. Because it is a 31-bit prime, the unreduced result of any field multiplication is at most 62 bits and thus fits in a 64-bit integer. It is also trivially vectorizable using e.g VPMULUDQ.

If 31 bits is not enough, you can use the 61-bit Mersenne prime $ 2^{61} - 1 $, which is the largest Mersenne prime that fits in a 64-bit integer and apply similar techniques.

Take Away: We want to use Mersenne prime fields for our STARKs because the modular reduction is very fast: it really doesn't get any better than this.

The Problem with Mersenne Primes

Usually when designing a STARK we have many possible choices of (prime) field $\mathbb{F}_p$ and we can pick one with a smooth multiplicative subgroup. One way to do so, is to pick some $n$ such that $p = 2^m + n \cdot 2^k + 1$ is prime, then the field will have a smooth subgroup of order $2^k$ since $2^k \mid p - 1$. For instance, the ethSTARK prime $p = 2^{61} + 20 \cdot 2^{32} + 1$ has $n = 20$, simply because it's the smallest $n > 0$ that makes $p$ prime.

The problem with Mersenne primes is that we cannot pick them, only 51 are known and they grow very very fast. So unlike the ethSTARK prime, we cannot just "pick another one" and unfortunately they do not have smooth multiplicative subgroups, for instance, the 31-bit Mersenne prime $ p = 2^{31} - 1 $ has a multiplicative group of order: $$ \left| \mathbb{F}_{2^{31} - 1}^* \right| = 2^{31} - 1 = 2 \cdot 3^2 \cdot 7 \cdot 11 \cdot 31 \cdot 151 \cdot 331 $$ With no large power of 2 in sight :(

We will start exploring an alternative group structure we can exploit in the case of Mersenne primes, namely the unit circle, in part II of this series.

zkSecurity offers auditing, research, and development services for cryptographic systems including zero-knowledge proofs, MPCs, FHE, and consensus protocols.

Learn more →

Share This Article