Security Levels, Ring Dimension and Packing

FHEON is compiled for one security level (cmake -DSECURITY_LEVEL=..., one build folder per level):

  • PERFORMANCE (default): the ring dimension and slot count of each model’s HEConfig, a sparse ternary secret, HEStd_NotSet. Fast, but not a standard security level.

  • 128, 192, 256: HEStd_<n>_classic. OpenFHE takes the smallest ring dimension the HE security standard allows for log QP, the size of the modulus chain the model asks for (log Q) plus the key-switching modulus (log P). Everything is chosen at run time, so the same program adapts to every level.

Choosing the ring

FHEONHEController (fheon_gen_context) builds the context of a standard level in three steps:

  1. Digits. With hybrid key switching log P shrinks as the number of digits grows, so when log QP lands just above the bound of a ring dimension, one to three more digits bring it under the bound of half that ring.

  2. Ring optimization (HEConfig.minScaleBits, HEConfig.maxDigits). log Q = firstMod + depth * scale: a model validated with a smaller scale can fit a smaller ring. Every smaller ring is tried with the fewest digits (up to maxDigits, by default three more than the digit search gave) and, with them, the largest scale down to minScaleBits (the first modulus keeps its distance to the scale); the smallest ring OpenFHE accepts is kept. OpenFHE also needs depth + 1 NTT primes of about the scale’s size, which limits the smallest scale of a long chain in a small ring. minScaleBits = 0 (default) keeps the model’s scale.

  3. Packing (HEConfig.fillSlots). The ring of a standard level usually holds more slots than the model was written for (2^15 slots in a 2^16 ring for a 2^14-slot model). With fillSlots the context packs all of them (num_slots = ringDim / 2) and the model scales its packing by slot_scale(numSlots).

The log prints every decision (Key switching digits raised ..., Ring optimization: ..., Packing: ...) and security.txt in the keys folder records the ring, slots, scale, digits, log Q and log QP.

The chain of a model is the first thing to look at: a model that never bootstraps should use a leveled context (generate_leveled_context) with the depth of its circuit rather than a bootstrapping chain it does not use, and a model whose bootstrapping needs a large scale can be faster leveled with a small scale (LeNet-5 diagonal at the standard levels). Keys of a leveled context load with --load-context like the others (no bootstrapping setup).

Results at 128 bits

Program

Before

Now

Notes

BasicMLP

2^16 (unused bootstrapping chain, log QP ~1100)

2^15: leveled, depth 21, scale 31 bits, 5 digits, log QP 867

3/3 correct, ~73 s per image, 3.4 GB

MLPDiagonal

2^15 (leveled, 2 digits, log QP 849)

2^15

2^14 would need a scale near 20 bits; 1.9 s per image, 1.6 GB

LeNet5Diagonal, LeNet5KeyOptimizedDiagonal

2^16: one bootstrapping, scale 46 bits, log QP 1515; ~33 s per image (13 s of circuit), 11.2 GB

2^15: leveled chain of 28 levels, scale 26 bits, first modulus 32 bits, 8 digits, log QP 879, all 2^14 slots (16 parallel conv2 groups)

LeNet5KeyOptimizedDiagonal: 10/10 correct, ~18 s per image (9.1 s of circuit), 9.0 GB. The bootstrapping needs its 46-bit scale (30, 32 and 40-bit scales make the bootstrapped result undecryptable); without it the chain is precise down to 22 bits, and 26 bits is the smallest scale with enough NTT primes in a 2^15 ring

LeNet5

2^16

2^16 (unchanged)

four bootstrappings on 4096 slots. A leveled chain needs 57 levels: 2^16 at ~26 bits with twice the towers (29.6 s against 14.1 s per image with the performance parameters), so the bootstrapped chain stays

Standard batch programs

2^16, half the slots used

2^16, all the slots: twice the images per ciphertext (Batch Input Examples)

5 digits

At 192 and 256 bits the same steps run; most of these chains need 2^16 (MLPs) or 2^17 (bootstrapped models).

In the Studio

The Workbench shows every program as it is at the chosen security level: the ring dimension, slots, scale and digits (estimated with the same rules, then read from security.txt once the program has generated its keys), the batch a batch program takes there, and its title with that batch. A program that only repeats another one at that level is not listed: at 128 bits BResNet20N16 takes 32 images, like BResNet20N32, so only ResNet-20, batch of 32 (BResNet20N32) is shown, and a selected BResNet20N16 switches to it.