← Back to FHE Intro

The CKKS Scheme

An overview of the scheme (Cheon-Kim-Kim-Song) that enables approximate arithmetic on encrypted real numbers.

Contents

  1. What is CKKS? (And Why We Need It)
  2. Toy LWE Intuition
  3. Encoding Real Numbers
  4. Rescaling & Noise Management
  5. Batching (SIMD)
  6. Concrete Example
  7. Interactive Playground
  8. When to Use CKKS
  9. Further Reading

1. What is CKKS? (And Why We Need It)

BFV and BGV schemes work perfectly with integers, giving exact results. But most machine learning and data analysis operate on real numbers. CKKS, introduced by Cheon, Kim, Kim, and Song (2016), is designed for approximate arithmetic on encrypted real and complex numbers.

2. Toy LWE Intuition

Before CKKS, consider a simple LWE-style encryption (integers with noise) to build intuition:

\[ q = 97, \quad s = 17, \quad e = \text{small noise term (e.g., ±1)} \]

Encryption: \[ Enc(m) = (a, b = (a \cdot s + m + e) \bmod q) \]

Decryption: \[ Dec(a,b) = (b - a\cdot s) \bmod q \approx m \]

Noise grows with operations; CKKS handles this carefully for real numbers.

3. Encoding Real Numbers

CKKS encodes real numbers as scaled integers using a scale factor \(\Delta\):

\[ \text{Encode}(x) = \lfloor x \cdot \Delta \rceil \]

This integer is then encrypted; the “noise” becomes part of the approximation.

4. Rescaling & Noise Management

Multiplication grows both the scale and the noise. CKKS uses rescaling to divide the ciphertext by \(\Delta\) and keep results in a manageable range:

\[ c' \xrightarrow{\text{rescale}} c'' \approx \frac{c'}{\Delta} \]

To understand why this is necessary, it's crucial to look at the two distinct types of noise in CKKS.

4b. The Two Types of Noise in CKKS

In CKKS, "noise" comes from two sources, unlike base LWE/RLWE schemes [2]:

1. Base Encryption Noise (\(e_1\))

Like standard LWE/RLWE encryption, CKKS ciphertexts include a small random noise \(e_1\) to ensure semantic security [2]:

\[\text{Enc}(\tilde{x}) = \big(a, \; b = (a \cdot s + \tilde{x} + e_1) \bmod q\big)\]

This noise grows as you perform additions and multiplications.

2. Encoding / Rounding Error (\(e_2\))

CKKS encodes real numbers as integers using a scale factor \(\Delta\) [4]:

\[ \tilde{x} = \text{Round}(x \cdot \Delta) \]

This means the encoded value can be seen as the "true" scaled value plus a small rounding error, \(e_2\):

\[ \tilde{x} = (x \cdot \Delta) + e_2 \]

Here, \(e_2\) is the rounding error. Unlike \(e_1\), it is not cryptographic; it represents the inherent approximation from scaling real numbers.

3. How Noise Propagates

  • Addition: Noise adds linearly:
    \(c_1 + c_2 \implies e_\text{total} = e_1^{(1)} + e_1^{(2)} + e_2^{(1)} + e_2^{(2)}\)
  • Multiplication: Noise grows roughly multiplicatively with the scale:
    Compact form:
    \(c_1 * c_2 \implies e_\text{total} \approx (\tilde{x} + e_1^{(1)} + e_2^{(1)}) (\tilde{y} + e_1^{(2)} + e_2^{(2)}) - \tilde{x}\tilde{y}\)
    Expanded form (main contributions):
    \(e_\text{total} \approx \tilde{x} e_1^{(2)} + \tilde{y} e_1^{(1)} + \tilde{x} e_2^{(2)} + \tilde{y} e_2^{(1)} + e_1^{(1)} e_1^{(2)} + \text{smaller cross-terms}\)
    Here, the terms involving \(\tilde{x}\) and \(\tilde{y}\) dominate the growth; the higher-order error products are typically much smaller.
  • Rescaling: Divides both value and noise by Δ, keeping errors manageable for decoding.

4. Visualizing Noise

Think of CKKS ciphertexts as "fuzzy" numbers [4]:

Plaintext \(x = 1.5\)
Encode & scale: \(\tilde{x} = 1500 + e_2\)
Encrypt: \(c = \text{Enc}(\tilde{x})\) (includes \(e_1\))
Homomorphic addition/multiplication → Noise grows
\(e_\text{total} = e_1 + e_2\) (+ more from operations)
Rescale → Keep noise / scale manageable
Decrypt & decode → \(x \pm\) small approximation error

✅ CKKS embraces the noise: the cryptographic noise e1 ensures security, while the encoding error e2 defines the unavoidable approximation. Controlled rescaling and scale management allow arithmetic on real numbers with predictable approximation.

5. Bounding Noise (The Noise Model)

CKKS papers and libraries don't use a single formula, but a noise model to track growth [4]. The primary goal is to ensure the final noise is smaller than the desired precision after decoding.

  • Key Insight: Unlike other schemes where noise grows exponentially, CKKS's rescaling step makes the noise grow (at worst) linearly with the multiplicative depth.
  • Parameter Selection: In practice, you tell the library your desired precision (e.g., 40 bits) and multiplicative depth (e.g., 7 levels). The library uses this noise model to automatically select parameters (like the polynomial degree \(N\) and the modulus chain \(q_L, ..., q_0\)) that guarantee the final error is acceptably small.
  • Security: This bound is also crucial for security. To prevent "decryption attacks" (IND-CPA-D) where an attacker analyzes noise statistics, libraries add *new* random noise (called "noise flooding") after decryption to mask the original computation's noise.

5. Batching (SIMD)

CKKS allows packing thousands of numbers into one ciphertext. Operations on ciphertexts apply to all packed numbers simultaneously:

\[ C_{vec} = \text{Encrypt}([x_1, x_2, \dots, x_N]) \]

7. Concrete Example

Encoding \(x=1.5\), \(y=2.25\) with scale \(\Delta=1000\):

CKKS Data Flow

This diagram shows the full lifecycle of data using the values from above.

1. Plaintext
Real number x = 1.5
2. Encode & Scale
\(\tilde{x} = \text{Round}(1.5 \cdot \Delta) = \mathbf{1500}\)
3. Encrypt
LWE-style: (a, b = a·s + 1500 + e mod q)
4. Homomorphic Operations
Operate on ciphertexts
\( \text{(with } y = 2.25 \rightarrow \tilde{y} = \mathbf{2250}\text{)} \)
Addition Path
C_add = Enc(1500) + Enc(2250)
Decrypt & Decode ≈ 3.75
Multiplication Path
5. Multiply
C_mult = Enc(1500) · Enc(2250)
6. Rescale
C_mult / Δ ≈ 3375
7. Decrypt & Decode
3375 / Δ ≈ 3.375

7. Interactive Playground

Try encrypting real numbers using CKKS-like approximate arithmetic:

Cipher A: —
Cipher B: —
Result: —
Notes about this toy demo
  • Real numbers are scaled and rounded; the result is approximate.
  • Repeated operations increase approximation error.

8. When to Use CKKS

9. Further Reading