Skip to main content

No project description provided

Project description

py_arkworks_bls12381

The main usage of this library at this moment is to generate test vectors for EIP4844 in the consensus-specs. The library itself is generic, so feel free to use it for other purposes.

G1/G2Points

from py_arkworks_bls12381 import G1Point, G2Point, Scalar

# G1Point and G2Point have the same methods implemented on them
# For brevity, I will only show one method using G1Point and G2Point 
# The rest of the code will just use G1Point

# Point initialization -- This will be initialized to the g1 generator 
g1_generator = G1Point()
g2_generator = G2Point()

# Identity element 
identity = G1Point.identity()

# Equality -- We override eq and neq operators
assert g1_generator == g1_generator
assert g1_generator != identity


# Printing an element -- We override __str__ so when we print
# an element it prints in hex
print("identity: ",identity)
print("g1 generator: ", g1_generator)
print("g2 generator: ", g2_generator)

# Point Addition/subtraction/Negation -- We override the add/sub/neg operators
gen = G1Point()
double_gen = gen + gen
assert double_gen - gen == gen
neg_gen = -gen
assert neg_gen + gen == identity

# Scalar multiplication
#
scalar = Scalar(4)
four_gen = gen * scalar
assert four_gen == gen + gen + gen + gen

# Serialisation
# 
# serialising to/from a g1 point
# We don't expose the uncompressed form 
# because it seems like its not needed
compressed_bytes = gen.to_compressed_bytes()
deserialised_point = G1Point.from_compressed_bytes(compressed_bytes)
# If the bytes being received are trusted, we can avoid
# doing subgroup checks
deserialised_point_unchecked = G1Point.from_compressed_bytes_unchecked(compressed_bytes)
assert deserialised_point == deserialised_point_unchecked
assert deserialised_point == gen

Pairing

from py_arkworks_bls12381 import G1Point, G2Point, GT, Scalar


# Initilisation -- This is the generator point
gt_gen = GT()

# Zero/One
zero = GT.zero()
one = GT.one()

# Computing a pairing using pairing and multi_pairing
# multi_pairing does multiple pairings with only one final_exp
assert gt_gen == GT.pairing(G1Point(), G2Point()) 
g1s = [G1Point()]
g2s = [G2Point()]
assert gt_gen == GT.multi_pairing(g1s, g2s)

# Bilinearity
a = Scalar(1234)
b = Scalar(4566)
c = a * b


g = G1Point() * a
h = G2Point() * b

p = GT.pairing(g, h)

c_g1 = G1Point() *c
c_g2 = G2Point() *c

assert p == GT.pairing(c_g1, G2Point())
assert p == GT.pairing(G1Point(), c_g2)

Scalar

from py_arkworks_bls12381 import Scalar

# Initialisation - The default initialiser for a scalar is an u128 integer
scalar = Scalar(12345)

# Equality -- We override eq and neq operators
assert scalar == scalar
assert Scalar(1234) != Scalar(4567)

# Scalar Addition/subtraction/Negation -- We override the add/sub/neg operators
a = Scalar(3)
b = Scalar(4)
c = Scalar(5)
assert a.square() + b.square() == c.square()
assert a * a + b * b == c * c

neg_a = -a
assert a + neg_a == Scalar(0)
assert (a + neg_a).is_zero()

# Serialisation
compressed_bytes = scalar.to_le_bytes()
deserialised_scalar = Scalar.from_le_bytes(compressed_bytes)
assert scalar == deserialised_scalar

Development

You will need maturin to build the project.

pip install maturin
  • First activate the virtual environment
 source .env/bin/activate
  • Next build the rust package and install it in your virtual environment
maturin develop
  • Now run a file in the examples folder
python3 examples/point.py

Benchmarks

python3 -m examples.benches.bench

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ark_algebra_py-0.1.4.tar.gz (16.7 kB view details)

Uploaded Source

Built Distributions

ark_algebra_py-0.1.4-cp37-abi3-win_amd64.whl (598.5 kB view details)

Uploaded CPython 3.7+ Windows x86-64

ark_algebra_py-0.1.4-cp37-abi3-win32.whl (611.1 kB view details)

Uploaded CPython 3.7+ Windows x86

ark_algebra_py-0.1.4-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ x86-64

ark_algebra_py-0.1.4-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.0 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ s390x

ark_algebra_py-0.1.4-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.9 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ppc64le

ark_algebra_py-0.1.4-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.9 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARMv7l

ark_algebra_py-0.1.4-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.7 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARM64

