I’m having problems using EvalSum after serializing and deserializing the CrytoContext as I get the following error:
RuntimeError: /openfhe-development/src/pke/lib/cryptocontext.cpp:146 You need to use EvalSumKeyGen so that you have EvalSumKeys available for this ID
I set the cryptocontext like this:
def generate_k1_k2(scaleModSize,batchSize, multDepth):
parameters = CCParamsCKKSRNS()
parameters.SetScalingModSize(scaleModSize)
parameters.SetBatchSize(batchSize)
parameters.SetMultiplicativeDepth(multDepth)
# CryptoContext generation
node1CC = GenCryptoContext(parameters)
node1CC.Enable(PKE)
node1CC.Enable(KEYSWITCH)
node1CC.Enable(LEVELEDSHE)
node1CC.Enable(ADVANCEDSHE)
node1CC.Enable(MULTIPARTY)
## Perform Key Generation Operation
############################################################
print("Running key generation (used for source data)...")
# Round 1 (party A)
print("Round 1 (party A) started.")
kp1 = node1CC.KeyGen()
# Generate evalmult key part for A
evalMultKey = node1CC.KeySwitchGen(kp1.secretKey, kp1.secretKey)
# Generate evalsum key part for A
node1CC.EvalSumKeyGen(kp1.secretKey)
evalSumKeys = node1CC.GetEvalSumKeyMap(kp1.secretKey.GetKeyTag())
print("Round 1 of key generation completed.")
# Round 2 (party B)
print("Round 2 (party B) started.")
print("Joint public key for (s_a + s_b) is generated...")
kp2 = node1CC.MultipartyKeyGen(kp1.publicKey)
evalMultKey2 = node1CC.MultiKeySwitchGen(kp2.secretKey, kp2.secretKey, evalMultKey)
print("Joint evaluation multiplication key for (s_a + s_b) is generated...")
evalMultAB = node1CC.MultiAddEvalKeys(evalMultKey, evalMultKey2, kp2.publicKey.GetKeyTag())
print("Joint evaluation multiplication key (s_a + s_b) is transformed into s_b*(s_a + s_b)...")
evalMultBAB = node1CC.MultiMultEvalKey(kp2.secretKey, evalMultAB, kp2.publicKey.GetKeyTag())
evalSumKeysB = node1CC.MultiEvalSumKeyGen(kp2.secretKey, evalSumKeys, kp2.publicKey.GetKeyTag())
print("Joint evaluation summation key for (s_a + s_b) is generated...")
evalSumKeysJoin = node1CC.MultiAddEvalSumKeys(evalSumKeys, evalSumKeysB, kp2.publicKey.GetKeyTag())
node1CC.InsertEvalSumKey(evalSumKeysJoin)
print("Round 2 of key generation completed.")
print("Round 3 (party A) started.")
print("Joint key (s_a + s_b) is transformed into s_a*(s_a + s_b)...")
evalMultAAB = node1CC.MultiMultEvalKey(kp1.secretKey, evalMultAB, kp2.publicKey.GetKeyTag())
print("Computing the final evaluation multiplication key for (s_a + s_b)*(s_a + s_b)...")
evalMultFinal = node1CC.MultiAddEvalMultKeys(evalMultAAB, evalMultBAB, evalMultAB.GetKeyTag())
node1CC.InsertEvalMultKey([evalMultFinal])
if not SerializeToFile(f"{mylocalfolder}/{ccLocation}", node1CC, BINARY):
raise Exception("Exception writing cryptocontext to cryptocontext.txt")
Can anyone help me?