CKKS: Plaintext from EVAL to COEFF

Hello,
For academic propose I’m testing a few things and one of them is changing a encoded data from COEFF space.
I’m 90% sure that what I’m doing is correct, but I need 100%.
So If I want to change the j coeff of a plaintext I do this:

Initialization
input
etc
.
.
.
Plaintext ptxt1 = cc->MakeCKKSPackedPlaintext(input);
ptxt1->GetElement<DCRTPoly>().SwitchFormat();
auto originalCoeff = ptxt1->GetElement<DCRTPoly>().GetAllElements()[0][j];
ptxt1->GetElement<DCRTPoly>().GetAllElements()[0][j] = changeCoeff(originalCoeff);
ptxt1->GetElement<DCRTPoly>().SwitchFormat();

Need to be sure that:

  1. ptxt1 is in deed the encoding of the input data
  2. The format of ptxt1->GetElement().GetAllElements()[0] is in EVAL space
  3. When i make ptxt1->GetElement().SwitchFormat() all the elements that I will receive with ptxt1->GetElement().GetAllElements()[0] are in deed now in COEFF space

It would be more helpful if you could provide additional information about your objective.

For the code you provided above, I can confirm the following:
ptxt1 after encoding will be in EVAL mode (evaluation representation of the RNS polynomials).
When you call ptxt1->GetElement<DCRTPoly>().SwitchFormat();, the representation of ptxt1 RNS polynomials will become COEFF mode (coefficient representation of the RNS polynomials).
You seem to be only updating the j-th coefficient of the first RNS polynomial, which does not make sense to me.

Note that CKKS encoding invokes a special form of Discrete Fourier Transform to represent the input message (input in your example) as a polynomial. To me, the input message is treated as one unit and I do not think you can change one part of it that way, unless your input message includes only a single value.

Btw, you can print out the plaintext DCRT element and see check its representation as follows:
std::cout << ptxt1->GetElement<DCRTPoly>();

Perfect! I’m doing a resilience analysis of the CKKS scheme when a bit flip occurs in different stages of the pipeline. Because of what you say of NTT always breaks…

When we encode/encrypt some input, OpenFHE saves only the data in DCRTPoly? Or it also saves the NativePoly or extra info?

Only DCRTPoly is used after encode/encrypt.