## Elliptic Curve Cryptography

$secp256k1$: used by Bitcoin and Ethereum to implement public key cryptography. Elliptic curve over a field $z_{p}$ where $p$ is a 256-bit prime.

ECDSA: Elliptic Curve Digital Signature Algorithm

Public key cryptography uses this method to calculate public keys which is a point on ECC curve.

$K=(k∗G)%p$

- $K$ = 512-bit public key
- $k$ = 256-bit randomly generated private key
- $G$ = base point on the curve
- $p$ = prime number

Take a base point $G$, add it $n$ (private key) times to make $nG(%p)$ (public key).

Note: addition here means addition in elliptic curve and not addition in field of integers mod p.

Order of a base point is when keys generated using this point starts to form a cycle. Max number of points on the curve.

Thus, choosing a good base point is necessary in any public key generation curves.

secp256k1:

The order is:

Ethereum public keys are serialisation of 130 hex characters

04 is prefixed as it is used to define uncompressed point on the ECC.

Ethereum addresses are hexadecimal numbers, identifiers derived from the last 20 bytes of the Keccak256 hash of the public key.

### Why Discrete Logarithm?

ECC is significant because solving $k∗G$ is trivial but obtaining $k$ from product $k∗G$ is not.

$k∗G$ can be obtained using Fast-Exponentiation algorithm but solving for $k$ requires computing discrete logarithms.

## Security

Big-O Notation of discrete logarithm problem is $O(n )$.

Base point $G$, is chosen to be closer to $2_{256}$ and thus is in the order of `256`

.

So, $256 =128$ bits level of security is provided by curves like $secp256k1$.

## secp256k1 v/s secp256r1

$secp256k1$ is a Koblitz curve defined in a characteristic 2 finite field while $secp256r1$ is a prime field curve.

Not going into details as to what a characteristic 2 finite field is, we can specify $secp256r1$ as a pseudo-randomised curve and $secp256k1$ as completely random curve which can’t be solved using discrete logarithm problem **yet**.

## Pairing Friendly Curves

Pairing-based cryptography is a new cryptographic primitive that has been developed in recent times, enabling new applications like short digital signatures that are aggregatable, identity-based cryptography, MPC, efficient polynomial commitments.

They have a favourable embedding degree, and a large prime-order subgroup.

### BLS12-381

Most of these notes are taken from this amazing post by Ben

This was first introduced by Sean Bowe from ZCash in 2017 and has been used in various things from then. Now for the naming,

- BLS stands for Barreto, Lynn, Scott.
- 12 stands for embedding degree of the curve
- 381 stands for the order of the prime used for the field $2_{381}$, i.e. number of bits used to represent coordinates on the curve.
**Why 381?**because 48 bytes per field element and remaining 3 bytes for flags or arithmetic optimisations.

Equation: $y_{2}=x_{3}+4(modq)$

Key parameters of the curve are derived from a single parameter $x$ = `-0xd201000000010000`

- Field modulus, $q:31 (x−1)_{2}(x_{4}−x_{2}+1)+x$
- Subgroup size or the number of points on the curve, $r:(x_{4}−x_{2}+1)$

Reason for such x:

- low hamming weight, allows for efficient pairing operation
- field modulus in 381 bits, efficient curve operation in 64 bit machines
- subgroup size of 256 bits
- curve security of 128 bits
- nth root of unity for FFT

#### Field Extensions

The two curves used in BLS12-381 are defined on $F$ and $F_{q_{12}}$. This power raised is known as an extension field of field $F_{q}$.

Let’s construct $F_{q_{2}}$, quadratic extension of $F_{q}$. element representation $F_{q_{2}}:a_{0}+a_{1}x$ also written as $(a_{0},a_{1})$.

- addition: $(a,b)+(c,d)=(a+c,b+d)$
- multiplication: $(ac−bd,ad+bc)$

Understanding multiplication is a tricky thing and it takes time to get accustomed to field arithmetic. Basically, the original multiplication has a $x_{2}$ term which doesn’t make any sense in the $F_{q_{2}}$ field, so we need a mechanism to remove this term. This is where reduction of polynomial terms is used. Certain rules are used to reduce the polynomials having degree greater than 2. Rule in this case is $x_{2}+1=0$

