Skip to main content

zk_dtypes is a stand-alone implementation of several NumPy dtype extensions used in Zero Knowledge.

Project description

zk_dtypes

CI

zk_dtypes is a stand-alone implementation of several NumPy dtype extensions used in Zero Knowledge libraries inspired by ml_dtypes, including:

  • Narrow integer:

    • int2
    • int4
    • uint2
    • uint4
  • Prime Field:

    • babybear
    • babybear_mont
    • goldilocks
    • goldilocks_mont
    • koalabear
    • koalabear_mont
    • mersenne31
  • Extension Field:

    • babybearx4
    • babybearx4_mont
    • goldilocksx3
    • goldilocksx3_mont
    • koalabearx4
    • koalabearx4_mont
    • mersenne31x2
  • Binary field:

    • binary_field_t0
    • binary_field_t1
    • binary_field_t2
    • binary_field_t3
    • binary_field_t4
    • binary_field_t5
    • binary_field_t6
    • binary_field_t7
  • Elliptic curve:

    • bn254_sf
    • bn254_sf_mont
    • bn254_g1_affine
    • bn254_g1_affine_mont
    • bn254_g1_jacobian
    • bn254_g1_jacobian_mont
    • bn254_g1_xyzz
    • bn254_g1_xyzz_mont
    • bn254_g2_affine
    • bn254_g2_affine_mont
    • bn254_g2_jacobian
    • bn254_g2_jacobian_mont
    • bn254_g2_xyzz
    • bn254_g2_xyzz_mont

Prerequisite

  1. Follow the bazel installation guide.

Build instructions

  1. Clone the zk_dtypes repo

    git clone https://github.com/fractalyze/zk_dtypes
    
  2. Build zk_dtypes

    bazel build //...
    
  3. Test zk_dtypes

    bazel test //...
    

Installation

The zk_dtypes package is tested with Python versions 3.11-3.13, and can be installed with the following command:

pip install zk_dtypes

To test your installation, you can run the following:

pip install absl-py pytest
pytest zk_dtypes/tests

Installation from source

To build and install the package from source, run:

pip install .

Installation from prebuilt binary

Use USE_BAZEL_OUTPUT=1 for a faster installation that uses pre-built Bazel artifacts. This is the recommended path for development.

  • On Linux / macOS

    # Build the shared library (.so)
    bazel build //zk_dtypes:_zk_dtypes_ext.so
    
    # Install using the Bazel output
    USE_BAZEL_OUTPUT=1 pip install .
    
  • On Windows

    # Build the Python extension (.pyd)
    bazel build //zk_dtypes:_zk_dtypes_ext.pyd
    
    # Install using the Bazel output (PowerShell syntax)
    $env:USE_BAZEL_OUTPUT=1; pip install .
    

Example Usage

>>> from zk_dtypes import babybear_mont
>>> import numpy as np
>>> a = np.array([-1, -3, 2**30, 7], dtype=babybear_mont)
>>> b = np.array([5, 2, 4, 10], dtype=babybear_mont)
>>> a + b
array([4, 2013265920, 1073741828, 17], dtype=babybear_mont)

Importing zk_dtypes also registers the data types with numpy, so that they may be referred to by their string name:

>>> np.dtype('babybear_mont')
dtype(babybear_mont)

See examples/zk_dtypes_examples.ipynb for more examples.

Benchmarks

Benchmarks are disabled by default (though CI verifies their validity). To execute a specific benchmark (e.g., field_mul_benchmark), run the following command manually:

bazel run -c opt //zk_dtypes:field_mul_benchmark

License

The zk_dtypes source code is a modified derivative of the ml_dtypes project and inherits the original Apache 2.0 License (see LICENSE). All subsequent modifications comply with and are released under the same license.

Pre-compiled Wheels Dependencies

Note that pre-compiled wheels utilize the following dependencies:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

zk_dtypes-0.0.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

