Skip to content
On this page

BLS12-381 โ€‹

BLS12-381 is a paring-friendly elliptic curve.
SmartPy supports all associated Michelson types and constructions including in tests in the interpreter.

See reference BLS12 template.

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.

See sp.TBls12_381_fr type.

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.

See sp.TBls12_381_g1 type.
See sp.TBls12_381_g2 type.

Operations โ€‹

Convert to int โ€‹

sp.to_int(<expression>)
a Convert an expression of type sp.TBls12_381_fr into sp.TInt .

Example โ€‹

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

anInt = sp.to_int(fr)
Michelson INT

Negation โ€‹

- expr
Negate a curve point or field element.

Example โ€‹

python
g1 = sp.bls12_381_g1("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1")
g2 = sp.bls12_381_g2("0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801")
fr = sp.bls12_381_fr("0x2ef123703093cbbbd124e15f2054fa5781ed0b8d092ec3c6e5d76b4ca918a221")

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

Addition โ€‹

expr1 + expr2
Add two curve points or field elements.

Adding sp.TBls12_381_g1 withsp.TBls12_381_g1 producessp.TBls12_381_g1
Addingsp.TBls12_381_g2 withsp.TBls12_381_g2 producessp.TBls12_381_g2
Addingsp.TBls12_381_fr withsp.TBls12_381_fr producessp.TBls12_381_fr

Example โ€‹

python
g1 = sp.bls12_381_g1("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1")
g2 = sp.bls12_381_g2("0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801")
fr = sp.bls12_381_fr("0x2ef123703093cbbbd124e15f2054fa5781ed0b8d092ec3c6e5d76b4ca918a221")

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

Multiplication โ€‹

sp.mul(expr1, expr2)
Multiply a curve point or field element by a scalar field element.

Multiplying sp.TBls12_381_g1with sp.TBls12_381_fr producessp.TBls12_381_g1
Multiplying sp.TBls12_381_g2with sp.TBls12_381_fr producessp.TBls12_381_fr
Multiplying sp.TBls12_381_frwith sp.TBls12_381_fr producessp.TBls12_381_fr
Multiplying sp.TNat withsp.TBls12_381_fr producessp.TBls12_381_fr
Multiplying sp.TInt withsp.TBls12_381_fr producessp.TBls12_381_fr

Example โ€‹

python
g1 = sp.bls12_381_g1("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1")
g2 = sp.bls12_381_g2("0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801")
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)
Michelson MUL

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 โ€‹

python
listOfPairs = sp.list([
    sp.pair(
        sp.bls12_381_g1("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1"),
        sp.bls12_381_g2("0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801")
    ),
    sp.pair(
        sp.bls12_381_g1("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1"),
        sp.bls12_381_g2("0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801")
    )
])

isValid = sp.pairing_check(listOfPairs)
Michelson PAIRING_CHECK