InnerProduct question

Hi openfhe team!

I would like to know how to determine whether my inner product operation is correct based on the given parameters, ensuring that the calculation results are accurate. Currently, with the given parameter, the results start to become incorrect at around 200values. How to accurately determine the boundary value that this parameter can support?

 bool innerProductBFV(std::vector<int64_t>& incomingVector) {
     int64_t expectedResult = plainInnerProduct(incomingVector);
     /////////////////////////////////////////////////////////
     // Crypto CryptoParams
     /////////////////////////////////////////////////////////
     CCParams<CryptoContextBFVRNS> parameters;
     parameters.SetPlaintextModulus(65537);
     parameters.SetMultiplicativeDepth(20);
     parameters.SetSecurityLevel(lbcrypto::HEStd_NotSet);
     parameters.SetRingDim(1 << 7);
     uint32_t batchSize = parameters.GetRingDim() / 2;
 
     /////////////////////////////////////////////////////////
     // Set crypto params and create context
     /////////////////////////////////////////////////////////
     lbcrypto::CryptoContext<lbcrypto::DCRTPoly> cc;
     cc = GenCryptoContext(parameters);
 
     // Enable the features that you wish to use.
     cc->Enable(PKE);
     cc->Enable(LEVELEDSHE);
     cc->Enable(ADVANCEDSHE);
 
     KeyPair keys = cc->KeyGen();
     cc->EvalMultKeyGen(keys.secretKey);
     cc->EvalSumKeyGen(keys.secretKey);
 
     Plaintext plaintext1 = cc->MakePackedPlaintext(incomingVector);
     auto ct1             = cc->Encrypt(keys.publicKey, plaintext1);
     auto finalResult     = cc->EvalInnerProduct(ct1, ct1, batchSize);
     lbcrypto::Plaintext res;
     cc->Decrypt(keys.secretKey, finalResult, &res);
     auto final = res->GetPackedValue()[0];
 
     std::cout << "Expected Result: " << expectedResult << " Inner Product Result: " << final << std::endl;
     return expectedResult == final;
 }

Like I set the values = {190}
And the result is Expected Result: 36100 Inner Product Result: -29437
The problem is i dont know it was buggy or just my parameter-setting was wrong

This is linked to the definition of the plaintext space. The values are not in [0, 65536], but in [-32768, 32768]. In your case, 36100 exceeds 32768, so it is represented as 36100 - 65537 = -29437. Therefore, you have the correct result.

1 Like