diff options
Diffstat (limited to 'docs/journal/pages/pairings.md')
| -rw-r--r-- | docs/journal/pages/pairings.md | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/docs/journal/pages/pairings.md b/docs/journal/pages/pairings.md index 816e81a..793e5be 100644 --- a/docs/journal/pages/pairings.md +++ b/docs/journal/pages/pairings.md @@ -4,7 +4,7 @@ Pairings are the dark magic that make PLONK ZK systems work. They provide an **efficient** bilinear mapping from two groups to a third, all three with the same order `N`. -To have a feel for what you get with pairing, imagine a _fictional_ pairing function defined as `e(P, Q) = R` where, given `s` and `t` such that `P = sG` and `Q = tG` for some generator point `G`, then `R = (s * t)G`. This gives us the wonderful bilinear properties of pairings: `e(P, Q) = e(sG, tG) = e(G, stG) = e(tG, sG) = (s * t) * e(G, G)`. In many ways, this acts like "multiplication" in contract to the addition of points (where `P + Q = sG + tG = (s + t)G`). There is an issue with our _fictional_ pairing definition: it is not efficient. Specifically, given two points `P` and `Q` without knowing `s` and `t`, it is not possible to compute `s * t` (otherwise, you could efficiently solve the discrete logarithm problem, and you would have broken the cryptography that underpins Ethereum signatures). +To have a feel for what you get with pairing, imagine a _fictional_ pairing function defined as `e(P, Q) = R` where, given `s` and `t` such that `P = sG` and `Q = tG` for some generator point `G`, then `R = (s * t)G`. This gives us the wonderful bilinear properties of pairings: `e(P, Q) = e(sG, tG) = e(G, stG) = e(tG, sG) = (s * t) * e(G, G)`. In many ways, this acts like "multiplication" in contrast to the addition of points (where `P + Q = sG + tG = (s + t)G`). There is an issue with our _fictional_ pairing definition: it is not efficient. Specifically, given two points `P` and `Q` without knowing `s` and `t`, it is not possible to compute `s * t` (otherwise, you could efficiently solve the discrete logarithm problem, and you would have broken the cryptography that underpins Ethereum signatures). By some black magic, mathematicians found a function `e` that behaves like the multiplication above with some caveats: instead of all `P`, `Q` and `R` being points on a curve, they are part of three different groups (with the same order -- i.e. number of elements): @@ -12,23 +12,28 @@ By some black magic, mathematicians found a function `e` that behaves like the m - `Q` is a point on an elliptic curve over a polynomial extension field over the same finite field as `G1`, lets call that `G2` - `R` is **not** a point, but an element in the polynomial extension field over which `G2` is defined. -For BLS12-381: +There are a few such pairings (such as Weil and Tate pairings), but the most commonly used in practice are optimal Ate pairings. The optimal Ate pairing for BLS12-381 uses: - `G1` is just the elliptic curve BLS12-381 -- `G2` is... well complicated... _technically_, it is the BLS12-381 curve over a specific 12th degree polynomial extension field `Fp12`, with a chosen generator point. In practice, there exists another related curve over a 2nd degree polynomial extension field `Fp2` with a twisting operation that efficiently maps `E'[Fp2] -> E[Fp12]`. This allows you to do elliptic curve arithmetic much more efficiently in the `E'[Fp2]` curve, and then "convert" it to a point in `E[Fp12]` for the pairing computation itself. -- `GT` is a group of elements in `Fp12`, where the: - - The identity element is `1` - - The group operation is field multiplication +- `G2` is... well complicated... _technically_, it is the BLS12-381 curve over a specific 12th degree polynomial extension field `Fp12`. In practice, there exists another related curve over a 2nd degree polynomial extension field `Fp2` with a twisting operation that efficiently maps `E'[Fp2] -> E[Fp12]`. This allows you to do elliptic curve arithmetic much more efficiently in the `E'[Fp2]` curve, and then "convert" it to a point in `E[Fp12]` for the pairing computation itself. +- `GT` is a multiplicative subgroup of `Fp12` -The exact magic that we use isn't super important (and I don't pretend to fully understand it). +The exact magic that we use isn't super important (and I don't pretend to fully understand it). Additionally, I have found competing implementations compute the actual pairing value differently: +- The Pairing-Friendly Curves IETF draft document includes an algorithm for computing the optimal Ate pairing, however, I could not get an implementation to match the provided test vector. In fact, I could not find a single implementation that did pass the test vector (including implementations referenced in the IETF draft itself) +- Ethereum `py_ecc` Python implementation of ECC pairing implementation is the _closest_ to the algorithm in the Pairing-Friendly Curves IETF draft, but does not return the same value (it also ignore the sign of the curve's `x` parameter, which drives the Miller loop in the optimal Ate pairing implementation) +- Every other implementation I found (including `zkcrypto/bls12-381` used in ZCash, `kilic/bls12-381` used in Geth, Paul Miller's Noble Curves, etc.) returns yet another value, but implements the optimal Ate loop using more complicated yet more computationally optimal primitives -> Small note on differences in BN254 and BLS12-381 curves: the Miller Loop is implemented slightly differently in that there is a post-computation in the case of the BN254 curve at the end of the Miller Loop algorithm. As far as I can tell (information on this was relatively hard to find), but it is to untwist the point. +In the end, I don't believe the pairing value itself is _that_ important, as you typically build cryptography around "pairing checks", where `e(P1, Q1) * e(P2, Q2) * ... * e(Pn, Qn) = 1`. For example, for signing you provide a signature `S = k * H(m)`, where `k` is your secret key and `H(m)` is the hash of the message `m` to the `G2` curve; given a public key `P`, `e(G1, -S) * e(P, H(m)) = 1`, since that is equal to `e(G1, -k * H(m)) * e(k * G1, H(m)) = e(G1, H(m))^(-k) * e(G1, H(m))^k = 1`. This means that the what matters is that `e` is efficient, bilinear, and non-degenerate (which the implementations above all satisfy). + +> Small note on differences in BN254 and BLS12-381 curves: optimal Ate pairings are implemented differently for Barreto-Naehrig curves compared to Barreto-Lynn-Scott curves. # Resources - [BLS12-381 For The Rest Of Us](https://hackmd.io/@benjaminion/bls12-381) - [Pairings for Beginners](https://static1.squarespace.com/static/5fdbb09f31d71c1227082339/t/5ff394720493bd28278889c6/1609798774687/PairingsForBeginners.pdf) - [Exploring Elliptic Curve Pairings](https://vitalik.eth.limo/general/2017/01/14/exploring_ecp.html) +- [Ethereum Python ECC Pairing](https://github.com/ethereum/py_ecc) - [Noble Curves](https://github.com/paulmillr/noble-curves/blob/289db6f25979d226b3be2057c16d94e64dca3280/src/abstract/bls.ts#L97) +- [Pairing-Friendly Curves](https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-pairing-friendly-curves-11) > [Index](../README.md) |
