# Why is this single multiplication require more multiplicative depth?

**URL:** <https://openfhe.discourse.group/t/why-is-this-single-multiplication-require-more-multiplicative-depth/1855>\
**Category:** Library Questions\
**Created:** [February 3, 2025, 5:57pm UTC](https://openfhe.discourse.group/t/why-is-this-single-multiplication-require-more-multiplicative-depth/1855 "2025-02-03T17:57:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![malioboro](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@malioboro](https://openfhe.discourse.group/u/malioboro)\
**Post date:** [February 3, 2025, 5:57pm UTC](https://openfhe.discourse.group/t/why-is-this-single-multiplication-require-more-multiplicative-depth/1855/1 "2025-02-03T17:57:45Z")

</div>

Hi, I need help, I have this simple code, a single ciphertext-ciphertext multiplication:

```auto
int main(int argc, char* argv[]) {
    uint32_t batchSize = 8;
    CCParams<CryptoContextCKKSRNS> parameters;
    parameters.SetMultiplicativeDepth(2);
    parameters.SetScalingModSize(50);
    parameters.SetScalingTechnique(FIXEDMANUAL);
    parameters.SetBatchSize(batchSize);

    CryptoContext<DCRTPoly> cc = GenCryptoContext(parameters);

    cc->Enable(PKE);
    cc->Enable(KEYSWITCH);
    cc->Enable(LEVELEDSHE);

    auto keys = cc->KeyGen();
    cc->EvalMultKeyGen(keys.secretKey);

    std::vector<double> x = {100.0, 100.01, 100.02, 100.03, 100.04, 100.05, 100.06, 100.07};
    Plaintext ptxt = cc->MakeCKKSPackedPlaintext(x);
    auto c = cc->Encrypt(keys.publicKey, ptxt);

    auto c2 = cc->EvalMult(c, c);
    auto cRes = cc->Rescale(c2);

    Plaintext result;
    cc->Decrypt(keys.secretKey, cRes, &result);
    result->SetLength(batchSize);
    std::cout << "Results = " << result << std::endl;
    return 0;
}

```

It only has one multiplication, but when I set the `SetMultiplicativeDepth(1)` it returns the wrong results. I changed the `FIXEDMANUAL` to `FIXEDAUTO` and removed the rescaling process, but it still behaves the same. Is this expected?

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![andreea.alexandru](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/andreea.alexandru/32/378_2.png) [@andreea.alexandru](https://openfhe.discourse.group/u/andreea.alexandru)\
**Post date:** [February 3, 2025, 8:29pm UTC](https://openfhe.discourse.group/t/why-is-this-single-multiplication-require-more-multiplicative-depth/1855/2 "2025-02-03T20:29:53Z")

</div>

First, you are performing a ciphertext-ciphertext multiplication, not a plaintext-ciphertext multiplication.

Second, the results have the magnitude too large to be able to be decrypted when multiplicative depth is set to 1 and the moduli are set the way they are. You need to ensure that when decryption happens on level 0, the magnitude of the result is at most FirstModSize - ScalingModSize bits. You can check that either decreasing the inputs, e.g., divide by 10, or increasing the difference between FirstModSize (by default set to 60 bits) and the ScalingModSize, e.g., by setting the latter to 40 bits.

See also [EvalAdd does not add in some cases - #7 by ypolyakov](https://openfhe.discourse.group/t/evaladd-does-not-add-in-some-cases/517/7).

---

<div class="post-metadata">

**Author:** ![malioboro](https://avatars.discourse-cdn.com/v4/letter/m/eb8c5e/32.png) [@malioboro](https://openfhe.discourse.group/u/malioboro)\
**Post date:** [February 4, 2025, 2:13am UTC](https://openfhe.discourse.group/t/why-is-this-single-multiplication-require-more-multiplicative-depth/1855/3 "2025-02-04T02:13:18Z")

</div>

Thank you for the answer and the referenced discussion is clear now!

I am sorry that I wrote the question (code) while checking other cases, and it turns out it also happened in Ciphertext-ciphertext multiplication. I will update the question and title for future reference.
