The post BLS12-381 For The Rest Of Us constitutes the base point for this article, so I highly recommend reading it to get a solid background of the BLS1-381 curve. This post will reuse some parts with an emphasy on the computational aspect of the optimal Ate pairing over such curve.
For those with a poor background on Pairing-Based Cryptography (PBC) but with a decent background on Elliptic-Curve Cryptoraphy (ECC) I recommend reading the following resources in order:
Only after (and not before) you feel sufficiently comfortable with both PBC and ECC come back to this post and start to make sense out of it. The full list of consulted resources can be found at the end of this post.
The implementation in zkASM has been done in this PR.
The BLS12-381 is the elliptic curve of the form:
defined over a finite field , where the prime is the following -bit number:
The number of points can be factorized as follows:
where t = x + 1 = -15132376222941642751
is known as the trace of Frobenius and x
is the BLS-family parameter that generates this specific curve.
Therefore, its -bit prime factor:
is the only one with sufficiently size for cryptographic purposes.
The point with coordinates:
is a point of order , i.e. a generator of the subgroup of size of the curve.
The embedding degree of this curve is .
To represent we use the following tower of extension fields:
fields:
where is not a quadratic residue in and is neither a quadratic residue or a cubic residue in .
In the particular case of the BLS12-381, we have and and therefore:
from which we can extract the identities , , and consequently the idenity .
Using the latter identity, we can also write:
These two representations of will allow us to apply some optimizations:
BLS curves admits a sextic twist defined over of the form:
This means that pairing computations can be restricted to points and and avoid computations over entirely.
The point with coordinates:
is a point of order , i.e. a generator of the subgroup of size of the curve.
The following mapping, known as the untwist:
with:
defines a group isomorphism from to and we are going to use it to convert points from the twisted curve to the curve only whenever required.
The inverse mapping, the twist, is defined as:
The optimal Ate pairing over the BLS12-381 curve is defined by:
where:
is the only subgroup of the -torsion of over .
, represented for point arithmetic efficiency by . The former is the trace zero subgroup of the -torsion of over , whereas the latter is the only subgroup of the -torsion of over .
is the set of -th roots of unity over .
x = -15132376222941642752
, which is a number of bits that can be expressed in binary as:
and has a Hamming weight of 6.
, for any and , is a rational function on that is computed using Miller's "double-and-add"-style algorithm:
starting with .
The conjugate of an element in in is . Hence, if we write we have:
Therefore, what we want to compute is the following:
In what follows we explain how to compute each of the components of the previous pseudocode snippet.
To summary 2019/814, we have:
A point belongs to if and only if:
where is the well-known endomorphism[1] defined by , where is of order .
This is clearly much cheaper than the naive scalar multiplication by , since its main cost is the scalar multiplication by , which is half the size of and has low Hamming weight.
A point belongs to if and only if:
where is the untwist-Frobenius-twist endomorphism, i.e., .
Again, this is much cheaper than the naive scalar multiplication by , since its main cost is the scalar multiplication by , which is roughly a fourth the size of .
Given two points and in the twisted curve such that and and a point in the curve , the evaluation at of the line passing through and is given by:
Given a point in the twisted curve and a point in the curve , the evaluation at of the line passing through is given by:
In the final exponentiation, we raise an element to the power .
First, divide the exponent as follows:
Let's start with the easy part of the easy part, when we first attempt to compute . But since, , we have , just one conjugate, one inversion and one multiplication in .
To finish the easy part, we first compute which is the Frobenius operator applied to and then multiply the result by to finally obtain .
Importantly, after the computation of the easy part, the resulting field element becomes a member of the cyclotomic subgroup , which means that inversion from now on can be computed by simply conjugation. Moreover, when an element belongs to , one can compute using fewer multiplications and therefore the overall costs of performing exponentiations (see this section).
Following Section 5 of this 2020/875, we can write:
To compute it, we proceed as follows:
(recall that, at this point, computing the conjugate is the same as computing the inverse)
As we have shown, in the final exponentation we must compute the first and second Frobenius operator over an element in . Recalling that , a naive implementation would take -operations, but we will do it much better.
Recall that we can write any element as:
where and with and .
Then, we have:
with and .
We will now show that raising an -element over any power of is almost cost free and therefore so is raising .
Using all the previous observations, we have:
which can be computed using a few multiplications and a few conjugations, assuming each is pre-computed for .
Similarly, notice and therefore , where .
Hence, assuming the precomputation of for , we can compute and almost for free.
I follow 2010/542 closely for this section.
Recall that:
and also:
For this optimitzation, it will be useful to introduce and represent as a degree-3 extension of :
where ; so that an element in can be written as . We can equivalently write .
These optimizations are due to "compression" and "decompression" techniques, which exploits the algebraic relationships arising from elements belonging to the cyclotomic subgroup .
If then the compression function is:
and the decompression function is:
where:
Now, on input we will be able to compute its square on compressed form. That is, , where :
Given and , the idea is to compute using the squaring formula in compressed form.
Represent in binary as with and define . Then:
Therefore, we can use the square-and-multiply algorithm to compute such product. Since we are going to be squaring in compressed form, we start at rather than the standard in such algorithm.
The endomorphism acts as a multiplication map , where . ↩︎