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;
    parameters.SetMultiplicativeDepth(multDepth);
    parameters.SetScalingModSize(scalSize);
    parameters.SetFirstModSize(firstModSize);
    parameters.SetRingDim(8192);

    switch (securityLevel) {
        case 128:
            parameters.SetSecurityLevel(HEStd_128_classic);
            break;

        case 256:
            parameters.SetSecurityLevel(HEStd_256_classic);
            break;

        case 192:
            parameters.SetSecurityLevel(HEStd_192_classic);
            break;

        default:
            parameters.SetSecurityLevel(HEStd_NotSet);
    }

    parameters.SetBatchSize(batchSize);

    CryptoContext<DCRTPoly> context = GenCryptoContext(parameters);

    context->Enable(PKE);
    context->Enable(KEYSWITCH);
    context->Enable(LEVELEDSHE);
    context->Enable(ADVANCEDSHE);

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.

Thanks

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 – OpenFHE.org 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!