There are only 2 rules about this rule:

- the polynomial we’re reducing must be a $k$ degree polynomial, where $k$ is the extension degree.
- It must be irreducible in the field it is getting extended.

BLS12-381 consists of two curves: $G_{1}$ and $G_{2}$. $G_{1}$ is a fairly simple curve defined over finite field $F_{q}$. We can call this curve $E(F_{q})$. Curve equation for $G_{1}$ is $y_{2}=x_{3}+4$.

The other curve is defined over an extension of $F$ to $F_{q_{12}}$. Since arithmetic on $F_{q_{12}}$ is fairly complex, it is reduced to $F_{q_{2}}$. So, we’ll call this curve $E_{′}(F_{q_{2}})$. Curve equation is slightly modified to be $y_{2}=x_{3}+4(1+i)$.

#### Subgroups

BLS12-381 is popular because it’s a pairing friendly curve. For pairings, we need two points from **distinct** groups, each of order $r$. The first curve only has one subgroup of order $r$, and thus we can’t just use that one curve. That’s why we require a second different curve which has a distinct subgroup of same order. Fortunately, this is exhibited by the curve defined over the extension field and one of these groups only contains points having a trace of zero. This is where $k=12$, embedding degree comes in. Thus, we have group $G_{1}$ of order $r$ in $E(F_{q})$, and a distinct group $G_{2}$ of same order in $E(F_{q_{12}})$. This enables pairings.

Note:

`Trace of Zero`

#### Twists

As explained earlier, that arithmetic on field $F_{q_{1}2}$ is fairly complex and inefficient. And all the curve operations like `add`

, `sub`

, `mul`

, etc. requires a lot of arithmetic. Thus, we need to transform the $E(F_{q_{12}})$ curve into a curve defined over a lower degree field that still has an order $r$ subgroup. Why we didn’t take this lower order field in the first place? Because we require subgroup having trace of zero points.

The basic idea for point compression is not only to restrict the first pairing argument to $E(F_{p})$, but also to take the second argument $Q∈E(F_{p_{12}})$ as the image $ψ(Q_{′})$ of a point on a sextic twist $E_{′}(F_{p_{2}})$, where $ψ:E_{′}(F_{p_{2}})→E(F_{p_{12}})$ is an injective group homomorphism. This way one would work only with $E(F_{p})$ and $E_{′}(F_{p_{2}})$ for non-pairing operations like key generation, and map from $E_{′}(F_{p_{2}})$ to $E(F_{p_{12}})$ only when actually computing pairing values.

BLS12-381 uses a **sextic twist**. This means reducing the extension field degree by a factor of `6`

. We find a $u$ such that $u_{6}=(1+i)_{−1}$, then we define a twisting transformation as $(x,y)→(u_{2}x ,u_{3}y )$. This transforms the original curve from $E:y_{2}=x_{3}+4$ to $E_{′}:y_{2}=x_{3}+4/u_{6}$. $E$ and $E_{′}$ looks different but actually are same objected with coefficients in different base fields.

This twist gives curve $E_{′}$ that has a subgroup of order $r$ that maps to our $G_{2}$ group. So, we can work over more efficient $E_{′}(F_{q_{2}})$ and map $G_{2}$ back to $E(F_{q_{12}})$, when required.

Now, we have two groups:

- $G_{1}⊂E(F_{q})$ where $E:y_{2}=x_{3}+4$
- $G_{2}⊂E_{′}(F_{q_{2}})$ where $E_{′}:y_{2}=x_{3}+4(1+i)$

Since, point in $G_{2}$ are complex numbers, it takes twice the amount of storage and are more expensive to perform arithmetic operations.

#### Embedding Degree

Smallest $k$ with respect to $r$, where $r$ is a factor of the order $n$ of the curve, such that $q_{k}≡1(modr)$. Embedding Degree, $k(r)$ is the smallest positive integer required to extend the field to satisfy conditions required for pairings.

- $F_{q_{k}}$ contains more than one subgroup of order $r$ for constructing $G_{2}$.
- $F_{q_{k}}$ contains all the $r_{th}$ roots of unity for constructing $G_{T}$.

