Skip to main content

No project description provided

Project description

arkworks BLS12-381 bindings

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.

Usage examples

Scalar field arithmetic

from ark_algebra_py.ark_algebra_py 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)

Group arithmetic

from ark_algebra_py.ark_algebra_py import G1, G2, Scalar

# G1 and G2 have the same methods implemented on them
# For brevity, we will only see one method using G1 and G2;
# the rest of the code will just use G1

# Point initialization -- This will be initialized to the generator of G1.
g1_generator = G1()
g2_generator = G2()

# Identity element 
identity = G1.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 = G1()
double_gen = gen + gen
double_gen2 = gen.double()
assert(double_gen == double_gen2)
assert((double_gen2 - gen) == gen)
neg_gen = -gen
assert(neg_gen + gen == identity)

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

# 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 = G1.from_compressed_bytes(compressed_bytes)
# If the bytes being received are trusted, we can avoid
# doing subgroup checks
deserialised_point_unchecked = G1.from_compressed_bytes_unchecked(compressed_bytes)
assert(deserialised_point == deserialised_point_unchecked)
assert(deserialised_point == gen)

Pairings

from ark_algebra_py.ark_algebra_py import G1, G2, PairingOutput, Scalar, Pairing


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

# Zero/One
zero = PairingOutput.one()

# Computing a pairing using pairing and multi_pairing
# multi_pairing does multiple pairings and adds them together with only one final_exp
assert gt_gen == Pairing.pairing(G1(), G2()) 
g1s = [G1()]
g2s = [G2()]
assert gt_gen == Pairing.multi_pairing(g1s, g2s)

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


g = G1() * a
h = G2() * b

p = Pairing.pairing(g, h)

c_g1 = G1() *c
c_g2 = G2() *c

assert p == Pairing.pairing(c_g1, G2())
assert p == Pairing.pairing(G1(), c_g2)

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

Uploaded Source

Built Distributions

ark_algebra_py-0.2.1-cp37-abi3-win_amd64.whl (603.9 kB view details)

Uploaded CPython 3.7+ Windows x86-64

ark_algebra_py-0.2.1-cp37-abi3-win32.whl (584.9 kB view details)

Uploaded CPython 3.7+ Windows x86

ark_algebra_py-0.2.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

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

ark_algebra_py-0.2.1-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.7 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARMv7l

ark_algebra_py-0.2.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.5 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARM64

ark_algebra_py-0.2.1-cp37-abi3-macosx_11_0_arm64.whl (660.5 kB view details)

Uploaded CPython 3.7+ macOS 11.0+ ARM64

ark_algebra_py-0.2.1-cp37-abi3-macosx_10_12_x86_64.whl (730.7 kB view details)

Uploaded CPython 3.7+ macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for ark_algebra_py-0.2.1.tar.gz
Algorithm Hash digest
SHA256 ba92042dc65c0bea3bec83109de20a1ee78feda5cc7b00444610f8c2996165d0
MD5 daa1e16074d50d0080cf7f511fc832bf
BLAKE2b-256 65ce39c4f9bc2176c8b6691381f3eccc2c8102b384a81aa6291fc7142f70cd56

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.2.1-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 409ab28c08c8c55e2626adc0db6b4a3e155d4141cae5b8625ff63d420398391a
MD5 bfa08e142ee34d904bef026cf9af1676
BLAKE2b-256 6037b826b0dd816dd2215e129fe842c322101553df77c7397c166314116ccd26

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.2.1-cp37-abi3-win32.whl
Algorithm Hash digest
SHA256 83e6cd811d7c855c793e8d186c02b75488793a4972f5c5453cbe6ec2ca20e853
MD5 fa942fa5afe5a56b87215075075d48b7
BLAKE2b-256 3602a6916d9b250505002e1f4173cbeb934f93d3535c196441aea8aff6e6599f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.2.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bc472484619e93060e648a94bc3a6bc82edaa24dd943a3148581cce5b60d5fac
MD5 721c56ab525962b3b229e4a870413905
BLAKE2b-256 16521834b0392a5f8607e1e9a497c94bcb37c0f6ad5ae1b978965007ffa57f8d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.2.1-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 853e1644753906f9c64498ad979a201effc17b1a8814119f203dbace9ccd4b2c
MD5 49ce039adf7349ec87171656ddfcf983
BLAKE2b-256 587eae56857740bb65552c6167e25afed4de08547e5bb140f6b20970bfd26e0b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.2.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e07859ce95dccda6f1b50061a5b14eb434d7d8c311e53a53d661e9378470b661
MD5 aabd00622f0eb75d087c14f8955c8312
BLAKE2b-256 9619c5e9f3a765436374afe9022a741093bb603b498de3c8fd0065b3be296473

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ark_algebra_py-0.2.1-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5d7915e15db09040e8695596a85ca82e3bb2958633e1a9387b8c976b95a20f69
MD5 03c3c150f9e783779f241133fc4672f2
BLAKE2b-256 4a22b0730b0a251d99deaf926747206775238375e833c8b67be3e77b5f73f637

See more details on using hashes here.

File details

Details for the file ark_algebra_py-0.2.1-cp37-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ark_algebra_py-0.2.1-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 88b8a9f899e782d1aacf2d5bdece57e486cd81519be6e9cb33d89f83f4b0e12a
MD5 c04fe493c80420974badc814a95d15ee
BLAKE2b-256 1b80f3ed86c689e71f999cca0ee2fc764fce1f1ec91e7cbd8ee8fe0513c252c5

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