tuneinsight / lattigo

A library for lattice-based multiparty homomorphic encryption in Go
Apache License 2.0
1.19k stars 176 forks source link

[Question] Trying to multiply Ciphertexts with output of degree>=6. bfv #50

Closed HorusXXVI closed 1 year ago

HorusXXVI commented 4 years ago

HiHi, I was trying to multiply Ciphertexts multiple times using bfv for a program using MulNew(), however after certain amount of times I face the error: panic: runtime error: index out of range [6] with length 6 from inside the evaluator.go function tensorandrescale.

I also tried it with two random ciphers of degree three and it gives the same error (any other ciphers where the result is a poly is of degree>=6).

k := bfv.NewCiphertextRandom(params, 3) l := bfv.NewCiphertextRandom(params, 3) evaluator.MuNewl(k, l)

Same error when using Mul. I am using the default params inside the examples_bfv, and was wondering if this error is because I need to modify something to allow these larger polynomials.

ChristianMct commented 4 years ago

Hi @HorusXXVI and thanks for your feedback.

There is indeed a limitation on the maximum ciphertext degree in the multiplication. It lies in the size of some temporary buffers and is quite arbitrary (I think we didn't see this kind of high degree multiplication as a likely usage).

I'll label this as a potential enhancement, since the size of these buffer could be extended dynamically. As a workaround, you could increase their value yourself in bfv/evaluator.go, on lines 76-83:

for i := 0; i < 4; i++ {
    poolQ[i] = make([]*ring.Poly, 6)      // Change to max degree + 1 
    poolP[i] = make([]*ring.Poly, 6)      // Change to max degree + 1 
    for j := 0; j < 6; j++ {                        // Change to max degree + 1 
        poolQ[i][j] = q.NewPoly()
        poolP[i][j] = qm.NewPoly()
    }
}
Pro7ech commented 1 year ago

306 changes the maximum degree to 2 (in line with bgv and `ckks).