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.3.tar.gz (17.2 kB view details)

Uploaded Source

Built Distributions

ark_algebra_py-0.1.3-cp37-abi3-win_amd64.whl (597.2 kB view details)

Uploaded CPython 3.7+ Windows x86-64

ark_algebra_py-0.1.3-cp37-abi3-win32.whl (600.9 kB view details)

Uploaded CPython 3.7+ Windows x86

ark_algebra_py-0.1.3-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.3-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.3-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.3-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.3-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.3-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.3-cp37-abi3-macosx_11_0_arm64.whl (706.9 kB view details)

Uploaded CPython 3.7+ macOS 11.0+ ARM64

ark_algebra_py-0.1.3-cp37-abi3-macosx_10_7_x86_64.whl (778.1 kB view details)

Uploaded CPython 3.7+ macOS 10.7+ x86-64

File details

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

File metadata

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

File hashes

Hashes for ark_algebra_py-0.1.3.tar.gz
Algorithm Hash digest
SHA256 ff4939ecf1732e265fe6bbd61e93d3386ce350b356fa1b7477b56bd1a893baee
MD5 a0f3d7c40031ef06b96df52d7b8f7f2d
BLAKE2b-256 5b21f3b968d5a7f31223fb7514b4ec9ff47f87b8eb99965ea11e31d03d504dc3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.3-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 3b21926182241d70e2e2314adc2e10ac816afc7d85df5e0809575b833b5c026a
MD5 23708fdced2fe01f16b44a1fcf4b1d21
BLAKE2b-256 6dd04b90e9633528f826a539764755067a92b8c32d7c7fe9dd50cd8af44238ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.3-cp37-abi3-win32.whl
Algorithm Hash digest
SHA256 b3cce53c260ce13148883568c25c3ac8d48b49259e8598f0a77e3b50ae3e45ea
MD5 73bfc49743139d405241de018efaa5a5
BLAKE2b-256 48e719b242bafdfa46d2b596ed5b18b16fa5f895cf4aed0cd135a61e085454de

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.3-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b5845d2842e707315a0304a5e6ce76b06c1bd84f564ed9a94446c08fb29e7cc3
MD5 5348fe42da7719b496713b256ea4a482
BLAKE2b-256 4004fe27c3c1e8753791e4138f77a8b7a5fd9557fbe45cf02f89a7f6666cb88f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.3-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 88eb96897ab6d98636e30ddd09d18592fef21b46de3a4c7ef577c1997944a38e
MD5 331305b867a591304bd8603e80fa1852
BLAKE2b-256 5c1ac8c95988dcbd6ddf44a10827faaeee3141b35c29340eb88e2db8ab30ca40

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.3-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 2543cbf5d846b14f4c43ad15c77ed27859bcb842801043d69d3966451f78a518
MD5 c6bc33ac3910c3e44c59c5a957c06ce1
BLAKE2b-256 c6ac90bb41b85ab832084da832bf635a5e131306219cb939faa2e77421b435c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.3-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 673e4050f10c0c641c7a98d0676c5cad791ba8ddd43e292b1d2a54855e54c597
MD5 b7e35f304564d97a43daefaa61799c7a
BLAKE2b-256 08624c83b8f26b63343e5dab89e1279cb59bbda9ead28a9298d7700b07b008ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.3-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b9f2d353b312840b9c535b90ebf4020a1098cdce8d9509ddde0265df31676da8
MD5 33ff283660032f2aac0eea75ddcc293f
BLAKE2b-256 e8511b64c29e9e37068ebf2e98b191b5517e02516d6ddbabf1c43ccbfa36c72f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.3-cp37-abi3-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 dda92a2943593bd4d76e41ef72a1f7ffc75e247bbcb0682a49c3ca9cb4cee591
MD5 8364a04b50550cc01fba334feb769fcb
BLAKE2b-256 cb65da83c5ad3d062cfe642fdcbaf83c4f69722f733ad50d480802f060c7a984

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.3-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c508d42cc9346257f76defa4e8b200d21554084fb3e1fda2c334bfdbc3490e59
MD5 5a2739b7a7eff856ecd452113ed8571a
BLAKE2b-256 011540b07cd41aec287527bd3deb659cccccbf15585cd2a66a700c8b3077480f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.3-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 e9409da01af977a9a5f9b3339c3035abaab25c2215144e9e1d5c099d772c9bed
MD5 0c882384e7bb97e15709d5abb5b8cff2
BLAKE2b-256 6fd6ad19c330b0df575f6f02ace9f866926ee3f399a8633f6a60f251efc3f5b0

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