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.16-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.16-cp313-cp313-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

zk_dtypes-0.0.16-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.16-cp312-cp312-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

zk_dtypes-0.0.16-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.16-cp311-cp311-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for zk_dtypes-0.0.16-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 248b7c04337040b6b8e56e99abbec20ab9fee71db7d56bf4bab6dfb0c70bd0ec
MD5 76d0b4ccc788736b5220fd93ec3b331b
BLAKE2b-256 98de4d22686693f3c7580f9fd6e25eda5a49b34ab0ca494401bd795c48cff0c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_dtypes-0.0.16-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.16-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.16-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ec1852fafe0ff29d7e555c714f651735bad43b93057cffccb061f0c1d364f4cd
MD5 9f2ef206334fc9e0175d26aef2e3b1da
BLAKE2b-256 a36e1051e066e6f6a1c6003085b300cec8bb5467703fd3d43233136e2f88fa67

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_dtypes-0.0.16-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.16-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.16-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 83248d772fd7acfd4821b7e41e6e0b246ddf1d46bdfeaacf09f466468f2ecb68
MD5 f53013b324f0c77cf098d04b34f18e7b
BLAKE2b-256 36ff215845abd0ed67428c3d8e299773ebfabaf06cf48c2a4af222435b0691bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_dtypes-0.0.16-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.16-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.16-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 69d0e0929176e8b9c014e481dde3160c10c334bf8e59e0f571e81acb1b3408a1
MD5 4ace020716806fb0785ceb3e62270c0a
BLAKE2b-256 039b5163baf692ef347f721443a1039f644279356175a068674627778fe59cee

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_dtypes-0.0.16-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.16-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.16-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9ec9caf0e331b9cb6a2c32d27314766b8f0ddd3c0342c9063d7fea8b0222361e
MD5 7c21847266d650e4b33f2dbcd6b3cae7
BLAKE2b-256 f1fccf2ae70d8081b0198d65df0b52ab181aacfe606742bfa2fcabe7efc90e8b

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_dtypes-0.0.16-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.16-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.16-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 90907c7c0bdc7d5f6a5bbe91e4e4aea0a246577585d81ab3a3a36675023254ca
MD5 041a0c3fc9c6b57ba9a2de1ca8536716
BLAKE2b-256 b981a6ca43b950e8b96dd5ba45bcabb6a1cdd4a71237d0a1107213d8476eb69d

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_dtypes-0.0.16-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

0.0.17

6 files

This release

0.0.16 This release

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