1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
> [Index](../README.md)
# Elliptic Curves
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. 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`.
The same principle can be extrapolated to doubling a point, which is a special case where `P = Q` in the example above, and the line would be the tangent to the curve passing by `P`. The formula of `x_R` and `y_R` are the same, but the slope is computed as the tangent `m = 3x_P^2 / 2y_P` (derivatives!).
It turns out that the equations for elliptic curves over real numbers also apply to finite fields, so yay! With this, we can implement the basic operations of a group over elliptic curve.
# Resources
- [A From-Scratch Tour of Bitcoin in Python](http://karpathy.github.io/2021/06/21/blockchain/)
- [Elliptic Curve Cryptography: a Gentle Introduction](https://andrea.corbellini.name/2015/05/17/elliptic-curve-cryptography-a-gentle-introduction/)
> [Index](../README.md)
|