zk_dtypes-0.0.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (948.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

zk_dtypes-0.0.5-cp313-cp313-macosx_11_0_arm64.whl (806.9 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

zk_dtypes-0.0.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

zk_dtypes-0.0.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (948.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

zk_dtypes-0.0.5-cp312-cp312-macosx_11_0_arm64.whl (806.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

zk_dtypes-0.0.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

zk_dtypes-0.0.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (939.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

zk_dtypes-0.0.5-cp311-cp311-macosx_11_0_arm64.whl (806.0 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file zk_dtypes-0.0.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f402bd9afbec82c97272f2ff80914b4a98c7ccea3f43e6d4e3f8485f41106159
MD5 0694affd99a25653f4a575d5b7f52985
BLAKE2b-256 0fb00bf7a157606a79f303c5c278cd9e3778610662cebd0d01982f55bb63050f

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_dtypes-0.0.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on fractalyze/zk_dtypes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zk_dtypes-0.0.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8bcaf192b3285fef83a96bad534c98acb15db668a517631a6ca0e505e0969005
MD5 2e140892760ef45578147b5d19e4d168
BLAKE2b-256 cade5b1c8b7ecc7c4fcda544bec75cae104b126c430a63eed439ed667303ba63

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_dtypes-0.0.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on fractalyze/zk_dtypes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zk_dtypes-0.0.5-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f5998c80f707a765aa51f5735f2bd79817bcc7259d5be1fa80d323121f172603
MD5 860ac07bab38ca56d5fe56ac8cb171a3
BLAKE2b-256 55ab966a071043a4cea6d54f8a1288474b790ed3deae010b29ad55152a90170e

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_dtypes-0.0.5-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: publish.yml on fractalyze/zk_dtypes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zk_dtypes-0.0.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f32ca72c604e3d566808e610a0f17a3eb4dbc905a95172c67ce09d8df993def9
MD5 31e6d8c227762b60141d1d9e82fcaf4b
BLAKE2b-256 fc38bfdcf7577efcd660e9031d5bee7b520941f8ab983abeed2d2205ef9d62bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_dtypes-0.0.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on fractalyze/zk_dtypes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zk_dtypes-0.0.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 62c647c4f8c54426f06be887120ed491b83b919ac0400eedc18b628d544585f5
MD5 0dafdbc4df97585844ff0ea4e85a277a
BLAKE2b-256 40ee54036c542462d2aabcc59b854fb9008563f91045397005a9d2be4562bde8

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_dtypes-0.0.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on fractalyze/zk_dtypes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zk_dtypes-0.0.5-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 77bdbc091a2ec971283d33e43fa707f5191b712a4da9b713955b8a2e247f59d5
MD5 d3998a233ccc6cfe225f2b06e296fddf
BLAKE2b-256 7ac8a0f1732355c63aa1d294c7592996ed4b5a70c0fae3da9ef4402c42ae809e

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_dtypes-0.0.5-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish.yml on fractalyze/zk_dtypes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zk_dtypes-0.0.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 06d1240f8d2a2190b675ef6d94f7785458fe96ae4fcefebbe51cb0a06ea4c2e0
MD5 b191bbb9fe7859f3355b044216640f88
BLAKE2b-256 b49c51b791a3a6cad0a7a4bbe20df4c2c2f421278b139e61c787dd9191d8aa73

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_dtypes-0.0.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on fractalyze/zk_dtypes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zk_dtypes-0.0.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f9ebbc31aef5dff5ac9fed404cb5b316ce2077014cca00fced33645df8cb0dde
MD5 cfb11fabbf7df072b8a29804b8019505
BLAKE2b-256 2e01637f409912c55df5d4a9f2fa785944ad93c466c541e514449d78fcbb08ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_dtypes-0.0.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on fractalyze/zk_dtypes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zk_dtypes-0.0.5-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3b237932ff3618611200e1eb9822a65ce8d9792c73a869aa21eac803e2e3d2c2
MD5 a43c02677b07f0458a4cee558394a1e9
BLAKE2b-256 fac005453e2f8a65800f5589a9ac9523b0af1106cf7ef8d34cd43de9e29fd710

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_dtypes-0.0.5-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: publish.yml on fractalyze/zk_dtypes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page