---
title: "When does CKKS change a prediction?"
date: "2026-11-25"
author: "Sri Vedantam"
description: "A two-input yes-or-no classifier lets us measure when CKKS changes a prediction and what an extra encrypted multiplication costs."
tags: [CKKS, encrypted inference, benchmarking]
---

## Forenote

> This entire article is just a reality check being able to implement CKKS scheme for Encrypted Inferences. There are no new results, other than the sake of confirming what we already know through our experiment and scenario. Thank you for understanding. - Sri Vedantam


## How CKKS computes on encrypted numbers

The work that this laboratory will work on is summed up with Fully Homomorphic Encryption (FHE). Of such, we have a scheme called CKKS, a homomorphic encryption scheme for approximate arithmetic. Previous HE schemes (categorized: Partial HE, Somewhat HE, Leveled HE, and Fully HE). Homomorphic encryption allows computations on encrypted inputs. Different schemes support different operations and computation depths. This experiment uses CKKS, named after Cheon, Kim, Kim, and Song, because it supports approximate arithmetic on encrypted numbers.

A client encodes numbers, encrypts them, and sends the ciphertexts to an evaluator. Using the appropriate evaluation keys, the evaluator can add and multiply those ciphertexts without receiving the client's secret decryption key. The client decrypts and decodes the resulting ciphertext to recover a numerical answer. For example, the evaluator can add encryptions of $0.2$ and $0.4$ and return an encryption of their sum. The ideal answer is $0.6$. [Cheon, Kim, Kim and Song, *Homomorphic Encryption for Arithmetic of Approximate Numbers*](https://eprint.iacr.org/2016/421)

