Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: encrypted_ntt and plain_ntt parameter mismatch in evaluate_polynomial #224

Open
kamzon opened this issue Dec 7, 2023 · 1 comment
Labels

Comments

@kamzon
Copy link

kamzon commented Dec 7, 2023

Description:
I encountered a ValueError while using the Pyfhel library in the evaluate_polynomial function. The error specifically points to a parameter mismatch between encrypted_ntt and plain_ntt. The issue arises when attempting to perform certain operations within the function.
Code Issue:
/encry_minimaxcompa.py:63: UserWarning: Cannot align scales 0 and 30 (available rescalings: [])
monomial = monomial * coeff
Traceback (most recent call last):
File encry_minimaxcompa.py", line 108, in
c_result = MinimaxComp(encrypted_a, encrypted_b, alpha, epsilon, depth, margin, HE)
File "encry_minimaxcompa.py", line 20, in MinimaxComp
result = evaluate_polynomial(p, c_x, HE)
File "//encry_minimaxcompa.py", line 63, in evaluate_polynomial
monomial = monomial * coeff
File "Pyfhel/PyCtxt.pyx", line 468, in Pyfhel.PyCtxt.PyCtxt.mul
File "Pyfhel/Pyfhel.pyx", line 1224, in Pyfhel.Pyfhel.Pyfhel.multiply_plain
ValueError: encrypted_ntt and plain_ntt parameter mismatch

Code Snippet:

def evaluate_polynomial(coefficients, ctxt_x, HE):
    c_result = []
    HE.relinKeyGen()
    for i, coeff in enumerate([1,1,1]):
        if i == 0:
            monomial = HE.encrypt(1)
        else:
            monomial = ctxt_x
            HE.rescale_to_next(monomial)
            HE.relinKeyGen()
            monomial = ~monomial
            for j in range(1, i):
                monomial = monomial * ctxt_x
                HE.rescale_to_next(monomial)
                HE.relinKeyGen()
                monomial = ~monomial
        HE.relinKeyGen()
        monomial = monomial * coeff
        HE.rescale_to_next(monomial)
        HE.relinKeyGen()
        HE.relinearize(monomial)
        monomial = ~monomial
        c_result.append(monomial)
    return c_result
@kamzon kamzon added the bug label Dec 7, 2023
@ibarrond
Copy link
Owner

@kamzon It looks like you ran out of available rescalings. Try adding more moduli to the qi in the ContextGen parameters, one per rescaling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants