Polynomial mismatch doing switching format when `n` is set to 2

The polynomial coefficient mismatch can be reproduced as follows. Note that the same issue doesn’t appear when n is set to a higher power of two.

    usint n      = 2; 
    size_t kRes  = 4;
    size_t size  = 1;

    auto paramsTest = std::make_shared<ILDCRTParams<BigInteger>>(2 * n, size, kRes);

    // create a vector of strings "1" and "1"
    std::vector<std::string> coeffsTest = {"1", "1"};

    // Create a BigVector
    lbcrypto::BigVector bigVecTest(paramsTest->GetRingDimension(), paramsTest->GetModulus());

    for (size_t i = 0; i < coeffsTest.size() && i < paramsTest->GetRingDimension(); ++i) {
        bigVecTest[i] = BigInteger(coeffsTest[i]);
    }

    // Create a Poly that supports BigInteger coefficients
    lbcrypto::PolyImpl<lbcrypto::BigVector> polyLargeTest(paramsTest, Format::COEFFICIENT);
    polyLargeTest.SetValues(bigVecTest, Format::COEFFICIENT);

    // Convert polyLarge to a DCRTPoly
    lbcrypto::DCRTPoly dcrtPolyTest(polyLargeTest, paramsTest);

    std::cout << "dcrtPolyTest before set to eval" << dcrtPolyTest << std::endl; // [1, 1] correct!

    dcrtPolyTest.SetFormat(Format::EVALUATION);

    std::cout << "dcrtPolyTest after set to eval " << dcrtPolyTest << std::endl; // [6, 9] correct!

    dcrtPolyTest.SetFormat(Format::COEFFICIENT);

    std::cout << "dcrtPolyTest after set back to coef" << dcrtPolyTest << std::endl; // [2, 0] wrong!

The issue is confirmed. INTT has a problem when the ring dimension is 2. We created an issue here, and it will be fixed in the upcoming release. In fact, a PR has already been created here.

Thank you for reporting this problem.

Note that the case where the ring dimension is set to 2 is unlikely to be encountered in practice as the ring dimension for secure instantiations of FHE schemes would be much larger.