Skip to main content

Lattica FHE Core Python Bindings

Project description

Lattica FHE Core

This repository contains the source code for the Lattica Client FHE SDK, which powers encrypted inference for AI workloads using Fully Homomorphic Encryption (FHE). The SDK provides a portable FHE implementation that compiles into a shared library used both by the Lattica Python and JS clients.


🛠️ Build Instructions

Requirements

Linux x86_64 or macOS ARM-64

  • C++17-compatible compiler (e.g. g++ ≥ 9)
  • CMake ≥ 3.14
  • Python ≥ 3.8
  • pybind11
  • torch == 2.5.1
  • setuptools, wheel (for Python packaging)
macOS only:
  • autoconf, automake

Build Steps

git clone https://github.com/Lattica-ai/lattica_fhe_core.git
cd lattica_fhe_core

# Create and activate a virtual environment (recommended)
python -m venv .venv
source .venv/bin/activate

# Install required Python packages
pip install pybind11 torch==2.5.1 setuptools wheel

# Build the project
cmake . -B build -DPYTHON_ENABLED=ON
cmake --build build --parallel 32

This will generate a Python extension shared library named like:

# On Linux:
cpp_sdk.cpython-312-x86_64-linux-gnu.so

# On macOS:
cpp_sdk.cpython-312-darwin.so

▶️ Using This Build in the Lattica Client

To replace the binary distributed by lattica-query:

  1. Install the query client as described here:
    👉 https://platformdocs.lattica.ai/how-to-guides/client-installation/how-to-install-query-client

  2. Locate the installed .so file by running:

pip show -f lattica-fhe-core
  1. Replace the installed cpp_sdk.*.so file with the one you built.

📁 Project Structure

A detailed breakdown of the major components in this repository:


src/encryption_schemes/

Implements the supported encryption schemes used by the Lattica client.

  • Includes ckks, rbgv, and two GSW-like variants (*_g, *_g_crt) based on gadget matrix decompositions.
  • Each scheme provides:
    • Encoding and decoding of plaintext data
    • Encryption and decryption procedures
    • Key generation, including auxiliary key-switching keys
  • All cryptographic randomness is generated via Libsodium

src/context_utils/

Provides utilities for interpreting and validating encryption context parameters.

  • Parameters are received from the backend per model — they are not generated locally.
  • Includes logic for:
    • Representing data in double-CRT form
    • Managing modulus chains and per-prime decompositions
    • Ensuring structural compatibility of runtime contexts

src/homomorphic_operations/

Implements apply-clear versions of homomorphic operations.

  • These simulate encrypted computation by applying the logic directly to plaintext inputs.
  • Used only for client-side validation and debugging — no encrypted computation is performed here.
  • Actual homomorphic execution is handled remotely by the Lattica backend.

src/binding/python/

Defines the Python interface via pybind11.

  • These four functions are exposed:
    1. py_generate_key(...)
    2. py_enc(...)
    3. py_dec(...)
    4. py_apply_client_block(...)

src/encryption_scheme_utils/

Implements abstractions for representing and manipulating the structure of plaintext data.

  • Defines the pt_shape object, which describes logical dimensions, padding, and layout

src/tensor_engine/

Implements the core arithmetic and layout handling logic for encrypted and plaintext data.

  • All data — including ciphertexts, plaintexts, and context elements — is represented as tensors
  • Built on PyTorch tensor operations, with select extensions for FHE-specific requirements
  • Includes custom kernels for modular arithmetic routines: addition, multiplication, NTT, inverse NTT

src/serialization/

Handles serialization and deserialization of all major objects.

  • Implemented using Protocol Buffers (protobuf)
  • Supports efficient encoding of ciphertexts, plaintexts, keys, and context objects

src/slot_permutation/

Implements coefficient permutations, supports both:

  • Permutations in the coefficient basis
  • Permutations in the CRT basis

src/ (top-level)

  • num.cpp: Implements multi-precision integer arithmetic
  • toolkit_python.cpp: Entry point for the Python integration layer

🔐 License

See LICENSE.txt for license details.

For support, please contact the Lattica team or consult internal documentation.

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

lattica_fhe_core-0.1.6.tar.gz (5.8 kB view details)

Uploaded Source

Built Distributions

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

lattica_fhe_core-0.1.6-cp312-cp312-manylinux_2_39_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

lattica_fhe_core-0.1.6-cp312-cp312-macosx_13_0_arm64.whl (1.5 MB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64

File details

Details for the file lattica_fhe_core-0.1.6.tar.gz.

File metadata

  • Download URL: lattica_fhe_core-0.1.6.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/5.15.167.4-microsoft-standard-WSL2

File hashes

Hashes for lattica_fhe_core-0.1.6.tar.gz
Algorithm Hash digest
SHA256 5a75c55ebc35f6e5463270d3201fb16cda03ec0ef758700648d34e0b95b13d26
MD5 9de26556338d9b20e8683c0f48346c13
BLAKE2b-256 b012eefa7469ca6d64be11cad5bc7ab0f1c28953f430224980e14806a2ab80d6

See more details on using hashes here.

File details

Details for the file lattica_fhe_core-0.1.6-cp312-cp312-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for lattica_fhe_core-0.1.6-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 dc9f85dbce625e60e28b8ccb41d02fb07c9e453475a65f6cb1447cc9c0cd2596
MD5 f301ee7a6dcd60d1e47ad9ead914946e
BLAKE2b-256 6b02bf3768e1d9b1dc03bad35d59c72649565e5f6a758e3a605a494d60ffaadd

See more details on using hashes here.

File details

Details for the file lattica_fhe_core-0.1.6-cp312-cp312-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for lattica_fhe_core-0.1.6-cp312-cp312-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 552a4f25202a67a0161b82c9fc2e316034b2278ce590cfec8942ce2f042f50b1
MD5 55b53ebda841edaf157693ee7f7a0b9b
BLAKE2b-256 bf11d25c14a5ccdb676bc1fcc950a9caa9409532389aa51bdf94486a2fbb54a9

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