0Pricing
Cryptology Academy · Lesson

CKKS for Approximate Arithmetic & ML

Apply CKKS to privacy-preserving machine learning inference.

CKKS for Approximate Arithmetic & ML is a free Cryptology Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cryptology Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why CKKS?

BGV/BFV work over integers (exact arithmetic). Machine learning uses floating-point numbers (approximate arithmetic). CKKS (Cheon-Kim-Kim-Song, 2017) encodes real/complex numbers and allows controlled precision loss — ideal for ML inference and data analytics.

Approximate Arithmetic

CKKS treats the noise as part of the encoding precision. Instead of eliminating noise (error correcting), CKKS views the result as an approximation with guaranteed precision bounds. This trade-off enables much more efficient HE for continuous-valued computations.

Encoding Real Numbers

CKKS encodes a vector of complex numbers as a polynomial: a vector (z_0, ..., z_{n/2-1}) is mapped via inverse FFT to a polynomial in R. Scaling factor Δ (e.g., 2^40) maps floating-point to integers. n/2 real slots per ciphertext.

Rescaling

After multiplication, the scaling factor doubles: Δ^2. CKKS introduces a rescaling operation: divide by Δ to restore single scaling. This also reduces the ciphertext modulus level (like BGV modulus switching), keeping the ciphertext manageable.

Precision Analysis

Each multiplication consumes one modulus level and reduces precision by ~log2(Δ) bits. For a circuit of depth L with scaling factor Δ = 2^40, total precision loss ≈ L*40 bits. Choose initial modulus Q large enough to accommodate this precision budget.

ML Inference on CKKS

Linear layers (matrix-vector multiply): efficient — rotation and accumulation. Activation functions (ReLU, sigmoid): polynomial approximation required. ReLU: approximate with degree-7 Chebyshev polynomial. Accuracy loss: ~0.1-1% vs plaintext inference.

Private Inference Example

Hospital encrypts patient data with their CKKS public key. Cloud runs a diagnostic neural network on the encrypted data using CKKS operations. Returns encrypted prediction. Hospital decrypts with private key. Cloud never sees patient data or plaintext diagnosis.

CKKS Parameters

HEAAN/OpenFHE recommendation: n=2^15 (32768) for deep ML circuits. Modulus chain: initial Q ≈ 2^1500 for 30 multiplication levels at Δ=2^50. Security: 128-bit assuming CKKS with these parameters is as hard as RLWE. Memory: ciphertext ~1 MB.

Bootstrapping in CKKS

CKKS bootstrapping (Cheon et al., 2018) homomorphically evaluates the modular reduction to refresh the ciphertext. Complexity: evaluating the sine function (via polynomial approximation) over complex numbers. Enables unlimited circuit depth at ~30 seconds per bootstrap.

Comparison: CKKS vs BFV

BFV: exact integers, integer plaintexts, no precision loss. CKKS: approximate reals/complex, floating-point plaintexts, precision decreases with depth. Use BFV for: databases, queries, exact computation. Use CKKS for: ML, statistics, scientific computing.

Libraries

HEAAN (original CKKS, Seoul National University). Microsoft SEAL (CKKS + BFV). OpenFHE (CKKS + BGV + BFV). Concrete-ML (Zama.ai, wraps OpenFHE for scikit-learn and PyTorch models). TF-HE (TensorFlow + HE integration experiments).

Quick Check

Why is CKKS preferred over BFV for machine learning inference?

Recap

CKKS supports approximate real-number arithmetic, ideal for ML inference and statistics on encrypted data. Rescaling manages the scaling factor; polynomial approximations replace activation functions. Next: post-quantum cryptography — Shor's and Grover's algorithms.

Frequently asked questions

Is the “CKKS for Approximate Arithmetic & ML” lesson free?

Yes — the full text of “CKKS for Approximate Arithmetic & ML” is free to read here on the web, and the Cryptology Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cryptology Academy course, upgrade to CoddyKit PRO.

What will I learn in “CKKS for Approximate Arithmetic & ML”?

Apply CKKS to privacy-preserving machine learning inference. You practise Cryptology Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Cryptology Academy?

No prior experience is required. Cryptology Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “CKKS for Approximate Arithmetic & ML” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Cryptology Academy lesson?

Yes. Every Cryptology Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. What Is Homomorphic Encryption?
  2. Learning With Errors (LWE) Foundation
  3. BGV & BFV Schemes for Integer Operations
  4. CKKS for Approximate Arithmetic & ML
← Back to Cryptology Academy