Question: Error when Serialization of ciphertext
Closed this issue · 3 comments
Hello. I want to serialize ciphertext into xx.bin and deserialize them into the ciphertext, but some errors are printed. Thanks.
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x734507]
The error is at : o_ct.UnmarshalBinary(data);
My test function is:
func serialize_ct(ct []*rlwe.Ciphertext) []*rlwe.Ciphertext {
var o_cts []*rlwe.Ciphertext
var o_ct *rlwe.Ciphertext
for i := 0; i < len(ct); i++ {
if data, eff := ct[i].MarshalBinary(); eff != nil {
panic(eff)
} else {
os.WriteFile("ct"+fmt.Sprint(i)+".bin", data, 0644)
}
}
for i := 0; i < len(ct); i++ {
data, _ := os.ReadFile("ct" + fmt.Sprint(i) + ".bin")
if err := o_ct.UnmarshalBinary(data); err != nil {
panic(err)
} else {
o_cts = append(o_cts, o_ct)
}
}
return o_cts
}
There are two issues with your code, and it is not related to the library: o_ct
is nil when you unmarshal the data on it, hence your error. Secondly, if you do not re-declare it inside the loop, it will overwrite the underlying ciphertext it since it is a pointer to a ciphertext.
Additionally, Lattigo provides marshalling of ciphertext vectors in utils/structs
Thanks for your answer. It is work!!!