# Does Homomorphic Constant Multiplication Require Additional Circuit Depth?

**URL:** <https://openfhe.discourse.group/t/does-homomorphic-constant-multiplication-require-additional-circuit-depth/1292>\
**Category:** FHE Questions\
**Created:** [May 24, 2024, 5:42am UTC](https://openfhe.discourse.group/t/does-homomorphic-constant-multiplication-require-additional-circuit-depth/1292 "2024-05-24T05:42:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![oksuman](https://avatars.discourse-cdn.com/v4/letter/o/6de8d8/32.png) [@oksuman](https://openfhe.discourse.group/u/oksuman)\
**Post date:** [May 24, 2024, 5:42am UTC](https://openfhe.discourse.group/t/does-homomorphic-constant-multiplication-require-additional-circuit-depth/1292/1 "2024-05-24T05:42:15Z")

</div>

Hello,

I have a question about the minimum required level of ciphertexts to evaluate a homomorphic circuit. Specifically, I am wondering if constant multiplication in homomorphic encryption consumes a level.

When performing homomorphic multiplication between ciphertexts, it is understood that this requires a level. However, does constant multiplication also always require rescaling after the operation?

When setting the level of ciphertext to evaluate a homomorphic circuit, should I take constant multiplication into account, or can I skip rescaling in some cases?

(Or are the cases where I just multiply a constant to a ciphertext and the case where I multiply a packed plaintext to a ciphertext different?)

Thank you.

- In below code, why the output is as the screenshot instead of decryption failure or the vector with all entries 1?

```auto
    parameters.SetSecurityLevel(HEStd_NotSet);
    parameters.SetRingDim(1 << 12);

    
    usint scalingModSize = 50;
    uint32_t multDepth = 0;

    parameters.SetScalingModSize(scalingModSize);
    parameters.SetMultiplicativeDepth(multDepth);
    CryptoContext<DCRTPoly> cc = GenCryptoContext(parameters);
    cc->Enable(PKE);
    cc->Enable(KEYSWITCH);
    cc->Enable(LEVELEDSHE);
    cc->Enable(ADVANCEDSHE);
    cc->Enable(FHE);

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

    std::vector<double> input;     
    for(int i=0; i <16; i++){
        input.push_back(0.5);
    }   
    Plaintext plaintext = cc->MakeCKKSPackedPlaintext(input);
    auto ciphertext = cc->Encrypt(keyPair.publicKey, plaintext);

    std::cout << "before eval ciph level: " << ciphertext->GetLevel() << std::endl;

    double c = 2.0;
    auto cmult = cc->EvalMult(ciphertext, c);
    std::cout << "after constant multiplication level: " << cmult->GetLevel() << std::endl;
    Plaintext plaintextDec;
    cc->Decrypt(keyPair.secretKey, cmult, &plaintextDec);
    plaintextDec->SetLength(16);
    std::vector<double> finalResult = plaintextDec->GetRealPackedValue();
    std::cout << "output: " << finalResult << std::endl << std::endl;

```

Result was:

```auto
before eval ciph level: 0
after constant multiplication level: 1
output: [-8.67362e-19 -8.67362e-19 -8.67362e-19 -8.67362e-19 -8.67362e-19 -8.67362e-19 -8.67362e-19 -8.67362e-19 -8.67362e-19 -8.67362e-19 -8.67362e-19 -8.67362e-19 -8.67362e-19 -8.67362e-19 -8.67362e-19 -8.67362e-19]

```

---

<div class="post-metadata">

**Author:** ![narger](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/narger/32/420_2.png) [@narger](https://openfhe.discourse.group/u/narger)\
**Post date:** [May 24, 2024, 11:04am UTC](https://openfhe.discourse.group/t/does-homomorphic-constant-multiplication-require-additional-circuit-depth/1292/2 "2024-05-24T11:04:14Z")

</div>

> [@oksuman](#):
>
> When performing homomorphic multiplication between ciphertexts, it is understood that this requires a level. However, does constant multiplication also always require rescaling after the operation?

Yes. A constant value, under the hood, is still encoded as a plaintext, thus multiplied by a scale \Delta.

> [@oksuman](#):
>
> In below code, why the output is as the screenshot instead of decryption failure or the vector with all entries 1?

I guess this happens because you set a multiplicative depth equal to 0? Try to use (at least) 1.

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [May 24, 2024, 9:28pm UTC](https://openfhe.discourse.group/t/does-homomorphic-constant-multiplication-require-additional-circuit-depth/1292/3 "2024-05-24T21:28:08Z")

</div>

@narger is generally correct, but there is also an undocumented capability (`MultByInteger` or `MultByIntegerInPlace`) to multiply by an integer (assumes a small integer) that does not require a level (it still scales the noise though by its value). This capability is used internally in CKKS bootstrapping.

To call it in you code, you would need to write

```auto
auto cmult = cc->GetScheme()->MultByInteger(ciphertext, c);

```

Note that `c` in this case should be `uint64_t` rather than `double`. In other words, it only works when multiplying by an integer.

---

<div class="post-metadata">

**Author:** ![narger](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/narger/32/420_2.png) [@narger](https://openfhe.discourse.group/u/narger)\
**Post date:** [May 24, 2024, 10:45pm UTC](https://openfhe.discourse.group/t/does-homomorphic-constant-multiplication-require-additional-circuit-depth/1292/4 "2024-05-24T22:45:49Z")

</div>

Did not know that, thank you! So this could be used to perform maskings by 0? Do you have any reference for that capability?

Thank you very much

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [May 24, 2024, 11:04pm UTC](https://openfhe.discourse.group/t/does-homomorphic-constant-multiplication-require-additional-circuit-depth/1292/5 "2024-05-24T23:04:58Z")

</div>

Unfortunately, this would not work for masking as in that case you have a vector of numbers in {0,1}, which after inverse FFT become real numbers (so they need to be scaled and rounded, just like a normal CKKS plaintext). This trick only works for multiplying by an integer scalar, e.g., 2.

---

<div class="post-metadata">

**Author:** ![zhihan](https://avatars.discourse-cdn.com/v4/letter/z/67e7ee/32.png) [@zhihan](https://openfhe.discourse.group/u/zhihan)\
**Post date:** [July 30, 2024, 9:08pm UTC](https://openfhe.discourse.group/t/does-homomorphic-constant-multiplication-require-additional-circuit-depth/1292/6 "2024-07-30T21:08:47Z")

</div>

Thanks! This makes sense. This explains only non-scalar multiplication in homomorphic polynomial evaluation (modular reduction) consumes levels.

---

<div class="post-metadata">

**Author:** ![Arseniy](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@Arseniy](https://openfhe.discourse.group/u/Arseniy)\
**Post date:** [September 10, 2024, 3:17pm UTC](https://openfhe.discourse.group/t/does-homomorphic-constant-multiplication-require-additional-circuit-depth/1292/7 "2024-09-10T15:17:13Z")

</div>

Hello,

I’m hoping to clarify something regarding multiplication in OpenFHE. From what I understand, performing a multiplication by a double or plaintext consumes one multiplication level, and each multiplication requires a rescaling afterward.

I have a couple of questions related to this:

1. Is the need to rescale after scalar and plaintext multiplications a theoretical requirement, or is it an implementation constraint in OpenFHE?
2. If I work in `FIXEDMANUAL` mode and choose not to rescale after scalar or plaintext multiplications, will the results still be accurate? Or could this lead to incorrect results or potential overflow?

Thank you in advance for your help!

Best regards,  
Arseniy

cc @sloede

---

<div class="post-metadata">

**Author:** ![ypolyakov](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/ypolyakov/32/47_2.png) [@ypolyakov](https://openfhe.discourse.group/u/ypolyakov)\
**Post date:** [September 11, 2024, 1:46pm UTC](https://openfhe.discourse.group/t/does-homomorphic-constant-multiplication-require-additional-circuit-depth/1292/8 "2024-09-11T13:46:39Z")

</div>

Please create a new topic for your question as the prior question was answered and marked as a solution.

---

<div class="post-metadata">

**Author:** ![Haow\_P](https://avatars.discourse-cdn.com/v4/letter/h/da6949/32.png) [@Haow\_P](https://openfhe.discourse.group/u/Haow_P)\
**Post date:** [April 10, 2025, 4:41am UTC](https://openfhe.discourse.group/t/does-homomorphic-constant-multiplication-require-additional-circuit-depth/1292/9 "2025-04-10T04:41:36Z")

</div>

Is there any theoretical problem with multiplying by a double?  
Thank you very much
