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.7-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

zk_dtypes-0.0.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

zk_dtypes-0.0.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

File details

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

File metadata

File hashes

Hashes for zk_dtypes-0.0.7-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0ab346cbee3a634b7e9fe990fefe7a69ddbae2748e9eac0d76743630db9328ee
MD5 8a57db9b3319eaf1995f753a9ad9b6eb
BLAKE2b-256 e14e305fc199d2f541a5bfa7185938167a42006edec1603f3bea571d0e91339d

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_dtypes-0.0.7-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.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 879637a7dbb4914ba19ded1ef5c8ccfe83245800a7becefca809aeac8e4b8b5c
MD5 fdec0aa2774cb6dd305919234f4e9b35
BLAKE2b-256 de3800dc180ec75c9c5c19aa8b4c71451dc09767441dd1be364e7a4804e6e61a

See more details on using hashes here.

Provenance

The following attestation bundles were made for zk_dtypes-0.0.7-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.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1f48e53fd80fd68f50e1806fcad44e59aa74baa783bf7dcf2c74e88a51ba2620
MD5 5794597e5d6f87437c23df0ac8e51531
BLAKE2b-256 0d56e3a87416844e8ddd5c27aee188dfba83bedc27d2fbd0c0b53e8aaf3f3181

See more details on using hashes here.

Provenance

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

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