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.3-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (10.6 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

zk_dtypes-0.0.3-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (10.4 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

zk_dtypes-0.0.3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (10.4 MB view details)

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

zk_dtypes-0.0.3-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (10.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

zk_dtypes-0.0.3-cp314-cp314-macosx_15_0_arm64.whl (764.5 kB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

zk_dtypes-0.0.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (10.4 MB view details)

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

zk_dtypes-0.0.3-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (10.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

zk_dtypes-0.0.3-cp313-cp313-macosx_15_0_arm64.whl (764.7 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

zk_dtypes-0.0.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (10.4 MB view details)

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

zk_dtypes-0.0.3-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (10.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

zk_dtypes-0.0.3-cp312-cp312-macosx_15_0_arm64.whl (764.7 kB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

zk_dtypes-0.0.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (10.4 MB view details)

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

zk_dtypes-0.0.3-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (10.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

zk_dtypes-0.0.3-cp311-cp311-macosx_15_0_arm64.whl (764.7 kB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

File details

Details for the file zk_dtypes-0.0.3-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.3-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 495b887341fa28236d86ae81f0e59e2f49576d284e9e6b6aa3254a537fe21278
MD5 3a8f30af33ea8faaa190ff6d38a18552
BLAKE2b-256 9cd6f526f38ec84e973cdb4093ab59bbab2409a7bf835df52b456ea577458cee

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.3-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.3-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 baaab3a1419b1abfbf83cc854b4dd460ad411c804fa23137338646448074efd6
MD5 8e91d8efecb1597807160b43af8fe407
BLAKE2b-256 5c19c03db1b8820957eda344104ef42d26083550ae6d8e33801216ceef2a5614

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.3-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 98cd6c6235890f67cd250b39bbb73f1d1497a3449730074f94ce62abc6814825
MD5 8df5a06460df998259135d645252e6f6
BLAKE2b-256 fd4e5b3bc7ae4e6df2cf541469d1f699e92425d52de5a340387b98b6492f8ca3

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.3-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.3-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a4eadbb153cec3aed346b138906fc2259f9bd58f6bfab92ef6d90ad23bfa75ab
MD5 a044c5ed84dee3e5c8e5ae2a338bf6a2
BLAKE2b-256 03aee11011de973249f3975d8736c117989a50665daa916f1db5a2641516338a

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.3-cp314-cp314-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.3-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 a8c1c31a29184f8b32dfbe780cb6fc2b1540e85ee496af05f5d10f28f8b24453
MD5 6e7bba7de667ee66259e7d53605e1c70
BLAKE2b-256 d3d2ff20a4cd53b28414ab0f99c99ba025537c7694c0592275185e243e6fcce6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for zk_dtypes-0.0.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3628ae93932e0306d8ad3522697303005c82ba21090018a691779b40cd91f419
MD5 f3a6d01d4b25327372510c0a0788ea40
BLAKE2b-256 432ec65f5bbb27be7318371410aef1f8f364c2c0ab23fdc823415e466b6805d2

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.3-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.3-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b468b71aec9f18827ca0a7855ef468d2fba4d46a7752e2df7f606475f66c4dee
MD5 77b190c5b8afc974309c94c520bbe5c0
BLAKE2b-256 0f79d58ccabcf859c8d0c692f0afda4052ccda4490561b6bdbab5d29a8c76cc5

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.3-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.3-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 350ee7cbc9a26b06748100342bc991d2fcea843f848dcc71e4024d8d5672b8b1
MD5 2ec45f1a71b9f9803a44642c9cd99c05
BLAKE2b-256 612790657bf4da103f70f359b33ad36828b1e89fc52d190ef080d284603b5da3

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a66386cdaca68fb0145c608c09dfa3d7c635d67f7e49018aba0a444d6a7dd0a7
MD5 55e260fac58d86af80c38e20df1ebbb4
BLAKE2b-256 652717149022834782401e5cce4d95d2e55f44269f0c7309ee711bb2b69a07a0

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.3-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.3-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 877ee6a3e166c0307c662f9f5d6d3abc4f9ae599c032c7982e469c8712bd4e1a
MD5 97e4cafc0d7729360a4461673f3d27bd
BLAKE2b-256 2c77de83bd9b590cfdf6c6eb54ed252c0b4f6d0e6f566c8ad43807ef2799e6b1

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.3-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.3-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 2902ffb9dc3b1a63e08592712d5fac94fb4142b409c16a2f0d2ad5f6c27390f7
MD5 a94f425ac967e23823b7a770de863cc0
BLAKE2b-256 749a9519cdf7b0521ed0b47b094c862f7fb65816aaef65fcc27752fb415f2597

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 633ebfd92db56340d96a3cd8de41e254c04270ecde56c0ceb75700e62c03cd2a
MD5 717ecd76611f2c427ae18d20c66dda60
BLAKE2b-256 3670f74acd3eca7478d75ee7bf8fd9272c04995f5f0dd3d3104ec6cf856d8b4e

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.3-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.3-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 87382c7c85e22bc52d0044b796453e4aeafc9ae83a7f7d45c9d98c8b940bcaf1
MD5 a01466ed709b98ad8a14687a53548393
BLAKE2b-256 4a667abf5966773c5690d1e4a934ae4b82fda0622d5c8254c5e93ab4d1511f0f

See more details on using hashes here.

File details

Details for the file zk_dtypes-0.0.3-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for zk_dtypes-0.0.3-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 ae77954ae13b34548dbcbd4e4b3c4af401408561bdeb6d82209ddd4c5438beaa
MD5 65e04f56d8e4b4df4995e531ac0bfd77
BLAKE2b-256 dcf86ad2d18457c1b26fddb566a38c69222c7bdbd60c2c8f3a87e586eed2a069

See more details on using hashes here.

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