diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2024-07-25 22:58:36 +0200 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2024-07-25 22:58:36 +0200 |
| commit | 5eb33df1046c6627cc80716ffccaa927284c91a7 (patch) | |
| tree | c0dbe0354426f20e14c3969df23b1318bdfe14ff /docs | |
| parent | 33fe06c71019b826e47d3fdcf0f217ee9f32b5b1 (diff) | |
Switch to BLS12-381
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/journal/pages/elliptic-curves.md | 4 | ||||
| -rw-r--r-- | docs/journal/pages/field-extension.md | 10 | ||||
| -rw-r--r-- | docs/journal/pages/finite-fields.md | 11 |
3 files changed, 9 insertions, 16 deletions
diff --git a/docs/journal/pages/elliptic-curves.md b/docs/journal/pages/elliptic-curves.md index 8e9695f..baecf02 100644 --- a/docs/journal/pages/elliptic-curves.md +++ b/docs/journal/pages/elliptic-curves.md @@ -2,9 +2,9 @@ # Elliptic Curves -We are implementing PLONK over the BN254 curve. Baretto-Naehrig curves are a type of elliptic curve that are designed to be pairing friendly, which we need for PLONK. +We are implementing PLONK over the BLS12-381 curve. Named after Barreto, Lynn, and Scott, BLS curves are a pairing friendly elliptic curve, which we need for PLONK. -Implementing elliptic curves is actually easier than it sounds. Elements are `(x, y)` coordinate pairs, where each of the coordinates is a field element from the prime field we previously implemented. Baretto-Naehrig curves specifically have equations of the form `y^2 = x^3 + b` for some `b ∈ Fp`. The BN254 curve we are implementing has `b = 3`. Note that there is another Barreto-Naehrig curve which is also sometimes called, BN254 with has `b = 2`, this is not our curve. +Implementing elliptic curves is actually easier than it sounds. Elements are `(x, y)` coordinate pairs, where each of the coordinates is a field element from the prime field we previously implemented. BLS curves specifically have equations of the form `y^2 = x^3 + b` for some `b ∈ Fp`. The BLS12-381 curve we are implementing has `b = 4`. Curves are abelian groups, so we can implement addition and scalar multiplication (which is just repeated addition). While the addition formula looks complicated, it actually isn't that hard to derive. Lets start with the basic idea of point addition on an elliptic curve: if you draw a straight line that passes through 3 distinct points `P`, `Q` and `R` on the curve, then `P + Q + R = 0` (where 0 is some imaginary point representing a "zero" value, i.e. additive identity, and sometimes referred to as the point at infinity). From basic algebra, we know that the slope of the line between two points is `m = (y_P - y_Q) / (x_P - x_Q)`. Also, because `R` is on the same line, we have `y_R = y_P + m(x_R - x_P)` (and equivalently `y_R = y_Q + m(x_R - x_Q)`). Figuring out how to compute `x_R` is a little more complicated (it involves cubic equations) so lets just share the formula: `x_R = m^2 - x_P - x_Q`. diff --git a/docs/journal/pages/field-extension.md b/docs/journal/pages/field-extension.md index f1ff95d..6995570 100644 --- a/docs/journal/pages/field-extension.md +++ b/docs/journal/pages/field-extension.md @@ -4,12 +4,10 @@ The other kind of field that is important for elliptic curve pairings are polynomial extension fields. These are just polynomial quotient rings over the curve's field modulo some irreducible monic polynomial (chosen as a parameter of the extension field). This concept is a _little_ complicated, and the Wikipedia article linked in the resources section does a decent job at explainng it (at least better than I can, as I lack a lot of the jargon required). -To try an explain it better, lets take the polynomial extension field of degree 2 used in BN254 pairings. This is defined as the polynomial quotient ring `Fp[x] / (1 + x^2)`, or `Fp2` for brevity, where `Fp[x]` are polynomials over the field `Fp`. With a slightly more concrete example, imagine the polynomials `a + bx` and `c + dx` belonging to `Fp2` where `a`, `b`, `c`, `d` are elements of `Fp` and `x` is some indeterminate also belonging to `Fp`. For this field, addition and multiplication are just definied to be the addition and multiplication modulo `1 + x^2` respectively of the polynomials. +To try and explain it better, lets take the polynomial extension field of degree 2 used in BLS12-381 pairings. This is defined as the polynomial quotient ring `Fp[x] / (1 + x^2)`, or `Fp2` for brevity, where `Fp[x]` are polynomials over the field `Fp`. With a slightly more concrete example, imagine the polynomials `a + bx` and `c + dx` belonging to `Fp2` where `a`, `b`, `c`, `d` are elements of `Fp` and `x` is some indeterminate also belonging to `Fp`. In code we can represent the elements of `Fp2` as a tuple of two `Fp` elements `Fp.t * Fp.t` where `(a, b)` represents `a + bx`. For this field, addition and multiplication are just definied to be the addition and multiplication modulo `1 + x^2` respectively of the polynomials. -- Addition: `(a + bx) + (c + dx) = (a + c) + (b + d)x`. Since we don't create any `x^2` terms, this is already non-divisible by `1 + x^2`. Addition in these polynomial extension fields are, therefore, very straight forward. -- Multiplication: `(a + bx) * (c + dx) = ac + adx + bcx + bdx^2`. This must be taken modulo `1 + x^2`, so `ac + adx + bcx + bdx^2 =~ ac + adx + bcx + bdx^2 - bd(1 + x^2) =~ (ac - bd) + (ad + bc)x`. - -Additionally, in code we can represent the elements of `Fp2` as a tuple of two `Fp` elements `Fp.t * Fp.t` where `(a, b)` represents `a + bx`. +- Addition: `(a + bx) + (c + dx) = (a + c) + (b + d)x`. Since we don't create any `x^2` terms, this is already non-divisible by `1 + x^2`. Addition in these polynomial extension fields are, therefore, very straight forward: `(a, b) + (c, d) = (a + b, c + d)`. +- Multiplication: `(a + bx) * (c + dx) = ac + adx + bcx + bdx^2`. This must be taken modulo `1 + x^2`, so `ac + adx + bcx + bdx^2 =~ ac + adx + bcx + bdx^2 - bd(1 + x^2) =~ (ac - bd) + (ad + bc)x`. Multiplication over `Fp2` is therefore `(a, b) * (c, d) = (ac - bd, ad + bc)`. Look familiar? It is the same as complex number multiplication - which isn't a coincidence as the complex numbers are an extension field of degree 2 over the real numbers. This same concept can be extended to polynomial extension fields of any degree, and in particular a polynomial extension field of degree 12 is also used for elliptic curve pairings (but with a different irreducible monic polynomial): @@ -23,8 +21,6 @@ Computing additive and multiplicative inverses are done by: - Additive inverse: this is just the component-wise additive inverse of the polynomial coeficients: `-(a + bx) = -a + (-b)x`. - Multiplicative inverse: this is a little more complicated, but can be done using the extended euclidean algorithm and Bézout's identity. -Furthermore, the same principles apply for the elliptic curve pairings for the BLS12-381 curve, but with different parameterization. - # Resources - [Polynomial Ring](https://en.wikipedia.org/wiki/Polynomial_ring) diff --git a/docs/journal/pages/finite-fields.md b/docs/journal/pages/finite-fields.md index 4e71672..b9f9eb4 100644 --- a/docs/journal/pages/finite-fields.md +++ b/docs/journal/pages/finite-fields.md @@ -4,21 +4,18 @@ One of the mathematical principles underpinning the PLONK proof systems are finite fields. These are used in both the PLONK circuits themselves, but also in the eliptic curve pairings necessary for the proof system. -In PLONKers!, we are building a very specific PLONK construction over the BN254 curve (sometimes referred to as "alt-bn128" or "bn128" - why? They are **B**arreto-**N**aehrig curves with a **254**-bit prime and an initially estimated security of **128** bits). This curve is defined over a finite field with a prime modulus. This sounds complicated, but it really means that: +In PLONKers!, we are building a very specific PLONK construction over the BLS12-381 curve. This curve is defined over a finite field with a prime modulus. This sounds complicated, but it really means that: -- `p = 21888242871839275222246405745257275088696311157297823662689037894645226208583`, a very large prime -- It is the set of whole numbers from `0` to `p - 1` (inclusive) +- `p = 4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787`, a very large prime +- It is the set of integers from `0` to `p - 1` (inclusive) - Addition and multiplication are done modulo `p` - Substraction is the addition of the additive inverse (`-a = p - a`, so `a + (-a) = 0` for all `a`) -- Division is the multiplication by the multiplicative inverse (`1/a = a ^ (p - 2) mod p`, so `a * (1/a) = 1` for all `a` except `0`, the inverse of `0` is undefined) +- Division is the multiplication by the multiplicative inverse (`1/a = a ^ (p - 2) mod p`, so `a * (1/a) = a * a (p - 2) = a ^ (p - 1) = 1` by Fermat's little theorem for all `a` except `0`, where inverse of `0` is defined to be `0`). Note that multiplicative inverses can also be computed with the extended Euclidean algorithm and Bézout's identity. And with this we build the "numbers" that we use for PLONK and eliptic curve operations. -The BLS12-381 curve as it has some nicer properties over BN254, and may show up in a future episode :). - # Resources -- [BN254 For The Rest Of Us](https://hackmd.io/@jpw/bn254) - [BLS12-381 For The Rest Of Us](https://hackmd.io/@benjaminion/bls12-381) - [`ethereum/py_ecc`](https://github.com/ethereum/py_ecc) |
