BFV Ciphertext multiplication with default parameter setting

Hi everyone,

I am using the default parameter setting for multiplying BFV ciphertexts.
I am implementing the same code at openfhe-development/src/pke/examples/simple-integers.cpp at main · openfheorg/openfhe-development · GitHub
I changed the multiplicative depth from 2 to 3 and by binary tree multiplication it should multiply 8 ciphertext-ciphertext multiplication but i can only multiply 4 ciphertext-ciphertext multiplication.
What is the default ciphertext-ciphertext multiplication in BFV encryption mechanism.

Thanks in advance!.

How are you performing the multiplication? Is it like this

    auto ciphertextMul12 = cryptoContext->EvalMult(ciphertext1, ciphertext2);
    auto ciphertextMul34 = cryptoContext->EvalMult(ciphertext3, ciphertext4);
    auto ciphertextMul56 = cryptoContext->EvalMult(ciphertext5, ciphertext6);
    auto ciphertextMul78 = cryptoContext->EvalMult(ciphertext7, ciphertext8);
    auto ciphertextMul1234 = cryptoContext->EvalMult(ciphertextMul12, ciphertextMul34);
    auto ciphertextMul5678 = cryptoContext->EvalMult(ciphertextMul56, ciphertextMul78);
    auto ciphertextMultResult = cryptoContext->EvalMult(ciphertextMul1234, ciphertextMul5678);```

Please post a minimum working example such that we identify the issue.

Thanks for your response .
Below is the snippet of my code. when i giving total plaintext as 4 then it works correctly but on giving higher vaule it gives incorrect result.

std::vector plaintexts(numPlaintexts);
std::vector<Ciphertext> ciphertexts(numPlaintexts);

    for (int i = 0; i < numPlaintexts; ++i) {
        plaintexts[i] = cryptoContext->MakePackedPlaintext(vectors[i]);
        ciphertexts[i] = cryptoContext->Encrypt(keyPair.publicKey, plaintexts[i]);
    }

    // Sample Program: Step 4: Evaluation

    // Homomorphic multiplications
    auto ciphertextMul = ciphertexts[0];
    for (int i = 1; i < numPlaintexts; ++i) {
        ciphertextMul = cryptoContext->EvalMult(ciphertextMul, ciphertexts[i]);
    }

The way you are doing the multiplication requires a multiplicative depth of numPlaintexts - 1. To achieve a smaller multiplicative depth, you have to multiply ciphertexts in a binary tree shape, the way I showed in my previous post.

Note that OpenFHE API includes an EvalMultMany operation (Template Class CryptoContextImpl — OpenFHE documentation) that multiplies ciphertexts in a vector using the binary tree method.

1 Like