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

Uploaded Source

Built Distributions

ark_algebra_py-0.1.0-cp37-abi3-win_amd64.whl (598.4 kB view details)

Uploaded CPython 3.7+ Windows x86-64

ark_algebra_py-0.1.0-cp37-abi3-win32.whl (581.4 kB view details)

Uploaded CPython 3.7+ Windows x86

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

Uploaded CPython 3.7+ macOS 11.0+ ARM64

ark_algebra_py-0.1.0-cp37-abi3-macosx_10_7_x86_64.whl (780.2 kB view details)

Uploaded CPython 3.7+ macOS 10.7+ x86-64

File details

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

File metadata

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

File hashes

Hashes for ark_algebra_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8ed46a5822f5ab48b678e5a78f61f1e6a21f668c416e24e9d635c8125b4c617d
MD5 48ee306f3b88b195201651707b892fd0
BLAKE2b-256 ea66cbdb22ca86ccab376c378774c60fa7e9c8f6064fe0ac0d63a12f2098695b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.0-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ae2189e0818f4f333b23b55fd0686fe6fe0d6dc914f65c5712d13c9bf1ea83d6
MD5 0005fd809cff083ded298b46a2e1454b
BLAKE2b-256 c59e778230dadec0a5b11168f549b68229e4de8ce46c7d48137e78bdf5bd7df3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.0-cp37-abi3-win32.whl
Algorithm Hash digest
SHA256 8b54ccdc9f2032b98c71ed0938410e181495c8e2c30af9b5d88d9b0970e588f2
MD5 71632d41f819d2e4fefd4ac35ac69be6
BLAKE2b-256 58f7a63284caf592773f388156bc50cd8ae38878bd1379558ca4c4a8572825e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 17541f1b9a36205f63523278804e8d1edde4d33c2cf389417d4d3acfcd730368
MD5 905a2c61b102fb584ceac53b42abbefd
BLAKE2b-256 c79af0e4f4f82da61e4429daabfa9613d9be5175346a080288d44d16a07ac7b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.0-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 4417e6b9d6c9b1fd6306813db17b6a54c9b0734a85f2d971f44c88b4d7aa8041
MD5 359604ad1208b381276bd895b70e3df7
BLAKE2b-256 4eb6c3605fa0e4764b1d27f5474efee069ceb40d422731bf190ed72590fb84b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.0-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 1a49b6bf6df6c2f0ca3d8cfc8d49bb0c14b6b76e46f6363ffc05df06de97ae56
MD5 7bc50db5236c892899026751842adf98
BLAKE2b-256 ff96558ff7dcc0ed2b16518a52b0a0bfa718b6e97590bffa37dce73c72fd1687

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.0-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 1fb0b8cd91951442443be158dc81033d28ed6ad41a731c0ad483813aee0ba012
MD5 577092c1d342733e9cd1392ae9df3b99
BLAKE2b-256 3efba1c0ce778baf562e590bb0eabf333254f2a336b1521006836fb3168e522e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 06eb5273720317188f789f113fe0e6685a508713a2141c2c11fc33ed0a150f9b
MD5 d7f287a9699c43e2470a237119fec699
BLAKE2b-256 b22ea1c0ca2c18531cf97a779af35add2ada8e0a4bce3c409b1681d14610f970

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.0-cp37-abi3-manylinux_2_12_i686.manylinux2010_i686.whl
Algorithm Hash digest
SHA256 45e69d1a14bf61960b168cd52346ebc57cc4fce1341fa73e4a1e859fdc862d38
MD5 e218d2f0898bded9535edfddaab4d8a9
BLAKE2b-256 045d1af2d05dfc9cbb292b45aff3d653cd5cd89fd32b396b28b88dcce5356058

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.0-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f89936e8628f6faeeb8d64fb61df4b8cc6e01b58718f4e7c382d59cbb2c516e3
MD5 c9b823f63704e133dfa29aaf5a0e9508
BLAKE2b-256 4f493635dce74d77b9ea26fefa99dc71adf1c135c7b4ff1aa2579e6fcb8e2485

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.1.0-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 8254b0351161472e54d7c6a8c8e0255168b50ba24172ce9c8608c80f7c35b8d8
MD5 578e002a18899d5c1886a73d739647bb
BLAKE2b-256 ebf495d1a2f55846b22ad516bb6f13900d3dab0365262b2862b8d4f61eb5cd98

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