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

Uploaded Source

Built Distributions

ark_algebra_py-0.2.0-cp37-abi3-win_amd64.whl (599.2 kB view details)

Uploaded CPython 3.7+ Windows x86-64

ark_algebra_py-0.2.0-cp37-abi3-win32.whl (610.9 kB view details)

Uploaded CPython 3.7+ Windows x86

ark_algebra_py-0.2.0-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.2.0-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.2.0-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.2.0-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.2.0-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.2.0-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.2.0-cp37-abi3-macosx_11_0_arm64.whl (705.9 kB view details)

Uploaded CPython 3.7+ macOS 11.0+ ARM64

ark_algebra_py-0.2.0-cp37-abi3-macosx_10_7_x86_64.whl (781.7 kB view details)

Uploaded CPython 3.7+ macOS 10.7+ x86-64

File details

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

File metadata

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

File hashes

Hashes for ark_algebra_py-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5398bd926e7f99afd7bcf40e1c56ac97f6f7b00d06f6a90344198ba8899069d0
MD5 67ea1a510fb4fbaef4e64d397d4171d3
BLAKE2b-256 a329b1f2e9345c4a7f3348cad9dc8d384ff687ca4768dc31b9ab7e77c4e4c956

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.2.0-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2e77b428004f4cb103ee5f91e0abdba1cfacffb06ec978ea60f52c634ae188f3
MD5 4af5a9da2bad0bed5d37e2097946da36
BLAKE2b-256 51fa8175a4cbacf95c6c6e01985c24ebc9bd60fbf20564024558e57a130ea834

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.2.0-cp37-abi3-win32.whl
Algorithm Hash digest
SHA256 ca4316ed410bf7018a30b2eaa8e10fb69fe62e39bcf5e4fb9200ff9941661862
MD5 5011140e1dd7151a32daa0f9c78c71a1
BLAKE2b-256 030ea35a69218590a5cf0b3492c7272e0ca179f7304fc4ad84bb7d4fd394f755

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.2.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ca3e676c4040478f3825690de1aab23a5b291c31bd433fc94c7557b510ac8376
MD5 7e0babd460bd8b710f20ba741bdf1208
BLAKE2b-256 102d50f55e3b6962a3d4299284343272cb3b6330d5fa0ac6a38f872868adcad6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.2.0-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 dd6fdf4611db9054a49433f5b974b9c2a7a52989c7875b1bc1c73f6f579ba478
MD5 9cd2d6d5665a2ac703aed512bf24888c
BLAKE2b-256 9e99b240c52d87f22b88f6c99fbf2ec85f96dcd9382c49144703a417e42cf08d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.2.0-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 3aad19a01d1696b799a84070d24dde16d2b6989a030b05b02fef5ea1688bf80e
MD5 d95051227ce4831dabed62981daf81ab
BLAKE2b-256 cd5aae9372515c2a8c8bad0731523b23dd99167f599770f45c2ef069f38aec8e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.2.0-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 5d8608ef98b9163c65a076adfe8d8c53c6332b19adce22d8702a80a90b1df49b
MD5 8755244058ea59bfdd272822112dbf2f
BLAKE2b-256 523278a9c4eeae46fbc49a559924c22c68dbee0ce800d527887c9bf547d7d384

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.2.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0fa10b05ff83a5671986098acb5092a91fcf5f5aeb97c8934b81269be35c768a
MD5 4ac4eb5946282f987e744bf4a8791674
BLAKE2b-256 db8469849a49945c9f26ab24bf99630c85f978a3fa5fe2ae347257405fafb9dd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.2.0-cp37-abi3-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 a877df33881c8b4c3e2aec03084e1451a9c066716919b0b5171d101e4122b605
MD5 ccbebc0d13b2a04564a3375b16ad29c2
BLAKE2b-256 40f6e502585b7bce0b33ec70dd77c5445b23fe5f2d0e70cde7283d71015987a0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.2.0-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 495b522601737a8ed83b68ae9a7b09a2d846bf9f530f0f227b7cf45e98a511bf
MD5 afa476e73d05bcfd247bdc94f28db457
BLAKE2b-256 b64ca508c83ff02c8f9f54e0ad2a8ecc6bc51dab3372f483a2b7d8152a63f3fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.2.0-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 9d90cb4fcf5e67b5adc545e6915e9b660280322f4559141840036ee72ad20395
MD5 0fba4cb78a5f1298bd2281dc8124266d
BLAKE2b-256 8029e8cbb50e7a4fbee8e010a4a71d228f92098a2ef55396d712f58d2297b0bb

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