# 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 ​

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 ​

x: sp.TBls12_381_g1 → sp.TBls12_381_g1
x: sp.TBls12_381_g2 → sp.TBls12_381_g2
x: sp.TBls12_381_fr → sp.TBls12_381_fr

Negate a curve point or field element.

#### Example ​

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

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

a: sp.TBls12_381_g1  b: sp.TBls12_381_g1 → sp.TBls12_381_g1
a: sp.TBls12_381_g2  b: sp.TBls12_381_g2 → sp.TBls12_381_g2
a: sp.TBls12_381_fr  b: sp.TBls12_381_fr → sp.TBls12_381_fr

Add two curve points or field elements.

#### Example ​

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

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

### Multiplication ​

sp.mul(a: sp.bls12_381_g1, b: bls12_381_fr) → sp.bls12_381_g1
sp.mul(a: sp.bls12_381_g2, b: bls12_381_fr) → sp.bls12_381_g2
sp.mul(a: sp.bls12_381_fr, b: bls12_381_fr) → sp.bls12_381_fr
sp.mul(a: sp.nat, b: bls12_381_fr) → sp.bls12_381_fr
sp.mul(a: sp.int, b: bls12_381_fr) → sp.bls12_381_fr

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

#### Example ​

smartpy
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(p: sp.list[sp.pair[sp.bls12_381_g1, sp.bls12_381_g2]]) → sp.bool

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.

smartpy
listOfPairs = [
(