Setting security parameters according to 128 bit security (very small CKKS scaling factor)

Hello everyone,

I am trying to implement a neural net, which determines handwritten integers. It requires a multiplicative depth of nine, due to two activation functions, which are approximated with third degree Chebychev approximations. It does work, but it runs slowly. Therefore I was trying to get the ring dimension down to 8192. This works, but only if I do not set the security level. I do however need a security level of 128 bits. When I try to set FirstModSize and ScalingModSize to lower values in order to get \log(q) below 220, i get the error message

Modulus size 64 is too large. NativeVectorT supports only modulus size <= 60 bits

which I do not get, since I did set a modulus size below 64. Can somebody help me?

(edit) I am using CKKS

Thanks in advance and cheers

Can you share the portion of your code used to initialize the crypto context including CCParams<CryptoContextCKKSRNS> parameters?
Also, did you specify the NATIVE_SIZE when you built OpenFHE?

Hello Ceasar,

thanks for the quick reply. Here is the context initialization I use:

    uint32_t multDepth = std::stoi(argv[1]);
    uint32_t scalSize = std::stoi(argv[2]);
    uint32_t firstModSize = std::stoi(argv[3]);
    uint32_t securityLevel = std::stoi(argv[4]);
    uint32_t batchSize = 1024;

    CCParams<CryptoContextCKKSRNS> parameters;

    switch (securityLevel) {
        case 128:

        case 256:

        case 192:



    CryptoContext<DCRTPoly> context = GenCryptoContext(parameters);


I did it this way so that I did not have to recompile every time I wanted to test new parameters. I don’t think I set NATIVE_SIZE when building.


Can you provide the specific values below?

    uint32_t multDepth = std::stoi(argv[1]);
    uint32_t scalSize = std::stoi(argv[2]);
    uint32_t firstModSize = std::stoi(argv[3]);
    uint32_t securityLevel 

Adding to what @Caesar wrote. The main parameters are FirstModSize and ScalingModSize. FirstModSize should typically be larger than ScalModSize (to support messages larger in norm than unity). For NATIVE_SIZE=64 (default), FirstModSize cannot be larger than 60. ScaleModSize cannot be larger than 59 (because of the alternating logic of choosing the moduli above and below 2^{ScaleModSize}).

1 Like

Hi all,

I get this error if for example scalSize = 10 and firstModSize = 20.

Thanks in advance!

I would not recommend such low values as the approximation error in CKKS is more than 10 bits. So you cannot achieve even 1 bit of precision. Try something like 40 and 50 instead of 10 and 20, respectively. I also suggest watching Homomorphic Encryption for OpenFHE Users – to get more familiar with CKKS and its configuration parameters.

1 Like

Thanks a lot. I realize these are unrealistic parameters, but I do not understand why the error message states that My modulus size is 64 and too large for smaller parameters.

Cheers and thanks in advance

I agree that the message generated by the exception should be changed. I will create an issue for this in github.

Created an issue for this: Correct the exception message for small CKKS scaling factor · Issue #339 · openfheorg/openfhe-development · GitHub

Thanks a lot! The video is also really helpful, thanks!