Parameters Setting in BFV


I’m using BFVRNS, and I set the parameters as following:


And the ciphertext modulus is log2(cryptoContext->GetCryptoParameters()->GetElementParams()->GetModulus().ConvertToDouble()) = 240.
May I know how the q is decided and can openfhe guarantee the security using this set of parameters? I’m also wondering how the security is guaranteed.

As log q = 240 seems to be different from the table on page 26 of

Thanks in advance!

Hi @somnus

You are correct. 8192 should not be allowed for this parameters. If you do not set it manually, OpenFHE will use 16384. It looks like we are hitting an edge case where 8192 works at an earlier iteration but the extra check is not done for the updated log q. I’ve created an issue for this: Fix a bug with setting a lower ring dimension in BFV · Issue #382 · openfheorg/openfhe-development · GitHub This will be fixed in the next bugfix version (v1.0.4).

@ypolyakov I think I have figured out the root cause. Actually, the q is indeed 220-bit. However, if you convert q to double first and then compute the log, the result is incorrect. Converting to double will induce very large errors. I think this line should be modified:

Thank you @somnus No, the operations with doubles are not causing the issue. I looked at the parameters themselves. It is easy to see that q is 240 bits long (a product of small primes, each 60 bits long). We will fix this bug in the next bugfix version.

p = 4293918721
n = 8192
Element Parameters: ILDCRTParams [m=16384* n=8192 q=1766847064777580866691150287171358852739802792534902508212247869330554881 ru=0 bigq=0 bigru=0]
   0:ILParams [m=16384* n=8192 q=1152921504606830593 ru=25959043411404 bigq=0 bigru=0]

   1:ILParams [m=16384* n=8192 q=1152921504606748673 ru=100406242475323 bigq=0 bigru=0]

   2:ILParams [m=16384* n=8192 q=1152921504606683137 ru=45474351589225 bigq=0 bigru=0]

   3:ILParams [m=16384* n=8192 q=1152921504606601217 ru=92707844590835 bigq=0 bigru=0]

OriginalModulus 0

Encoding Parameters: [p=4293918721 rootP =0 bigP =0 rootBigP =0 g=0 L=8192]

log2 q = 240

Oh, indeed it’s true. May I know how you print out this info? I also want to check the limbs in some other settings.

Printing out the crypto parameters is the right way to show it. Here is the line I added to the example to display the moduli.

std::cout << *cryptoContext->GetCryptoParameters()  <<std::endl;

v1.0.4 (with the bugfix) is now released.