This article explores efficient prime fields tailored to enhance the performance of code-based zero-knowledge proofs. These fields, implemented in Plonky3, also potentially benefit pairing-based protocols. We cover four prime fields:
Prime fields consist of a finite number of elements with defined operations for addition, subtraction, multiplication, and division, adhering to field properties. For example, consider the set {0,1,2,3,4,5,6} under arithmetic modulo 7, where and . This set forms a finite field with seven elements. Prime fields are chosen for their computational efficiency across various architectures, and their structure makes them particularly suited for Fast Reed-solomon Interactive oracle proofs (FRI).
The two rules:
The primary difference lies in their computational efficiency and structural characteristics across different computing architectures. Additionally, the order of the prime field is , which varies among fields.
In Zero-knowledge proof protocols, the data in computation trace are represented as those prime field In zero-knowledge proof protocols, computational trace data are represented as elements of these prime fields. Fields such as Goldilocks, BabyBear, and Mersenne31 are designed to enhance proof generation efficiency in systems employing FRI-based commitment schemes.
Employing smaller prime fields in zero-knowledge proofs optimizes prover and verifier times and reduces proof sizes. This optimization leverages various techniques including diverse interactive oracle proofs (IOPs), polynomial commitment schemes, and efficient hardware use, making calculations more feasible on standard consumer hardware.
Prime numbers are natural numbers greater than 1, divisible only by 1 and themselves. The smallest prime is 2, which is also the only even prime.
There are several types of primes:
More detailed information about the type of primes, see Wikipedia.
In this article, we introduce Mersenne primes, Crandall primes and Solinas primes deeply.
Mersenne primes are the prime numbers which is of the form . The modulus of the Mersenne31 field is a Mersenne prime () where .
Crandall primes are the prime numbers of the form . To limit carry propagation during modular multiplication, should be small. It limits the fastest Crandall choices to a few options. such as , , and
In mathematics, a Solinas prime, or generalized Mersenne prime, is a prime number that has the form
, where is a low-degree polynomial with small integer coefficients. These primes allow fast modular reduction algorithms and are widely used in cryptography. They are named after Jerome Solinas. Solina primes encompasses those two categories of prime numbers mentioned before: Mersenne primes and Crandall primes.
We take Mersenne primes as an example to explain why this kind of prime allows fast modular reduction algorithms. Given a number , bit-length of is less than 64. We represent in base 2^{31}, than we have . For any 64-bit integer , the result of the modular reduction is equivalent to the modular addition of three segments of its binary representation.
Four of the recommended primes by NIST are Solinas primes:
Goldilock primes are the Solinas tribomial primes. In [Hamburg15], Mike Hamburg introduced a class of primes of the form and named them Goldilocks primes, where satisfies the Golden ratio relation . When is a power of two this allows for very efficient implementation as the benifits of Solinas primes. Unfortunately, the at the end means it will have very few power-of-two roots of unity, which is not friendly for doing large-scale number theoretic transforms (NTT) used in many ZKP systems..
To solve the drawbacks of Goldilock primes poposed by Hamburg, the researchers in plonky use the prime which is similar to the form of Goldilock primes, and keep the name Goldilocks prime.
The first advantage is : the has a -th root of unity. Because , it is friendly for doing number theoretic transforms for the polynomials with degree up to .
The second advantage is from the prime of the form . To multiplication two number , we can represent them in base and make use of Karatsuba multiplication:
There are several implementation methods for field extension in plonky3:
For 64-bits Goldilocks field, the ~128 bit extension field is the quadratic extension of base field . It is easy to find a irreducible 2-degree polynomial: , where is 7. Based on this irreducible polynomial, we can construct the extend field .
We can use vector to represent a element in the extend field . We can also use a polynomial to represent this element.
Now the two basic operations ( field addition operation and field multiplication operation) can be define as the polynomial arithmetic.
Through the field extension, the field arithmetic is defined in extend field can be computed efficiently based on the small based field.
For ~32-bits field (Mersenne31\BabyBear\KoalaBear), the ~128 bit extension field can be constructed by using two quadratic field extensions.
For those interested in a deeper dive into small field applications in zero-knowledge proofs, I recommend the article Small Fields for ZKP