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’sHEConfig, 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 forlog 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:
Digits. With hybrid key switching
log Pshrinks as the number of digits grows, so whenlog QPlands just above the bound of a ring dimension, one to three more digits bring it under the bound of half that ring.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 tomaxDigits, by default three more than the digit search gave) and, with them, the largest scale down tominScaleBits(the first modulus keeps its distance to the scale); the smallest ring OpenFHE accepts is kept. OpenFHE also needsdepth + 1NTT 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.Packing (
HEConfig.fillSlots). The ring of a standard level usually holds more slots than the model was written for (2^15slots in a2^16ring for a2^14-slot model). WithfillSlotsthe context packs all of them (num_slots = ringDim / 2) and the model scales its packing byslot_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 |
|---|---|---|---|
|
|
|
3/3 correct, ~73 s per image, 3.4 GB |
|
|
|
|
|
|
|
|
|
|
|
four bootstrappings on 4096 slots. A leveled chain needs 57 levels: |
Standard batch programs |
|
|
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.