SEAL icon indicating copy to clipboard operation
SEAL copied to clipboard

Can you give me a detailed example to use poly_modulus_degree=65536?

Open DGQAQ opened this issue 2 years ago • 6 comments

I am a novice learning seal. I read related questions and learned that I can use SEALContext context(parms, true, sec_level_type::none); to skip the security check, but I got an error when I used it myself,I am using seal3.4.0, does this version not support larger parameters? My code is as follows ` EncryptionParameters parms(scheme_type::CKKS);

parms.set_poly_modulus_degree(65536);
parms.set_coeff_modulus({ 60,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,60 });

auto context = SEALContext::Create(parms, true, sec_level_type::none);`

get error invalid_argument("encryption parameters are not set correctly");

When the code is changed to the following

` EncryptionParameters parms(scheme_type::CKKS);

parms.set_poly_modulus_degree(65536);
parms.set_coeff_modulus({ 60,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,60 });

SEALContext context(parms, true, sec_level_type::none);`

get error C++ There is no constructor for a seal::SEALContext::SEALContext instance that matches the parameter list with parameters of type: (seal::EncryptionParameters, bool, seal::sec_level_type)

As a beginner in C++ and seal, this is causing me a lot of headaches, I hope you can point out my mistakes and give me the correct code

DGQAQ avatar Feb 20 '23 04:02 DGQAQ

  • set_coeff_modulus takes as input std::vector<Modulus>, but not a vector of int like 60, 40
  • I suppose you want 60 bits of modulus. Then you first use CoeffModulus::Create(poly_modulus_degree, { 60, 40, 40, 60 }) to find the proper primes.
  • Strongly recommend to look though the examples

fionser avatar Mar 02 '23 02:03 fionser

Also update the SEAL version, for 3.4, the maximum degree is 32768

fionser avatar Mar 02 '23 02:03 fionser

I'm struggling with the same issue, but I'm using the latest version - 4.1.1. I'm trying to create context with poly modulus degree 65536 and primes that can definitely fit in: { 60, 56, 56, 60 } - the sum is 232 and largest allowed bit counts is at least 881, as stated at homomorphicencryption.org.

The context is created, but I can't generate keys - KeyGenerator constructor fails to verify context's parameters and stops at context_.parameters_set()

EncryptionParameters parms(scheme_type::ckks);
size_t poly_modulus_degree = 65536;
parms.set_poly_modulus_degree(poly_modulus_degree);
parms.set_coeff_modulus(CoeffModulus::Create(poly_modulus_degree, { 60, 56, 56, 60 }));
double scale = pow(2.0, 56);

SEALContext context(parms);
print_parameters(context);
cout << endl;

KeyGenerator keygen(context);

I ran example_ckks_basics, the only thing i've changed is poly_modulus_degree. Feels like 4.1.1 also doesn't support modulus degree greater than 32768

PIDAMI avatar Mar 03 '23 00:03 PIDAMI

  • That is because the current HE.org only give security level until degree=32768.
  • To use degree>32768, we need to make sure that the modulus size is not too large.

@PIDAMI For your case, it is safely to use sec_level::none to skip the security level check since Q is less than 881-bit.

May be @kimlaine can change the logic in hestdparms.h or just pop out a message.

fionser avatar Mar 03 '23 02:03 fionser

@fionser thank you, that indeed solved the problem. And what about the case where Q might be more than 881 bit? Do you need to manually check if your poly modulues degree is large enough and gives desired security level via other tools like https://github.com/malb/lattice-estimator/ ? Or is there a way to do so in SEAL?(haven't found one yet but maybe i've missed it just like the sec_level option)

PIDAMI avatar Mar 09 '23 04:03 PIDAMI

@PIDAMI For me, I have to check the latest lwe-estimator script if I really care the security level. For example to use a smaller security level (eg., 80 ~ 100) which is also not inside the SEAL implementation.

Also most of my application do not need a such large polynomial degree.

fionser avatar Mar 09 '23 08:03 fionser