Usage of sign circuit in CKKS #541
-
Hello, I'm currently in need of the sign(x) operator and I've tried to implement it using the CKKS circuit. I've looked at the documentation from the function itself and initialized all parameters using the CKKS general and bootstrapping tutorial. Unfortunately, I've not been able to get the function running, I keep getting this error:
I've tried adding a GaloisKey for 5^4096 to the comparison evaluator, but to no luck. // Init
var err error
var params ckks.Parameters
LogN := 14
if params, err = ckks.NewParametersFromLiteral(
ckks.ParametersLiteral{
LogN: LogN,
LogQ: []int{38, 28, 28, 28, 28, 28, 28, 28, 28},
LogP: []int{61},
LogDefaultScale: 28,
}); err != nil {
panic(err)
}
keyGen := rlwe.NewKeyGenerator(params)
secretKey := keyGen.GenSecretKeyNew()
publicKey := keyGen.GenPublicKeyNew(secretKey)
relinearizationKey := keyGen.GenRelinearizationKeyNew(secretKey)
galEls := make([]uint64, 1)
galEls[0] = params.GaloisElement(int(math.Pow(5, 4096)))
evaluationKey := rlwe.NewMemEvaluationKeySet(relinearizationKey, keyGen.GenGaloisKeysNew(galEls, secretKey)...)
encoder := ckks.NewEncoder(params)
encryptor := rlwe.NewEncryptor(params, publicKey)
decryptor := rlwe.NewDecryptor(params, secretKey)
evaluator := ckks.NewEvaluator(params, evaluationKey)
// https://github.com/tuneinsight/lattigo/blob/945cdf37938c253a48d76e29be461c2401cff730/examples/singleparty/ckks_bootstrapping/basics/main.go#L56
btpParametersLit := bootstrapping.ParametersLiteral{
LogN: utils.Pointy(LogN),
LogP: []int{61, 61, 61, 61},
Xs: params.Xs(),
}
btpParameters, _ := bootstrapping.NewParametersFromLiteral(params, btpParametersLit)
btpEvKeys, _, _ := btpParameters.GenEvaluationKeys(secretKey)
bootstrapper, _ := bootstrapping.NewEvaluator(btpParameters, btpEvKeys)
minimaxEvaluator := minimax.NewEvaluator(params, evaluator, bootstrapper)
comparisonEvaluator := comparison.NewEvaluator(params, minimaxEvaluator)
comparisonEvaluator.WithKey(rlwe.NewMemEvaluationKeySet(relinearizationKey, keyGen.GenGaloisKeysNew(galEls, secretKey)...))
// Sign operator test
m1 := []float64{2, -3, 4}
p1 := ckks.NewPlaintext(params, params.MaxLevel())
if err := encoder.Encode(m1, p1); err != nil {
panic(err)
}
ct1, err := encryptor.EncryptNew(p1)
if err != nil {
panic(err)
}
ct2, err := comparisonEvaluator.Sign(ct1)
if err != nil {
panic(err)
}
pt2 := decryptor.DecryptNew(ct2)
r1 := make([]float64, params.MaxSlots())
if err := encoder.Decode(pt2, r1); err != nil {
panic(err)
}
fmt.Println(r1[:3]) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You need to use params.GaloisElementForComplexConjugation() (which is cyclotomic order - 1). By the way, params.GaloisElements already computes 5^k mod cyclotomic order. |
Beta Was this translation helpful? Give feedback.
You need to use params.GaloisElementForComplexConjugation() (which is cyclotomic order - 1). By the way, params.GaloisElements already computes 5^k mod cyclotomic order.