Get the noise threshold on BFV/BGV #414
Unanswered
fedejinich
asked this question in
Q&A
Replies: 2 comments 3 replies
-
I'm trying to do the same as was proposed here but my results are almost the same after each operation, is this expected? I was expecting the noise to grow until the ciphertext is undecryptable, how can I achieve that? package main
import (
"fmt"
"github.com/tuneinsight/lattigo/v4/bfv"
"github.com/tuneinsight/lattigo/v4/rlwe"
)
func main() {
// setup a basic fh scheme
// do tons of multiplications
// measure noise
// it should grow
bfvParams, _ := bfv.NewParametersFromLiteral(bfv.PN15QP827pq)
bfvSK, _ := rlwe.NewKeyGenerator(bfvParams.Parameters).
GenKeyPairNew()
encryptor := bfv.NewEncryptor(bfvParams, bfvSK)
decryptor := bfv.NewDecryptor(bfvParams, bfvSK)
encoder := bfv.NewEncoder(bfvParams)
evks := rlwe.NewEvaluationKeySet()
evks.RelinearizationKey = rlwe.NewRelinearizationKey(bfvParams.Parameters)
evaluator := bfv.NewEvaluator(bfvParams, evks)
val := []uint64{2, 3, 3, 4, 2, 3}
pt := bfv.NewPlaintext(bfvParams, bfvParams.MaxLevel())
encoder.Encode(val, pt)
ct := encryptor.EncryptNew(pt)
pt = decryptor.DecryptNew(ct)
// var v []uint64
// v = encoder.DecodeUintNew(pt)
for i := 0; i < 10; i++ {
evaluator.Mul(ct, ct, ct)
// fmt.Println(v[:4])
fmt.Println(i)
// PrintNoise(evaluator, decryptor, encoder, ct, v, bfvParams)
PN(decryptor, encoder, evaluator, ct, val)
}
}
func PN(decryptor rlwe.Decryptor, encoder bfv.Encoder, evaluator bfv.Evaluator,
el *rlwe.Ciphertext, val []uint64) {
pt := decryptor.DecryptNew(el)
// encoder.DecodeUint(pt, val)
encoder.Encode(val, pt)
ct := evaluator.SubNew(el, pt)
res, _, _ := rlwe.Norm(ct, decryptor)
fmt.Printf("STD(noise) real: %f\n", res)
}
// PrintNoise prints the standard deviation of the noise in the given ciphertext.
func PrintNoise(evaluator bfv.Evaluator, decryptor rlwe.Decryptor, encoder bfv.Encoder, ct *rlwe.Ciphertext, values []uint64, params bfv.Parameters) int {
// Encode the coefficients back to a plaintext
pt := bfv.NewPlaintext(params, ct.Level())
encoder.Encode(values, pt)
// Subtract the encoded plaintext from the original ciphertext
vec := evaluator.SubNew(ct, pt)
// Calculate the norm of the resulting ciphertext, which gives the noise
res, _, _ := rlwe.Norm(vec, decryptor)
// Log the standard deviation of the noise
fmt.Printf("STD(noise)res: %d\n", int(res))
return int(res)
} STD(noise) real: 647.213323
1
STD(noise) real: 647.212887
2
STD(noise) real: 647.208673
3
STD(noise) real: 647.207073
4
STD(noise) real: 647.203124
5
STD(noise) real: 647.211714
6
STD(noise) real: 647.206122
7
STD(noise) real: 647.207491
8
STD(noise) real: 647.208768
9
STD(noise) real: 647.207933
|
Beta Was this translation helpful? Give feedback.
0 replies
-
no news about this? this should be a very basic scenario, I'm a bit frustrated |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
How can I check the noise threshold of a specific BFV/BGV scheme? I want to calculate how many operations my scheme supports
Beta Was this translation helpful? Give feedback.
All reactions