Skip to main content

The HEIR compiler

Project description

HEIR: Homomorphic Encryption Intermediate Representation

GitHub Workflow Status (with event) GitHub Contributors GitHub Discussions GitHub License OpenSSF Scorecard

An MLIR-based toolchain for homomorphic encryption compilers. Read the docs at the HEIR website.

For more information on MLIR, see the MLIR homepage.

Quickstart (Python)

Pip install the heir_py package

pip install heir_py

Then run an example:

from heir import compile
from heir.mlir import I64, Secret

@compile()  # defaults to scheme="bgv", OpenFHE backend, and debug=False
def func(x: Secret[I64], y: Secret[I64]):
    sum = x + y
    diff = x - y
    mul = x * y
    expression = sum * diff + mul
    deadcode = expression * mul
    return expression

func.setup()
enc_x = func.encrypt_x(7)
enc_y = func.encrypt_y(8)
result_enc = func.eval(enc_x, enc_y)
result = func.decrypt_result(result_enc)

print(
  f"Expected result for `func`: {func.original(7,8)}, FHE result:"
  f" {result}"
)

This will compile the function above using the BGV scheme to machine code via the OpenFHE backend. Then calling the function will encrypt the inputs, run the function, and return the decrypted result. The function call foo(7, 8) runs the entire encrypt-run-decrypt flow for ease of testing.

Building from source

This project uses bazel for its build system. Install bazelisk to manage the bazel version automatically. Then, with bazel on your path (pointing to bazelisk), run the following to build the main pass-running tool.

bazel build //tools:heir-opt

Or run an end-to-end test like

bazel test //tests/Examples/openfhe/ckks/halevi_shoup_matvec:all

HEIR depends on LLVM (from source) so a clean build may take 30 minutes depending on your machine. For faster builds, use BuildBuddy. Sign up for an account, create an API key, and add the following to .bazelrc.user in the root of the HEIR workspace:

common --remote_header=x-buildbuddy-api-key=<YOUR_API_KEY>
common --config=remote

This should reduce a clean build time to about 5 minutes.

See the bazel tips page for more example commands and tips on using bazel.

Supported backends and schemes

Backend Library BGV BFV CKKS CGGI
OpenFHE
Lattigo
tfhe-rs
Jaxite

Note some backends do not support all schemes.

Contributing

There are many ways to contribute to HEIR:

Citations

The HEIR project can be cited in in academic work through following entry:

@misc{ali2025heir,
      title={HEIR: A Universal Compiler for Homomorphic Encryption},
      author={Asra Ali and Jaeho Choi and Bryant Gipson and Shruthi Gorantala
              and Jeremy Kun and Wouter Legiest and Lawrence Lim and Alexander
              Viand and Meron Zerihun Demissie and Hongren Zheng},
      year={2025},
      eprint={2508.11095},
      archivePrefix={arXiv},
      primaryClass={cs.CR},
      url={https://arxiv.org/abs/2508.11095},
}

Support disclaimer

This is not an officially supported Google product.

Project details


Download files

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

Source Distribution

belfort_heir-2026.6.26.dev0.tar.gz (14.3 MB view details)

Uploaded Source

Built Distributions

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

belfort_heir-2026.6.26.dev0-cp310-abi3-manylinux_2_34_x86_64.whl (34.4 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.34+ x86-64

belfort_heir-2026.6.26.dev0-cp310-abi3-manylinux_2_34_aarch64.whl (32.5 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.34+ ARM64

belfort_heir-2026.6.26.dev0-cp310-abi3-macosx_11_0_arm64.whl (35.7 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file belfort_heir-2026.6.26.dev0.tar.gz.

File metadata

  • Download URL: belfort_heir-2026.6.26.dev0.tar.gz
  • Upload date:
  • Size: 14.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for belfort_heir-2026.6.26.dev0.tar.gz
Algorithm Hash digest
SHA256 29eea1c9c0b40f069413bc27ab94d85b6864bfbb92bf45f1a662330d40932fd2
MD5 16de464d3dd820d779cf1c8b31b6a169
BLAKE2b-256 b6245c5f8475138d58977a3c7ea1c172dbd15e2ab8d5a0c3ffbaf17251ff8f83

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_heir-2026.6.26.dev0.tar.gz:

Publisher: release.yml on belfortlabs/heir

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

File details

Details for the file belfort_heir-2026.6.26.dev0-cp310-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for belfort_heir-2026.6.26.dev0-cp310-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 50ebeb410c03fa6527e081b97cf0b5e680b7b215e756c15b3ab2cba7519b7c6c
MD5 17b9b2343dfc26d466245f70a2ebf711
BLAKE2b-256 e16e78c9f5eb40470436a278b03c7836331dc5c21d35ff709e26fecf16ab90d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_heir-2026.6.26.dev0-cp310-abi3-manylinux_2_34_x86_64.whl:

Publisher: release.yml on belfortlabs/heir

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

File details

Details for the file belfort_heir-2026.6.26.dev0-cp310-abi3-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for belfort_heir-2026.6.26.dev0-cp310-abi3-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 da3347401490d4ce81dd5e6ddd1286d48c285a539dbb09e23aed0a3a2a4ed39b
MD5 c576d5a4cc86f86642ed403546daba78
BLAKE2b-256 132b951c5b5fafcabe3185b7bba8896aec395ea7e7820ae9790887ac65a42743

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_heir-2026.6.26.dev0-cp310-abi3-manylinux_2_34_aarch64.whl:

Publisher: release.yml on belfortlabs/heir

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

File details

Details for the file belfort_heir-2026.6.26.dev0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for belfort_heir-2026.6.26.dev0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3ea346f0b2698987b1411c0b3e3ba7b5fcd518f11dac071e0e250d9806d9ef04
MD5 ebe292847404f4e8d5d5b780d10ed05c
BLAKE2b-256 f974fd87772047a95c615546c6d686ef84eab8b15691e57074fe866df29c4541

See more details on using hashes here.

Provenance

The following attestation bundles were made for belfort_heir-2026.6.26.dev0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on belfortlabs/heir

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