Embedding Degree should be chosen such that it doesn’t compromise security and efficiency. Basically, a higher embedding degree makes it harder to to solve DLP in $G_{T}$. But a higher embedding degree also make it harder to operations in higher field like $F_{q_{12}}$. Maximum available twist is degree six, so best we can do is reduce the field extension degree by six.

### Full Torsion Groups

Torsion group is a group where each element has finite order. $r$-torsion group of an Elliptic curve $E(F)[r]$, where $F$ is the finite field, $n$ is curve order, and $r$ is factor of $n$, is defined as set:

$E(F[r]):={P∈E(F)∣[r]P=O}$A simple example of $r$-torsion subgroups are the cyclic subgroups generated on each factor $r$ of curve order $n$.

Now, for an elliptic curve with defined on extension field $p_{m}$, the **full $r$-torsion group** is defined as:

An interesting observation is, $r$-torsion group $E(F_{p_{m}})[r]$ of a curve extension is equal to $E(F)_{p}[r]$ if power $m$ is less than the embedding degree of $E(F_{p})$. Full $r$-torsion groups contain $r_{2}$ many elements and $r+1$ subgroups, one of which is $E(F_{p})[r]$. These subgroups are used during finding appropriate subgroups for pairings.

$E(F_{p})E(F_{p})[r] ⊂E(F_{p_{2}})=E(F_{p_{2}})[r] ⋯⋯ ⊂⊂ E(F_{p_{k(r)}})E(F_{p_{k(r)}})[r] ⊂= E(F_{p_{k(r)+1}})E(F_{p_{k(r)+1}}) ⊂=⋯ ⋯ $Prove why full r-torsion group contain $r_{2}$ elements and $r+1$ subgroups?

### Cofactor

It’s the ratio of order of the curve group and order of the subgroup $hr=n$. Usually, cofactor should be very small in order to avoid subgroup attacks on discrete logarithms. But in pairing-based cryptography, the cofactors of $G_{1}$, $G_{2}$ and $G_{T}$ can be very large.

By multiplying by the cofactor, a point on the curve is mapped to the appropriate group known as **cofactor clearing**. Cofactors for $G_{1}$ and $G_{2}$ are as follows:

- $h_{1}=(x−1)_{2}/3$
- $h_{2}=$

### Roots Of Unity

Roots of Unity are complex solutions to the equation: $x_{n}=1$. Every nonzero element of a finite field is a root of unity, as $x_{q−1}=1$ for every nonzero element of $F_{q}$.[^3]

*Primitive root of unity* is when a number is solution to $x_{n}=1$ but not for $x_{m}=1$ for any positive integer $m<n$. So, if $a$ is a $n$th primitive root of unity in a field $F$, then $F$ contains all the roots of unity, $1,a,a_{2},…,a_{n−1}$.

Effect of the pairing is to map a point from $G_{1}$ and $G_{2}$ onto an $r$th root of unity in $F_{q_{12}}$. These $r$th roots of unity form a subgroup in $F_{q_{12}}$ of order $r$, which is the group $G_{T}$.

### Extension Towers

For BLS12-381, $F_{q_{12}}$ is constructed as a 2-3-2 extension tower, i.e. quadratic extension → cubic extension → quadratic extension.

- $F_{q_{2}}:F_{q}(u)/(u_{2}−β)$ where $β=−1$. Point in $F_{q_{2}}$ looks like $a_{0}+a_{1}u$ where $a_{j}∈F_{q}$. Reduction rule is $u_{2}+1=0$ which is irreducible in $F_{q}$.
- $F_{q_{6}}:F_{q_{2}}(v)/v_{3}−ξ$ where $ξ=u+1$. Point in $F_{q_{6}}$ looks like $b_{0}+b_{1}v+b_{2}v_{2}$ where $b_{j}∈F_{q_{2}}$. Reduction rule: $v_{3}−(u+1)=0$ which is irreducible in $F_{q_{2}}$.
- $F_{q_{12}}:F_{q_{6}}(w)/(w_{2}−γ)$ where $γ=v$. Point in $F_{q_{12}}$ looks like $c_{0}+c_{1}w$ where $c_{j}∈F_{q_{6}}$. Reduction rule: $w_{2}−v=0$ which is irreducible in $F_{q_{6}}$.