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

Uploaded Source

Built Distributions

ark_algebra_py-0.1.1-cp37-abi3-win_amd64.whl (600.0 kB view details)

Uploaded CPython 3.7+ Windows x86-64

ark_algebra_py-0.1.1-cp37-abi3-win32.whl (590.2 kB view details)

Uploaded CPython 3.7+ Windows x86

ark_algebra_py-0.1.1-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.1-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.1-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.8 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ppc64le

ark_algebra_py-0.1.1-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.1-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.1-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.1-cp37-abi3-macosx_11_0_arm64.whl (697.4 kB view details)

Uploaded CPython 3.7+ macOS 11.0+ ARM64

ark_algebra_py-0.1.1-cp37-abi3-macosx_10_7_x86_64.whl (785.9 kB view details)

Uploaded CPython 3.7+ macOS 10.7+ x86-64

File details

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

File metadata

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

File hashes

Hashes for ark_algebra_py-0.1.1.tar.gz
Algorithm Hash digest
SHA256 868ae2137488f0acbbc31a637d3fad5283258dc4c756525b70ad408054fb89d8
MD5 f61d358d88454a1a152d15042175f90d
BLAKE2b-256 4b15d595fe62599b46c7a4ca70c5eb96f53b7ac74afdccc5a30926ca3409d10d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.1-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1acc1d73b297224232c5100cddd6bb1438127eb15d900f105f32f44e00c59330
MD5 cba4ee9855fb068c6db34291607606d9
BLAKE2b-256 08035eb4d4543332d72e5fe3f990ea4f2ba7eff7aa173b870f8aa6e655b41773

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.1-cp37-abi3-win32.whl
Algorithm Hash digest
SHA256 dcdc73c558fdbd29a510260244f5bacea01ce167fca964f42d5dbd0f98c1540b
MD5 ea98e02655d87f3898c96d328042c433
BLAKE2b-256 be039447a0c6cea092f8aca5eaf38a61be6e825dbdaa12b38b29779e9aed8081

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3615fcb15bfd13a6a94a36d84d67be2f08b2ca0f9b8707d88f7c162c6bcda89b
MD5 27f7000b236472a6b38290b7507fa329
BLAKE2b-256 883c68cd82c5768366463bbb538a5065a789899d9d8429d951e66beb078f3661

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.1-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 5fa693d6c0b658e6faff45da672c7eb9b9b801c6a61dcdb0aeeb1bcd9eaf83bd
MD5 0522187a678e2e944bdae1bbf74d4a61
BLAKE2b-256 43d45126fad4dc3ff824dfd9d3f0ac820fa1cf59a138488b6a14b48c51bec82a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.1-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 f63f46af35d9f457b20175f985bbd9cf34146ca4abad787cdc9364604776c9ab
MD5 ad8cdeac437c354290c96f931395563a
BLAKE2b-256 7bfaed5d2605874562b6b9173e23a52b6138db4ec7f084901d40e6807b494ace

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.1-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 035c329759e5181aadaed92ed2440f2323ea0b1cc16fdc98734053cae8c3d0a1
MD5 2507d035d3ec7eb5330f2b84c2131eb9
BLAKE2b-256 49824d83b9f6a7752f02040d85d9ab05e2bc80bbd3d21104ef9bff64e8579b0e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 856ea1ec07f50f6c3791f10f51c9b26d825f49775066eba2751eb5f10b82f72d
MD5 5e84315693a55ebfa151cd59a2c50839
BLAKE2b-256 b33c7670408743adba1b690e933f0750822f0c773498282595309507a1934c05

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.1-cp37-abi3-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 aabf86428b0fbd92c0bd69d55d38c68f5c5cfc7394e11ab5de7c8fc79e9b8413
MD5 768415064f67332e00503546ed920169
BLAKE2b-256 e75f455ea9a60c1cdce849c7cbdb6fc0a12d4072c4017879d6002cee1cf10096

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.1-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4336c6e6a297bd0369ce4c79e8b773196f501d62d1fe4ac7e92be83c43e4cacb
MD5 aec9f63a5f5b787c6a2f8c39c564afde
BLAKE2b-256 38ab98fd85e83a253b50a6c2e8d50cf05eac9196b6f2441ecabdc35eeb739b16

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.1-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 5d3f411cc333dcdca9ce66940af503fb1f8ff2e0356045098036a6e1edf8705a
MD5 8086f319c8f0f9d26ab2f4ed210a2c01
BLAKE2b-256 2e64f8f9f50d7fcf3a2aac785800fa19c6f9c27118a84557c83bedb3c015d70c

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