# BLS12-381 ​

BLS12-381 is a paring-friendly elliptic curve.

## Types ​

### Scalar field Fr ​

An element of the scalar field Fr, used for scalar multiplication on the BLS12-381 curves G1 and G2. Written as raw bytes, using a little-endian encoding.

### Curve Points ​

Points on the BLS12-381 curves G1 and G2, respectively. Written as raw bytes, using a big-endian point encoding, as specified `here`.

## Operations ​

### Convert to int ​

smartpy
``````sp.to_int(x: sp.bls12_381_fr) -> sp.int
``````

Convert a `sp.bls12_381_fr` value to `sp.int`.

#### Example ​

smartpy
``````fr = sp.bls12_381_fr("0x2ef123703093cbbbd124e15f2054fa5781ed0b8d092ec3c6e5d76b4ca918a221")

x = sp.to_int(fr)
``````

### Negation ​

smartpy
``````- x
``````

Negate a curve point or field element.

#### Example ​

smartpy
``````g1 = sp.bls12_381_g1("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1")
fr = sp.bls12_381_fr("0x2ef123703093cbbbd124e15f2054fa5781ed0b8d092ec3c6e5d76b4ca918a221")

negatedG1 = - g1
negatedG2 = - g2
negatedFr = - fr
``````

`expr1 + expr2`

Add two curve points or field elements.

Adding sp.TBls12_381_g1 with sp.TBls12_381_g1 produces sp.TBls12_381_g1

Adding sp.TBls12_381_g2 with sp.TBls12_381_g2 produces sp.TBls12_381_g2

Adding sp.TBls12_381_fr with sp.TBls12_381_fr produces sp.TBls12_381_fr

#### Example ​

smartpy
``````g1 = sp.bls12_381_g1("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1")
fr = sp.bls12_381_fr("0x2ef123703093cbbbd124e15f2054fa5781ed0b8d092ec3c6e5d76b4ca918a221")

resultG1 = g1 + g1
resultG2 = g2 + g2
resultFr = fr + fr
``````

### Multiplication ​

`sp.mul(expr1, expr2)`

Multiply a curve point or field element by a scalar field element.

Multiplying sp.TBls12_381_g1 with sp.TBls12_381_fr produces sp.TBls12_381_g1.

Multiplying sp.TBls12_381_g2 with sp.TBls12_381_fr produces sp.TBls12_381_fr.

Multiplying sp.TBls12_381_fr with sp.TBls12_381_fr produces sp.TBls12_381_fr.

Multiplying sp.TNat with sp.TBls12_381_fr produces sp.TBls12_381_fr.

Multiplying sp.TInt with sp.TBls12_381_fr produces sp.TBls12_381_fr.

#### Example ​

smartpy
``````g1 = sp.bls12_381_g1("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1")
fr = sp.bls12_381_fr("0x2ef123703093cbbbd124e15f2054fa5781ed0b8d092ec3c6e5d76b4ca918a221")

resultG1 = sp.mul(g1, fr)
resultG2 = sp.mul(g2, fr)
resultFr1 = sp.mul(fr, fr)
resultFr2 = sp.mul(sp.nat(1), fr)
resultFr3 = sp.mul(sp.int(1), fr)
``````

### Pairing check ​

`sp.pairing_check(<pairs>)`

Verify that the product of pairings of the given list of points is equal to 1 in Fq12. Returns true if the list is empty.

`pairs` must be of type sp.TList(sp.TPair(sp.TBls12_381_g1, sp.TBls12_381_g2))

#### Example ​

smartpy
``````listOfPairs = [
(