lattigo icon indicating copy to clipboard operation
lattigo copied to clipboard

Bug[rgsw]: panic: runtime error when encrypting and `rgsw.Ciphertext` with an `rlwe.PublicKey`

Open Pro7ech opened this issue 1 year ago • 2 comments

What version of Lattigo are you using?

v5@latest

Does this issue persist with the latest release?

Yes

What were you trying to do?

Encrypt an rgsw.Ciphertext using the public key

What actually happened?

panic: runtime error: invalid memory address or nil pointer dereference

Reproducibility

package main

import (
	"github.com/tuneinsight/lattigo/v5/core/rgsw"
	"github.com/tuneinsight/lattigo/v5/core/rlwe"
)

func main() {
	params, err := rlwe.NewParametersFromLiteral(rlwe.ParametersLiteral{
		LogN:    11,
		LogQ:    []int{54},
		NTTFlag: true,
	})

	if err != nil {
		panic(err)
	}

	_, pk := rlwe.NewKeyGenerator(params).GenKeyPairNew()

	enc := rgsw.NewEncryptor(params, pk)

	ct := rgsw.NewCiphertext(params, params.MaxLevelQ(), params.MaxLevelP(), 7)
	pt := rlwe.NewPlaintext(params, ct.LevelQ())
	if err = enc.Encrypt(pt, ct); err != nil {
		panic(err)
	}
}

Pro7ech avatar Jun 03 '24 10:06 Pro7ech

Hey, to my knowledge RGSW uses the RingQP under the hood for the gadget products. Not specifying auxiliary primes P will result in an uninitialized RingP hence the nil pointer exception.

Maybe we could disallow parameters without P primes for RGSW?

qantik avatar Jun 04 '24 14:06 qantik

RingQP should still work even without P, as before doing operations it checks if there is or not a RingP. In practice RGSW is mostly used in contexts where the parameters are too small to accommodate for an auxiliary modulus P, such as blind rotations.

Pro7ech avatar Jun 07 '24 06:06 Pro7ech