Part 2: Technical Overview
The Building Blocks
Curve BLS12-381
- BLS12-381 is a cryptographically secure, pairing-friendly elliptic curve.
- Bilinear pairings enable important features such as signature aggregation and polynomial commitments.
This chapter is a revised and updated version of my original homage to curve BLS12-381. It is not required reading – it's fine to treat the elliptic curve implementation as a black box – but I've included it for those who enjoy digging deeper. While curve BLS12-281 is the main focus, much of what follows covers broader background material on elliptic curves and pairings in general. As a non-mathematician1, all of this was very mysterious when I first encountered it; it has taken me quite a while to feel that I have some grasp of what's going on.
Introduction
Elliptic curves have been part of the blockchain toolkit since day one. For example, both Bitcoin and Ethereum use the curve known as secp256k1 to sign users' transactions with ECDSA, the "elliptic curve digital signature algorithm".
Curve secp256k1 is not used in Ethereum's consensus layer, however. Instead we use a curve called BLS12-381 because it supports a mathematical operation called bilinear pairing - it is a "pairing-friendly" elliptic curve. Pairings are very cool because, among other things, they allow us to do signature aggregation and polynomial commitments, operations that have become foundational to Ethereum's consensus but are not supported by most elliptic curves.
Pairing-friendly elliptic curves are curves with both a favourable embedding degree (to be explained below), and a large prime-order subgroup (also see below). These are rare. If you create an elliptic curve at random, it has a miniscule chance of being pairing-friendly. Nevertheless, they can be constructed, and several families of pairing-friendly curves are known in addition to the BLS curves.
Some good reading if you want to learn more about pairing-based cryptography:
- Vitalik has a great general introduction to elliptic curve pairings.
- Alin Tomescu gives an entertaining review of the history of the development of pairing based cryptography and some of its applications in a blog post, Pairings or bilinear maps2.
- The NIST report on pairing-based cryptography is quite readable. I recommend Section 2 and the Appendix.
- Also good background is the draft IETF standard for pairing-friendly curves.
If you really want to understand this stuff then Pairings for Beginners is unsurpassed. It turns out to be a lot less scary than it looks if you work through it carefully, studying the examples as you go.
BLS12-381 in Ethereum
The possibility of signature aggregation was the key breakthrough that made Ethereum's beacon chain possible. It allowed us to abandon the previous, impractical, proof of stake plans in mid-2018 and go all-in on the beacon chain approach.
To perform signature aggregation, we need to use a cryptographically secure, pairing-friendly elliptic curve. As noted, these are quite rare.
The main reason for the choice of BLS12-381 for the beacon chain is that it is a sweet-spot among the available pairing-friendly curves in terms of security (originally thought to be around 128 bits, but see below), speed of the pairing operation, and the sizes of the public key (48 bytes) and signature (96 bytes). Among other candidates, the BN128/BN254 curve has smaller signatures but lower security (~100 bits). Other pairing-friendly curves (such as the BW, MNT, and KSS families) tend to have larger signatures or slower pairings for a similar security level.
Other influential factors were the following.
- BLS12-381 was designed for Zcash and was already being adopted by other chains such as Chia. There is safety in numbers (more scrutiny, better libraries), and interoperability between chains was a guiding principle at the time, although that ambition has faded since.
- The original paper3 about signature aggregation for blockchains used BLS12-381 in its analysis.
- BLS curves are included in the IETF pairing-friendly curve standardisation process. Standardisation makes everything easier4.
It's worth mentioning that BLS12-381 is also designed to be efficient for ZK-SNARK proving (which is Zcash's main purpose for it), but this wasn't a major consideration for Ethereum's original adoption of it.
All in all, I don't recall any significant debate about the adoption of curve BLS12-381; it was simply the obvious choice at the time.
About curve BLS12-381
History
Curve BLS12-381 was designed by Sean Bowe in early 2017 as the foundation for an upgrade to the Zcash protocol. It is both pairing-friendly (making it efficient for digital signatures) and effective for constructing ZK-SNARKs.
Ethereum 2.0 was a fairly early adopter of the curve. A number of other blockchains (Zcash, Chia, Dfinity, Filecoin, Algorand) also use BLS12-381, and several cryptographic libraries support it. The main library used by Ethereum clients is Blst, which was commissioned by the Ethereum Foundation for this purpose; other libraries that implement the curve are Gnark, Noble, Herumi/mcl, and Constantine.
As for standardisation, BLS12-381 is included in the emerging IETF standard for Pairing-Friendly Curves. It also appears in the draft standards for Hashing to Elliptic Curves, and BLS signatures5.
Naming
BLS12-381 is part of a family of curves described by Barreto, Lynn, and Scott (they are the B, L, and S in view here - a mostly different BLS trio appears in connection with BLS signatures).
The 12 is the embedding degree of the curve: neither too low, nor too high. We'll discuss embedding degrees in a little while.
The 381 is the number of bits needed to represent coordinates on the curve: the field modulus, . The coordinates of a point come from a finite field that has a prime order, and that prime number, , is 381 bits wide. 381 is a fairly handy number as we can use 48 bytes per field element, with 3 bits left over for useful flags or arithmetic optimisations. The size of this number is guided both by security requirements and implementation efficiency.
Curve equation and parameters
The basic equation of the BLS12-381 curve is .6
The key parameters for a BLS curve are set using a single parameter (different from the in the curve equation!) that can be selected to give the curve nice properties for implementation. BLS12-381 is derived from the case of Construction 6.6 in the taxonomy.
Specific design goals for BLS12-381 are:
- has "low hamming weight", meaning that it has very few bits set to 1. This is particularly important for the efficiency of the algorithm that calculates pairings (the Miller loop).
- The field modulus mentioned above is prime and has 383 bits or fewer, which makes 64-bit or 32-bit arithmetic on it more efficient.
- The order of the subgroups we use is prime and has 255 bits or fewer, which is good for the same reason as above.
- The security target is 128 bits - see below.
- To support ZK-SNARK schemes, we want to have a large power of two root of unity in the field . This means we want to be a factor of , for some biggish . Making a multiple of will achieve this. This property is key to being able to use fast Fourier transforms for interesting things like polynomial multiplication.
The value -0xd201000000010000
(hexadecimal, note that it is negative) gives the largest and the lowest Hamming weight meeting these criteria. With this value we have,
Parameter | Equation | Value | Comments | |
---|---|---|---|---|
Field modulus | Hex: 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab Dec: 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787 | 381 bits, prime | ||
Subgroup size | Hex: 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001 Dec: 52435875175126190479447740508185965837690552500527637822603658699938581184513 | 255 bits, prime |
Field extensions
Field extensions are fundamental to elliptic curve pairings. The "12" in BLS12-381 is not only the embedding degree, it is also (relatedly) the degree of field extension that we will need to use to calculate pairings.
The field can be thought of as just the integers modulo : . But what kind of beast is , the twelfth extension of ?
I have been unable to find any straightforward explainers of field extensions, so here's my attempt.
Let's construct , the quadratic extension of . In we will represent field elements as first-degree polynomials like , which we can write more concisely as if we wish.
Adding two elements is easy: . We just need to be sure to reduce and modulo .
What about multiplying? . Oops - what are we supposed to do with the that's appeared?
We need a rule for reducing polynomials so that they have a degree less than two. In this example we're going to take as our rule, but we could make other choices. There are only two rules about our rule7,
- it must be a degree polynomial, where is our extension degree, in this case; and
- it must be irreducible in the field we are extending. That means it must not be possible to factor it into two or more lower degree polynomials.
Applying our rule, by substituting to eliminate the unwanted term, gives us the final result . This might look a little familiar from complex arithmetic: . This is not a coincidence! The complex numbers are a quadratic extension of the real numbers.
Complex numbers can't be extended any further because there are no irreducible polynomials over the complex numbers. But for finite fields, if we can find an irreducible -degree polynomial in our field , and we often can, then we are able to extend the field to , and represent the elements of the extended field as degree polynomials, . We can write this compactly as , as long as we remember that there may be some very funky arithmetic going on.
Also worth noting is that modular reductions like this (our reduction rule) can be chosen so that they play nicely with the twisting operation.
In practice, large extension fields like are implemented as towers of smaller extensions. That's an implementation aspect, so I've put it in the more practical section below.
The curves
One of the initially non-obvious things about BLS12-381 is that we're really dealing with two curves, not one. Both curves share more-or-less the same curve equation, but are defined over different fields.
The simpler one is over the finite field , which is just the integers mod . So the curve has points only where the equation has solutions with and both integers less than . Such a point is , for example8. We shall call this curve .
The other curve is defined over an extension of to (think complex numbers). In this case, the curve equation is slightly modified to be 9, and we'll call the curve 10. We'll explain where this comes from in the section on Twists.
As an aside, the curve order of (the number of points on the curve) is vastly bigger than that of ; the curve equation has many more solutions when the domain is extended to the complex numbers. In fact, the order of is close to , and the order of is close to . This is not a coincidence, but a result of the Hasse bound. See the reference section for the actual values of these numbers.
The Subgroups
In this section and the next I'll attempt to explain how BLS12-381 ended up having two curve equations rather than one.
A pairing is a bilinear map. This means that it takes as input two points, each from a group of the same order, . This must be prime, and for security needs to be large. Also, for rather technical reasons11, these two groups need to be distinct. Let's call them and .
Unfortunately, our simple curve has only a single large subgroup, so we can't define a useful pairing based solely on .
However, if we keep extending the field over which is defined, it can be proved that we eventually find a curve that has more than one subgroup of order (in fact, of them). That is, for some , 12 contains other subgroups of order that we can use. One of these subgroups contains only points having a trace of zero13, and we choose that subgroup to be .
This number , the amount that we need to extend the base field by to find the new group, is called the embedding degree of the curve, which in our case is the "12" in BLS12-381. We'll discuss embedding degree more in a moment.
For completeness, note that each of and shares with its containing curve the "point at infinity". This is the identity element of the elliptic curve arithmetic group, often denoted . For any point , .
To summarise where we've got to, we now have a group of order in , and we have a distinct group of order in . Yay - we can do pairings!
Twists
But there's another challenge. As discussed earlier, doing arithmetic in is horribly complicated and inefficient, and curve operations need a lot of arithmetic. But there is a way to side-step this.
A twist is something like a coordinate transformation. Rather wonderfully, this can be used to transform our curve into a curve defined over a lower degree field that still has an order subgroup. Moreover, this subgroup has a simple mapping to and from our group14.
Curve BLS12-381 uses a "sextic twist". This means that it reduces the degree of the extension field by a factor of six. So on the twisted curve can be defined over instead of , which is a huge saving in complexity.
If we can find a such that , then we can define our twisting transformation as 15. This transforms our original curve into the curve . and look different, but are actually the same object presented with respect to coefficients in different base fields16.
When the twist is done correctly, the resulting has a subgroup of order that maps to our group and vice-versa. So, it turns out that we can work in over for most purposes, and map back to only when required (that is, only while actually computing pairings).
So these are the two groups we will be using:
- where
- where
And that's the story of why BLS12-381 looks like two curves, not one. is called the twist of, or the twisted curve corresponding to, .
Note that coordinates of points in the group are pairs of integers, and coordinates of points in the group are pairs of complex integers, so points take twice the amount of storage, and are more expensive to work with. This leads to interesting implementation trade-offs.
Pairings
So, what's this pairing thing all about?
As far as BLS12-381 is concerned, a pairing is a function that simply takes a point , and a point and outputs a point from a group . That is, a pairing is a mapping, .
Elliptic curve pairings are usually denoted (they take a pair of operands, hence the name) and have certain properties.
- is bilinear.
- is efficiently computable. For any and , we must have a polynomial time algorithm for computing .
- is non-degenerate. That is, for a non-zero there must exist some such that (the identity in ), and vice versa. This ensures that the pairing is "non-trivial" and actually useful.
Bilinearity
The property of pairings that we are most interested in is that they are bilinear. That is, is linear in both its arguments.
Anyone who can do multiplication is familiar with bilinearity : let , then , and - multiplication is linear in both its arguments.
We could construct a similar bilinear function for elliptic curve points by multiplying the discrete logarithms of the two input points. If is a generator of an elliptic curve group, then a point is, by definition, a multiple of that generator, , and is said to be the discrete logarithm of 17. So, given points and , we could find and and define - this boils down to integer multiplication and is therefore bilinear. The flaw with this, however, is that taking discrete logarithms on our elliptic curve is assumed to be very, very expensive by design. It basically requires brute-force calculation with a cost proportional to the curve order, which is what keeps our signature scheme secure. This is why the pairing operation needs its second property: it must be efficiently computable.
Bilinear pairings
I'm not going to go into all the details of how the efficiently computable pairing function is constructed – we can pretty much treat it as a black box – nevertheless, a great introduction is Vitalik's article, and for all the glorious details let me pitch again Pairings for Beginners.
Recall that is a mapping, . Since is linear in both its arguments, it behaves as follows.
- , and
From this, we can deduce that all of the following identities hold:
Note that, traditionally, the group operation in and is written additively, and the group operation in is written multiplicatively18 - I've used a "" to show that above. So we write or for applying the group operation times on or on , but we write (rather than ) because .
If we look past this notational weirdness, then we can loosely think of a pairing as being a way to "multiply" a point in by a point in , an operation that cryptographically secure elliptic curves don't normally support in any practical way.
In any case, bilinearity is just what we need when verifying BLS digital signatures.
Embedding degree
We've mentioned the embedding degree several times, and it is significant enough to appear in the name of the curve.
The embedding degree, , is calculated as the smallest positive integer such that divides . So, in the case of BLS12-381, is a factor of 19, but not of any lower power.
It turns out that this number, , gives the smallest field extension that satisfies the two equivalent conditions:
- contains more than one subgroup of order (used for constructing , see above);
- contains all the th roots of unity (used for constructing , see below)
These are the conditions we need to satisfy for pairings to be possible.
The choice of an embedding degree is a balance between security and efficiency (as ever). On the security front, the embedding degree is also known as the security multiplier: a higher embedding degree makes the discrete logarithm problem harder to solve in . However, a high embedding degree means we have to do field operations in high-degree extensions, such as , which is clunky and inefficient. (This is true even when using twists: the maximum available twist is degree six, so the best we can do is to reduce the field extension degree by six. And in any case pairing must be done in the large extension field.)
Embedding degrees of 12 or 24 seem to be a current sweet-spot for many applications. Once again, the embedding degree of BLS12-381 is 12 - it's in the name.
Security level
Security of cryptographic systems is measured in bits. Informally, I take -bit security to mean something like, "would need about operations to break it".
For elliptic curve cryptography, security is all about making the discrete logarithm problem hard. That is, given a point and a point (in multiplicative group notation), finding must be infeasible without prior knowledge, meaning that we want it to take at least operations for or so, in today's terms.
For pairing-friendly curves, the discrete logarithm problem must be hard in each of the three of the groups we are using, , , and . Thus, to target -bit security,
- The prime group order must be at least bits long as there are algorithms such as Pollard's rho algorithm that have cost .
- Our extension field must be large enough not to be vulnerable to methods like the number field sieve.
BLS12-381 was intended to offer around a 128 bit security level, based on these criteria, and this was supported by initial analyses. See Table 1.1 in the Taxonomy, for example.
However, on closer examination it seems that "the finite extension field of size 3072 = 12 × 256 bits is not big enough" (quoting section 2 here), in view of the second criterion above.
According to a report by NCC Group, citing other sources, the actual security level is probably between 117 and 120 bits (see pages 8 and 9). They regard this as a perfectly adequate level of security: "The value of reaching '128-bit' [being] mostly psychological". Sean Bowe has also commented on the security level in the light of the original design goals. The draft IETF specification for BLS12-381 is less pessimistic than the NCC Group, and cites a security level of 126 bits.
Cofactor
A subgroup's cofactor is the ratio of the size of the whole group to the size of the subgroup. Normal elliptic curve cryptography requires the cofactor to be very small, usually one, in order to avoid small subgroup attacks on discrete logarithms. In pairing-based cryptography, however, this is not the case, and the cofactors of the and groups can be truly enormous.
It turns out that, with care, we can have large cofactors and still be secure. Namely, when the cofactors of , and contain no prime factors smaller than . Section 3.2 of this paper discusses this in detail. This is not the case for BLS12-381, however, and the and cofactors both have several small factors. Thus, we have to be mindful of small subgroup attacks in our implementations.
I've listed the prime factors of the curve orders in the reference section, as well as the cofactors themselves. The cofactor contains small prime factors like 3, 11, and 10177; the cofactor contains small prime factors like 13, 23, and 2713.
It's not all bad news when it comes to the cofactors, though. It turns out that multiplying by the group's cofactor is a straightforward way to map any arbitrary point on the elliptic curve into the respective subgroup, or 20. This is important when doing "hash to curve" operations and the like: we first make a point on the curve, and then we map it into the appropriate group by multiplying by the cofactor, so-called cofactor clearing.
Roots of unity
Just a note on roots of unity, because they appear in two completely different and unrelated contexts, which can be confusing.
First, we said that to support ZK-SNARK schemes with this curve, for some biggish we want to have a th root of unity in the field (not , note). This is to facilitate efficient fast Fourier transforms for manipulating very large polynomials over the scalar field . From the hexadecimal representation of , it's clearly a multiple of , so there is a th root of unity ( of them, in fact).
Second, and completely unrelated, the effect of the pairing is to map the two points from and onto an th root of unity in . These th roots of unity actually form a subgroup in of order 21, which is the group we call .
Let's briefly revisit our discussion of extending the base field for to , which we did in order to find another subgroup of order . It also turns out treated as a multiplicative group is the smallest field extension that contains the th roots of unity in the field, the 12 coming from the embedding degree once again. This is why is defined over .
Using curve BLS12-381
This section is a miscellany of things relevant to using BLS12-381 in practice.
BLS digital signatures
Now it's time to introduce the other BLS: Boneh, Lynn and Shacham. (The L is the same L as in BLS12-381; the B and the S are different.)
BLS signatures were introduced back in 2001, a little before the BLS curve family was published in 2002. Pleasingly, they go hand-in-hand. (BLS signatures can use other curves; BLS curves have uses other than signatures. But it's nice when they come together.)
The BLS signature scheme is described briefly below. See the BLS Signatures chapter for a fuller exploration of how we have implemented them in Ethereum 2. You can find a pretty concise but lucid description of the BLS signature scheme in the draft IETF standard.
Private and public keys
The private/secret key (to be used for signing) is just a randomly chosen number between and inclusive. We'll call it .
The corresponding public key (if we're using for public keys) is , where is the chosen generator of . That is, multiplied by , which is added to itself times.
The discrete logarithm problem means that it is unfeasible to recover given the public key .
Signing
To sign a message we first need to map onto a point in group (if we're using for signatures). See hashing to the curve, below, for a discussion on ways to do this. Anyway, let's assume we can do this, and call the resulting point .
We sign the message by calculating the signature . That is, by multiplying the hash point by our secret key.
Verification
Given a message , a signature , and a public key , we want to verify that it was signed with the corresponding to .
This is where pairing comes in. The signature is valid if, and only if, .
We can confirm this using the properties of pairings: .
Aggregation
A really neat property of BLS signatures is that they can be aggregated (see also the original paper), so that we need only two pairings to verify a single message signed by parties, or pairings to verify different messages signed by parties, rather than pairings you might naively expect to need. Pairings are expensive to compute, so this is very attractive.
It's possible to aggregate signatures over different messages, or signatures over the same message. In the case of Ethereum 2.0 we aggregate over the same message, so for brevity I'm just going to consider that.
To aggregate signatures we just have to add up the points they correspond to: . We also aggregate the corresponding public key points .
Now the magic of pairings means that we can just verify that to verify all the signatures together with just two pairings.
Swapping G1 and G2
For many purposes, the and groups are interchangeable. For example, with the BLS signature scheme, we can choose our public keys to be members of and our signatures to be members of , or we can do it the other way round - the pairing function doesn't care; everything still works if we swap the groups over.
The trade-offs are execution speed and storage size. has small points and is fast; has large points and is slow. BLS12-381 was initially designed to implement Zcash, and for performance reasons they chose to use to represent signatures and to represent public keys.
With respect to Zcash, most other implementations are "reversed". In Ethereum 2.0 we use for public keys: for one thing, aggregation of public keys happens much more often than aggregation of signatures; for another, public keys of validators need to be stored in state, so keeping the representation small is important. Signatures, then, are points.
Point compression
(Note that sometimes, the twisting operation is referred to as point compression - that's something completely different to what we're discussing here.)
For storing and transmitting elliptic curve points, it is common to drop the -coordinate. This halves the amount of data. For BLS12-381, points are reduced from 96 bytes (2 × 381 bits-rounded-to-bytes) to 48 bytes, and points are reduced from 192 bytes to 96 bytes.
Any elliptic curve point can be regenerated from the coordinate by using the relevant curve equation, or . For any valid coordinate on the curve, is either zero or has two possible values that are the negative of each other: for , and analogously for .
Since field elements are 381 bits, and 48 bytes is 384 bits, we have some bits to spare for flags. The most important is a flag to show which of the values the point corresponds to (positive or negative). Another bit is used to signal whether this is the point at infinity (which has many possible representations). A third is simply to indicate whether this is a compressed or uncompressed representation, though context should handle this in practice.
For both and , about half of values are not on the curve. In this case, the point is conventionally decoded to the point at infinity. But unless the infinity flag is set – in which case we would not have attempted to decode the point – this is an error condition.
The specific details of how the flag bits and values are encoded is here.
Subgroup membership checks
When dealing with any point with an unknown origin, whether it comes to us compressed or uncompressed, it's important that we check that it lies in the correct subgroup. The point decompression described above only results in a point on the curve; we don't know whether it lies in the appropriate or .
The main issue seems to be that both and contain small subgroups (you can see this by factoring the cofactors22 - see the reference section for the actual factors). Inadvertently working with points in these small subgroups could lead to vulnerabilities, as discussed in this paper.
Subgroup checks are easy in principle: simply multiply our point by . For points in or this will result in the respective points at infinity; for points outside the groups, it won't.
Unfortunately, this is slow in practice, especially for , since is so large. As an alternative, there are new techniques making use of endomorphisms for performing faster subgroup checks.
Generators
and are cyclic groups of prime order, so any point (except the identity/point at infinity) is a generator. Thus, picking generators is just a matter of convention.
Generator points for and are specified in decimal here and the same points in hexadecimal here.
These were chosen as follows:
The generators of and are computed by finding the lexicographically smallest valid x-coordinate, and its lexicographically smallest y-coordinate and scaling it by the cofactor such that the result is not the point at infinity.
By my calculations, with and the respective group cofactors, this makes the generator , with as follows,
-
(0x04, 0x0a989badd40d6212b33cffc3f3763e9bc760f988c9926b26da9dd85e928483446346b8ed00e1de5d5ea93e354abe706c)
and the generator , with as follows,
-
([0x02, 0x00],[0x013a59858b6809fca4d9a3b6539246a70051a3c88899964a42bc9a69cf9acdd9dd387cfa9086b894185b9a46a402be73,0x02d27e0ec3356299a346a09ad7dc4ef68a483c3aed53f9139d2f929a3eecebf72082e5e58c6da24ee32e03040c406d4f])
(I think "lexicographically smallest" means treating all numbers in the base field as non-negative, and just taking the smaller one, prioritising real parts over imaginary parts.)
Final exponentiation
Calculation of a pairing has two parts: the Miller loop and the final exponentiation. Both parts are quite expensive, but there's a nice hack you can do to reduce the impact of the final exponentiation.
Normally, we calculate two full pairings in order to perform signature verification, to check whether .
If we denote as the pairing without the final exponentiation, then for, some , we are checking whether . ( happens to be , which is huge23.)
We know how to multiply in group , so we can reorganise this as a check whether . (We can negate any one of the points: the magic of pairings makes this equivalent to taking the inverse in .)
So, to verify a signature, we do the two Miller loops, one with a negated input value, multiply the results and then do a single final exponentiation. If the result is unity in then our pairings match. This ought to give a worthwhile speedup.
Hashing to the curve
To calculate a digital signature over a message, we first need to transform an arbitrary message (byte string) to a point on the curve (if we are using for signatures). There are many ways to do this, with varying degrees of efficiency and security.
Hash and check
The initial implementation in Eth2 was "hash-and-check". This is very simple.
- Hash your message to an integer modulo .
- Check if there is a point on the curve with this -coordinate (real part , imaginary part ). If not, add one to and repeat this step.
- We have a point on the curve! Multiply by the cofactor to convert it into a point in (cofactor clearing).
About half the points that we try will result in a point on the curve, so this is not constant time: we don't know how many iterations it will take to find one. In one sense it doesn't matter: all the information is public, so we're not leaking anything. However, it does open up a griefing attack. An attacker could pre-calculate messages that take a very long time to find a point (1 in one million messages will take 20 tries, for example) and slow us down considerably.
Simplified SWU map
We have now adopted a better approach which is described in this paper and defined in RFC 9380, the IETF standard for hashing to curves. As before (but a bit differently to ensure a uniform distribution of output points) we first create a field point by hashing the message mod (the "expand message" step).
Next we use a special map (the SWU map) that is guaranteed to translate that field point into a valid point on an elliptic curve. For technical reasons, this is not the curve , but a curve isogenous to it (i.e. having the same number of points). We then use another map (3-isogeny) to transfer this to a point on . Finally we use cofactor clearing to end up with a point in .
You can take a look at my implementation of this in Java , based on the reference code in Python. The idea is for this approach to be generally adopted to enhance the interoperability of blockchains.
Cofactor clearing
We discussed multiplying by the cofactor as a way to make an arbitrary point on or into a point in or respectively. This is useful when hashing to the curve, for example.
The co-factor is huge, so multiplying by it is slow. However, there are faster ways to map curve points into using an endomorphism (a map of a group to itself). This features in the RFC 9380 standard.
The endomorphism we use was until recently subject to a patent, but, as of 2020, this patent has expired everywhere.
As a workaround to the patent before it expired, instead of multiplying by the cofactor, the standard suggests multiplying by an effective cofactor, (see section 8.8.2 of RFC 9380 for the value), which gives the same result as the endomorphism. The effective cofactor is even larger than the cofactor, but the multiplication can be implemented using an addition chain as an optimisation.
Now that the patent has expired, the endomorphism can be just dropped in as a replacement for the effective cofactor multiplication.
Extension towers
Recall our discussion of field extensions? In practice, rather than implementing a massive 12th-degree extension directly, it is more efficient to build it up from smaller extensions: a tower of extensions.
For BLS12-381, the field is implemented as a quadratic (degree two) extension, on top of a cubic (degree three) extension, on top of a quadratic extension of .
As long as the modular reduction polynomial (our reduction rule) is irreducible (can't be factored) in the field being extended at each stage, then this all works out fine.
- is constructed as where .
- is constructed as where .
- is constructed as where
Interpreting these in terms of our previous explanation:
- We write elements of the field as first degree polynomials in , with coefficients from , and apply the reduction rule , which is irreducible in .
- an element of looks like where .
- We write elements of the field as second degree polynomials in , with coefficients from the field we just constructed, and apply the reduction rule , which is irreducible in .
- an element of looks like where .
- We write elements of the field as first degree polynomials in , with coefficients from the field we just constructed, and apply the reduction rule , which is irreducible in .
- an element of looks like where .
This towered extension can replace the direct extension as a basis for pairings, and when well-implemented can save a huge amount of arithmetic when multiplying points. See Pairings for Beginners section 7.3 for a full discussion of the advantages.
Coordinate systems
Finding the inverse of a field element (i.e. division) is an expensive operation, so implementations of elliptic curve arithmetic try to avoid it as much as possible. It helps if we choose the right coordinate system for representing our points.
Affine coordinates
Affine coordinates are the traditional representation of points with just an pair of coordinates, where and satisfy the curve equation. This is what we normally use when storing and transmitting points.
However, it is not always the most efficient form to use when actually working with points, and there are two other schemes I'm aware of that are used for BLS12-381.
The basic idea is to represent the coordinate using notional fractions, reducing the number of actual division operations needed. To do this, a third coordinate is introduced and we use for the internal representation of a point. Like our familiar fractions, there are many representations of the same value, all corresponding to a single actual value (, , are all the same number).
The two systems I know of in use for BLS12-381 are Standard Projective coordinates and Jacobian coordinates.
Standard Projective coordinates
The Standard Projective coordinate point represents the Affine coordinate point .
These are also called homogeneous projective coordinates because the curve equation takes on the homogeneous form . Points become straight lines through the origin in space, with the Affine point being the intersection of the line with the plane . Figure 2.10 in Pairings for Beginners gives a nice illustration.
Standard Projective coordinates are used by the Apache Milagro BLS12-381 library, and also by the noble-curves implementation.
Jacobian coordinates
A different kind of projective coordinates are Jacobian coordinates. In this scheme, the Jacobian point represents the Affine point . The curve equation becomes .
The sample code for the constant-time hash-to-curve uses Jacobian coordinates, as does the gnark-crypto library.
Note that, in both schemes, the easiest way to import the Affine point is to map it to .
BLS12-381 Reference
General
Parameter | Equation | Value | Comments | |
---|---|---|---|---|
Curve parameter | -0xd201000000010000 | |||
Field modulus | Hex: 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab Dec: 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787 | 381 bits, prime | ||
Subgroup size: , , | Hex: 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001 Dec: 52435875175126190479447740508185965837690552500527637822603658699938581184513 | 255 bits, prime |
Curve E(F_q)
Equation | |
Order | 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb15400008c0000000000aaab |
Order (decimal) | 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129030796414117214202539 |
Prime Factorisation | 3 11 10177 859267 52437899 |
The product of the factors of the group order, excluding , are (by definition) the cofactor of the subgroup with order ( in this case).
Observe that the number of points on curve , its order, , is (in some sense) very close to the field modulus, . This is a consequence of the Hasse bound.
Subgroup G_1
Order | |
Generator | (0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb, 0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1) |
Cofactor | 0x396c8c005555e1568c00aaab0000aaab |
The cofactor is the factorisation of the curve order, , excluding the term.
Curve E'(F_q^2)
Equation | |
Order | 0x2a437a4b8c35fc74bd278eaa22f25e9e2dc90e50e7046b466e59e49349e8bd050a62cfd16ddca6ef53149330978ef0137697386bf984315744a2d5eb3dd4d213f2484c55b94474ab096de2c62640b2643116b1e2788e6a8b2a9fffe1c7238e5 |
Order (decimal) | 16019282247729705411943748644318972617695120099330552659862384536985976748491357143400656079302193429974954385540174732940659106207100323726025938325193045129788127168347624263893040187112659960846674086295148469572963088890738917 |
Prime Factorisation | 13 23 2713 11953 262069 402096035359507321594726366720466575392706800671181159425656785868777272553337714697862511267018014931937703598282857976535744623203249 |
The order of curve , , is close to the square of the field modulus, .
Subgroup G_2
Order | |
Generator | ([0x024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8, 0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e], [0x0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801, 0x0606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be]) |
Cofactor | 0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5 |
The cofactor is the factorisation of the curve order, , excluding the term.
Resources and further reading
There are lots of references linked in the above, and I'm not going to repeat many here. I'll just pick out a few particularly useful or interesting things.
Useful reference material:
- The original BLS12-381 announcement
- Concise description of the parameters and serialisation
- Draft IETF standard
In general, implementations of pairing libraries tend to be highly optimised and/or very generic (supporting many curves) which makes them quite hard to learn from. The Noble BLS12-381 library in JavaScript/TypeScript by Paul Miller is among the easier to follow.
The blsh
REPL (a wrapper around the BLST library) is excellent for exploring the curve itself. See the grammar for the full functionality - the info
command alone is worth it. You can manually verify BLS signatures if you like.
Finally, a couple of random but fun and interesting reads:
- This white paper on Curve9769 is not directly relevant to BLS12-381, but is a well-written and wonderful exploration of the joys and pains of designing and implementing an elliptic curve (not a pairing-friendly one in this case).
- Pairings are not dead, just resting. A great overview presentation. Some BLS12-381 things.
Footnotes
-
While I did study mathematics many, many years ago, I diligently shirked anything, such as group theory, that smelt like pure maths. I regret this now. ↩
-
Do click through to the short clip of Dan Boneh explaining why all mathematicians should spend time in jail. ↩
-
Compact Multi-Signatures for Smaller Blockchains, Boneh, Drijvers, and Neven, 2018. ↩
-
That Ethereum's execution layer uses the almost, but not quite standard Keccak hash rather than the SHA-3 standard remains a burr in the underpants to this day. ↩
-
This document does not have the full force of an IETF standard. For one thing, it remains a draft (that is now expired), for another it is an IRTF document, meaning that it is from a research group rather than being on the IETF standards track. Some context from Brian Carpenter, former IETF chair,
I gather that you are referring to an issue in draft-irtf-cfrg-bls-signature-04. That is not even an IETF draft; it's an IRTF draft, apparently being discussed in an IRTF Research Group. So it is not even remotely under consideration to become an IETF standard...
-
This now deleted page is the reference for much of this section. Lots of curve data is also in the IETF specification. ↩
-
Our rule is "an extension field modular reduction" (terminology from here, section 4.4). We can think of it as analogous to the modulo operation in normal arithmetic: it keeps the degree of polynomials to within a given bound, just as the modulo operation keeps the size of numbers to within a given bound. The irreducibility requirement is akin to the polynomial being "prime", that is, having no non-trivial factors. ↩
-
Another point on is
(0x04,0x0a989badd40d6212b33cffc3f3763e9bc760f988c9926b26da9dd85e928483446346b8ed00e1de5d5ea93e354abe706c)
. On average about half of values result in a point on the curve, and for most of those both and are on the curve (for some, ). You soon get used to these ridiculously big numbers. ↩ -
Sometimes is used rather than here, with . I'm using . ↩
-
Here's a point on the curve:
(1+i, 0x17faa6201231304f270b858dad9462089f2a5b83388e4b10773abc1eef6d193b9fce4e8ea2d9d28e3c3a315aa7de14ca + i * 0xcc12449be6ac4e7f367e7242250427c4fb4c39325d3164ad397c1837a90f0ea1a534757df374dd6569345eb41ed76e)
↩ -
See the Asymmetric Pairings paragraph in the introduction to Subgroup security in pairing-based cryptography for more on why we prefer distinct subgroups for and . In short, asymmetric pairings are more secure and more efficient to compute than symmetric pairings, since the latter exist only on supersingular curves. ↩
-
Note that we lost the on here - this is the original curve , but now defined over . ↩
-
Basically, the trace of a point is , where k=12 in our case. Understanding this involves stuff like the Frobenius endomorphism, and that rabbit hole goes deep. ↩
-
Because we previously selected the trace zero subgroup. Pairings for Beginners dives into the details on this. ↩
-
This doesn't seem to be documented anywhere, but I got here by attempting to decode section 3 of Pairing-Friendly Elliptic Curves of Prime Order by Barreto and Naehrig. ↩
-
My thanks to Olivier Bégassat for this insight. ↩
-
Cue my usual rant about why it is still called discrete logarithm rather than discrete division in additively written groups. ↩
-
It is natural to write elliptic curve groups (like and ) additively due to the way that elliptic curve point addition is constructed geometrically. is not an elliptic curve group, but rather a finite field subgroup, in which multiplication is the more intuitive group operation. ↩
-
Numbers in this world are truly enormous. The number of times divides is 1299 digits long in decimal. This number is actually used in the final exponentiation when computing pairings (a multiplicative version of cofactor clearing). ↩
-
This is easy to see. The subgroup has order , and its cofactor is , such that , the order of the whole elliptic curve group. Consider an arbitrary element of the elliptic curve group. We have . Thus, . Alternatively, for every subgroup that is not , is a multiple of its order, so multiplying by "kills" all components of that are not in . While not specific to BLS12-381, here is an excellent article about cofactor clearing. ↩
-
This is a general property of roots of unity in multiplicative groups, not special to elliptic curves or pairings. For example, the set of fourth roots of unity in , , forms a group of order four under multiplication. ↩
-
A couple of online tools for factoring huge numbers are dCode, and Dario Alpern's tool) ↩
-
is actually the cofactor of the group in . Performing the exponentiation maps the element produced by the Miller loop into , the group of th roots of unity. When we account for the notational difference between additive and multiplicative groups, this is analogous to cofactor clearing for and discussed elsewhere in this section. ↩