CKKS first represents real numbers at a finite scale and rounds during encoding. Encryption introduces a small noise term. After the ciphertexts are added, the client uses its secret key to decrypt and then decodes the result. The recovered value can take the form $\hat z=0.6+\varepsilon$. Here $\varepsilon$ names the numerical difference from the ideal sum. We have not measured $\varepsilon$ for this illustrative pair. [Cheon, Kim, Kim and Song, *Homomorphic Encryption for Arithmetic of Approximate Numbers*](https://eprint.iacr.org/2016/421)

Our classifier also multiplies ciphertexts. After a multiplication, OpenFHE automatically rescales the ciphertext in the configuration used here. That step reduces its modulus and rounds its coefficients, keeping the representation manageable as the evaluator continues. These operations contribute to the difference between the decrypted score and the same calculation on the original inputs. [OpenFHE CKKS tutorial](https://openfheorg.github.io/aaai-2024-lab-materials/AAAI_Tutorial.pdf)

For a classifier, a small change in its numerical score matters when the score sits close to the cutoff between two labels. In our experiment the evaluator computes only the encrypted score. The client decrypts it and decides whether the answer is yes or no. This lets us compare the plaintext and decrypted decisions for the same input.

## Our two-number classification task

We built a task with two private numbers, $x$ and $y$. Its rule assigns the label **yes** when $|x+y|$ is at least $0.5$ and **no** otherwise. For example, $(0.2,0.4)$ is a yes because the sum has magnitude $0.6$. The pair $(0.2,-0.4)$ is a no because its sum has magnitude $0.2$. These labels give us a known answer for every input pair.

We fit a polynomial classifier to examples labeled by that rule. It returns a score whose sign gives its predicted yes or no label. The client encrypts $x$ and $y$ using CKKS, the evaluator calculates the score on ciphertexts, and the client decrypts and labels the result. We compare that label with the classifier's plaintext prediction to see when approximate arithmetic changes the answer.

Let $z=x+y$. Because $z^4$ is the same for $z$ and $-z$, it respects a rule based on $|z|$. In exact arithmetic, $|z|\geq 0.5$ is equivalent to $z^4\geq 0.5^4=0.0625$. Squaring $z$ would also express this rule. We chose the fourth power because it can be computed as $(z^2)^2$ or as $((z^2)z)z$: the two circuits calculate the same score but have different multiplication depths. That gives us a way to compare their running time and numerical error without changing the prediction rule.

## Fitting the classifier and evaluating its score

We generated 1,024 training pairs uniformly on $[-1,1]^2$ and labeled them using the yes or no rule above. Among the negative examples, we took the largest $z^4$. Among the positive examples, we took the smallest $z^4$. The midpoint gave us a fitted threshold $t=0.06241039574305908$. It differs slightly from the exact cutoff, $0.0625$, because we chose it from the sampled training pairs. Once fitted, this number stayed fixed for every evaluation.

$$
s(x,y)=(x+y)^4-t,\qquad \text{predict positive if }s(x,y)\geq 0.
$$

For $x=0.2$ and $y=0.3$, the fourth power is $0.0625$. Subtracting the fitted threshold leaves a small positive score, about $0.0000896$. At $x=y=0$, the score is $-t$. Both inputs yield a definite label, but the first is much closer to changing its label.

The client packs 256 values of $x$ into one ciphertext and the corresponding values of $y$ into a second. Arithmetic acts on corresponding slots. The evaluator receives the public threshold and the evaluation material for multiplication, and returns one ciphertext containing 256 scores. The client decrypts it and compares each score with zero. We ran both roles in one process to measure the arithmetic locally.

## How much error changes a decision?

:::definition Score margin
For this classifier the **margin** of a sample is $|s|$, the distance from its plaintext score to the cutoff at zero. Write $\hat{s}$ for the decrypted score and $e=\hat{s}-s$ for the signed numerical error.
:::

If $|e|<|s|$, the score keeps its sign. For a negative score to become positive under our labeling rule, the error must satisfy $e\geq -s$. For a positive score to become negative, it must satisfy $e<-s$. I want to pay particular attention to the direction because it does matter. Adding a positive error to a positive score can make the numerical result worse while preserving the label.

Consider sample 192 from repetition 0 of the balanced circuit at 40 scale bits and depth budget 3. Its plaintext score was about $-7.44\times 10^{-9}$. Its decrypted score was $+7.25\times 10^{-9}$. The error, about $+1.47\times 10^{-8}$, crossed the entire margin. The same error added to the worked example above would have left its label unchanged.

## Sampling both sides of the boundary

We kept 128 pairs drawn from the training distribution for the ordinary test. We also constructed 32 pairs at each of four offsets from the fitted boundary in the **input** coordinate $|x+y|$. If $b=t^{1/4}$, these pairs satisfy $|x+y|=b\pm 2^{-k}$. We sampled both sides, with both signs of $x+y$. Moving the input by $2^{-k}$ changes the score by $(b\pm 2^{-k})^4-b^4$. That distinction matters when comparing an offset with a decryption error.

Each packed batch held all 128 ordinary and all 128 boundary inputs. We used five fresh key pairs and encryptions for each parameter setting, keeping the samples fixed. Each boundary cell below therefore counts 32 inputs measured five times. A flip means the plaintext and encrypted evaluations gave different labels for that same input. Accuracy against our training rule answers a separate question.

| Scale modulus (bits) | Flips at $2^{-10}$ | At $2^{-18}$ | At $2^{-26}$ | At $2^{-34}$ | Mean absolute score error on ordinary inputs |
| --- | --- | --- | --- | --- | --- |
| 30 | 0 | 86 | 79 | 87 | $3.27\times 10^{-4}$ |
| 40 | 0 | 0 | 74 | 82 | $6.71\times 10^{-7}$ |
| 50 | 0 | 0 | 0 | 38 | $2.64\times 10^{-9}$ |

All three rows use the balanced circuit with a depth budget of 3. At $2^{-26}$, increasing the scale modulus from 40 to 50 bits brought observed flips from 74 to zero. At $2^{-34}$ even the 50-bit setting sometimes crossed zero. Therefore, we can infer that a disagreement rate would also depend on how often real inputs fall this close to its model’s boundary. This is relatively obvious, but it is nice seeing the transforms play out in reality.

![Percentage of labels that changed at four decreasing distances from the boundary, with separate panels for the balanced and serial circuits.](./boundary-flips.png)

## Computing the same fourth power twice

The balanced circuit computes $z^2$ and squares that result. The serial circuit computes $z^2$, multiplies by $z$ to get $z^3$, then multiplies by $z$ again. The longest chain of dependent ciphertext multiplications has length 2 in the first case and 3 in the second. This length is called the **multiplicative depth**. The **depth budget** is the capacity we request from OpenFHE when choosing parameters, before running either circuit. Some scientists may feel some affinity with this problem becoming an issue when we are dealing with large matrices in either theoretical computer science or AI applications.

For each comparison we used the same two input ciphertexts and randomized the order of the circuits. At 40 scale bits, the median evaluation times over five repetitions were as follows.

| Circuit | Actual depth | Configured budget | Time per 256 scores | Bytes for both serialized input ciphertexts |
| --- | --- | --- | --- | --- |
| Balanced | 2 | 3 | 16.32 ms | 2,099,362 |
| Serial | 3 | 3 | 24.53 ms | 2,099,362 |
| Balanced | 2 | 4 | 22.55 ms | 2,623,894 |

Reading down the first two rows holds the encryption parameters fixed. Computing the fourth power through $z^3$ cost an additional 8.21 ms per packed batch on my machine. Comparing the first and third rows holds the operations fixed. The larger budget gave OpenFHE a longer modulus chain, larger input ciphertexts and a higher median evaluation time. Thus, we conclude that a circuit can incur a cost for the depth it reserves even when it performs exactly the same two squarings. This also follows from pre-existing knowledge.

At the $2^{-26}$ input offset, each circuit evaluated the same 32 input pairs under five fresh encryptions: 160 comparisons between a plaintext label and its CKKS label. With 40 scale bits and a depth budget of 3, the faster balanced circuit disagreed with plaintext 74 times; the serial circuit disagreed 68 times. Neither disagreed on the ordinary inputs. The six-flip difference does not establish that the serial circuit is more reliable. These 160 comparisons reuse only 32 input pairs, so we would need more inputs and fresh encryptions to compare their flip rates with confidence.