ark_algebra_py-0.1.4-cp37-abi3-manylinux_2_12_i686.manylinux2010_i686.whl (1.9 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.12+ i686

ark_algebra_py-0.1.4-cp37-abi3-macosx_11_0_arm64.whl (705.2 kB view details)

Uploaded CPython 3.7+ macOS 11.0+ ARM64

ark_algebra_py-0.1.4-cp37-abi3-macosx_10_7_x86_64.whl (780.0 kB view details)

Uploaded CPython 3.7+ macOS 10.7+ x86-64

File details

Details for the file ark_algebra_py-0.1.4.tar.gz.

File metadata

  • Download URL: ark_algebra_py-0.1.4.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.2.3

File hashes

Hashes for ark_algebra_py-0.1.4.tar.gz
Algorithm Hash digest
SHA256 4db7b56e81b020f2157dc8c5b0f391544625ede71e9f25bfb2b5fdda602fb82b
MD5 1a47ea24bbd4e3c6c4d4791a002acc70
BLAKE2b-256 b8030e02375762e18db24685098ab09523471a9e9841a121d9c690506f9a5a99

See more details on using hashes here.

File details

Details for the file ark_algebra_py-0.1.4-cp37-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for ark_algebra_py-0.1.4-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 44bd33f9993e9095722f1903034cf0b39d7b146f324ac27d193a738e263130ba
MD5 3bdb44e76d57367ec4ca1210b8ba6862
BLAKE2b-256 7d9dddae06fcd540bdad69fcb22db0de2c1f5be1337fbe820f2e0c9101c2fb6d

See more details on using hashes here.

File details

Details for the file ark_algebra_py-0.1.4-cp37-abi3-win32.whl.

File metadata

File hashes

Hashes for ark_algebra_py-0.1.4-cp37-abi3-win32.whl
Algorithm Hash digest
SHA256 e2a69a1cdd593efac9fc90f3f3297d6d2aba6911cd2d8e1436ddbe001c2cec6f
MD5 765a62d6c47c9c9e271fad9b32a15ca8
BLAKE2b-256 a71e878db4d6fd0dae20aa72f70fba3486b034ba45e9369207e3b4ec4235f0b6

See more details on using hashes here.

File details

Details for the file ark_algebra_py-0.1.4-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ark_algebra_py-0.1.4-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d53caaa4581fc2476d310109a33d33a4434ae9fbe9c40b61e5b62bb85c6b32a9
MD5 331d6f889c77c172fcae58e66d583c26
BLAKE2b-256 fa684951222074c7fb05c2f4758aecd01a9da82699368ee96d17732693a0f0f3

See more details on using hashes here.

File details

Details for the file ark_algebra_py-0.1.4-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for ark_algebra_py-0.1.4-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 4faefe136522fd5af4cae92e5e85fff2bc26e3cbe7abf6e068ecc0334ffb6b0a
MD5 b08e210c2779bff4ab44bc2b6ddf35b7
BLAKE2b-256 c08db169b3b71b61e53829240274379ae6121831c38123f5fb621e98e3070259

See more details on using hashes here.

File details

Details for the file ark_algebra_py-0.1.4-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for ark_algebra_py-0.1.4-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 7c2421e665ea35762fe2256865f066e5b5c690ac04d76c2498c315ebc0788742
MD5 5e4669f4732b91265102783e7fc1eec1
BLAKE2b-256 8c09aca3bed8eaa972d0004468a12490a2eaa9ad47f67d3483179700dd176f72

See more details on using hashes here.

File details

Details for the file ark_algebra_py-0.1.4-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for ark_algebra_py-0.1.4-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 a89bd4feff521efb84f3283a6f453dac78eb1049dfe7ea6116b6a8c116cb750f
MD5 0c2252ae997f08bd4fb9646101a14fd2
BLAKE2b-256 b2cab9ede94668c30b098aad9f41407c1b09b3c07b982943388911c44c834ee7

See more details on using hashes here.

File details

Details for the file ark_algebra_py-0.1.4-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ark_algebra_py-0.1.4-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5a984ebaaef0dc8f96eab3093dea5ba4339075d89354c68dff59617aa74429ec
MD5 939d6e2f8a5c00d0bdeccb2eb996b1b0
BLAKE2b-256 3b3491ca3fbca310981aec6ad0fbbebfed8ac80e3fec40251503d988042e706e

See more details on using hashes here.

File details

Details for the file ark_algebra_py-0.1.4-cp37-abi3-manylinux_2_12_i686.manylinux2010_i686.whl.

File metadata

File hashes

Hashes for ark_algebra_py-0.1.4-cp37-abi3-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 52bb1fefddd1b13fbbfbff04c6910af9901726a72a083b6eacb8b68ae36a1175
MD5 6b708d0ff7c200ec59daa4248f62abaa
BLAKE2b-256 80e5da362efbd4a27457507a2ba4b9252e32ff1faf61f114c74de09a611f4d9d

See more details on using hashes here.

File details

Details for the file ark_algebra_py-0.1.4-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ark_algebra_py-0.1.4-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e4f9aa6a8a845dc44f2976f5616ef24a2e4223a77635a7af8f4d9b96d6d85023
MD5 dbb41eb09ec99a09707740da210c90f9
BLAKE2b-256 b27793b564ca5010e34697193936661035a7c53d61f284a303e6592e6c819909

See more details on using hashes here.

File details

Details for the file ark_algebra_py-0.1.4-cp37-abi3-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for ark_algebra_py-0.1.4-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 155b396f8f3e49effd133877eac4e8fb334cedf631bd59ccf080d51557892e26
MD5 e5eeff50b00c1b2a64e70d1abf55afa6
BLAKE2b-256 c83bc1525df744f5523bd9359d67c1b0601b118d666ad079653744ceb4fcb651

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page