Skip to main content

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:

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.17-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

zk_dtypes-0.0.17-cp313-cp313-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

zk_dtypes-0.0.17-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

zk_dtypes-0.0.17-cp312-cp312-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

zk_dtypes-0.0.17-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

zk_dtypes-0.0.17-cp311-cp311-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file zk_dtypes-0.0.17-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.17-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0ef7f686122f0a5b555f5f6b73cf9b1ba0226876929bef2c8852ca244d2ba43d
MD5 f28559c948fca06101bf86595fb86f56
BLAKE2b-256 6b06be85fad8b3b7a9850e258d5588b7fb0c2bb08a272a462293cd6e8f57f2d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_dtypes-0.0.17-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.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.17-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.17-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e9c063f77f4b65886dca7fa619e73d88cc8a96196447e7fb80a9a3d5ac82cc20
MD5 a09a44c5307b203682c84da72f96e371
BLAKE2b-256 1e7c7eef89fc136d5e02f20bfc9414a5b1b9fc709d53c4bcecb0143d70d022fb

See more details on using hashes here.

Provenance

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

Publisher: release.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.17-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.17-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6ed751f93bc1fbcc4a366fe52a151b19dc7d73c0e2f7ac94fe9c47ad27edf8b2
MD5 a631919f97334ee22e4b2c874fb61941
BLAKE2b-256 eb84f46eb91da185effde463a5980e18e669c73af62e384e8dfc035cd2c77784

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_dtypes-0.0.17-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.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.17-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.17-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a653d6d8391212c794295d426c5d17d5d86812eec4b853db3209d02ef94b3bd0
MD5 0fef92588c2d3a978dd48f3b36820cf0
BLAKE2b-256 4bfe8590d06665642c87f39dbd098a39704a5b6c5436c0ff98052a967a32b374

See more details on using hashes here.

Provenance

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

Publisher: release.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.17-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.17-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c44ee3d4920eab319b7294f75fe85dd41671bfd088a34d3bc20d62ff22b810f3
MD5 4cb362d4b2c03a5221a5b3d12776d6df
BLAKE2b-256 f87b8e52259e0f7a1b1414a38df1787563ac5ea7f149d57127d06d8db9d624bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_dtypes-0.0.17-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.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.17-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.17-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 13f21e420694265ced92e672fb11dd4de70395fa98dcedfb94cbb705cabd6c23
MD5 ef9944ec03920d4b52062d4ffce30a71
BLAKE2b-256 1e646d0f4ee6e3126a9b91040f9b2920817aaa30db440f2384d13017cd5f2d30

See more details on using hashes here.

Provenance

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

Publisher: release.yml on fractalyze/zk_dtypes

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

Release history Release notifications | RSS feed

This release

0.0.17 This release

6 files

0.0.16

6 files

0.0.15

6 files

0.0.14

6 files

0.0.12

6 files

0.0.11

6 files

0.0.10

3 files

0.0.9

3 files

0.0.8

3 files

0.0.7

3 files

0.0.6

3 files

0.0.5

9 files

0.0.4

9 files

0.0.3

14 files

0.0.2

11 files

0.0.1

14 files

Supported by

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