From 19d1022d611aeca69c72671d702f0b485cc7a0a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20=27birdy=27=20Danjou?= Date: Fri, 14 Jun 2024 18:42:15 +0200 Subject: [PATCH] fix: fix the destroy instruction --- fhevm/tfhe/tfhe_ciphertext.go | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/fhevm/tfhe/tfhe_ciphertext.go b/fhevm/tfhe/tfhe_ciphertext.go index 5f7dfb0..666cc4b 100644 --- a/fhevm/tfhe/tfhe_ciphertext.go +++ b/fhevm/tfhe/tfhe_ciphertext.go @@ -2689,29 +2689,41 @@ func GenerateObliviousPseudoRandom(generatedType FheUintType, seed uint64, numbe switch generatedType { case FheUint4: resultPtr = C.generate_oblivious_pseudo_random_uint4(C.uint64_t(seed), C.uint64_t(numberOfBits), sks) + if resultPtr == nil { + return nil, errors.New("GenerateObliviousPseudoRandom: generation failed") + } + defer C.destroy_fhe_uint4(resultPtr) case FheUint8: resultPtr = C.generate_oblivious_pseudo_random_uint8(C.uint64_t(seed), C.uint64_t(numberOfBits), sks) + if resultPtr == nil { + return nil, errors.New("GenerateObliviousPseudoRandom: generation failed") + } + defer C.destroy_fhe_uint8(resultPtr) case FheUint16: resultPtr = C.generate_oblivious_pseudo_random_uint16(C.uint64_t(seed), C.uint64_t(numberOfBits), sks) + if resultPtr == nil { + return nil, errors.New("GenerateObliviousPseudoRandom: generation failed") + } + defer C.destroy_fhe_uint16(resultPtr) case FheUint32: resultPtr = C.generate_oblivious_pseudo_random_uint32(C.uint64_t(seed), C.uint64_t(numberOfBits), sks) + if resultPtr == nil { + return nil, errors.New("GenerateObliviousPseudoRandom: generation failed") + } + defer C.destroy_fhe_uint32(resultPtr) case FheUint64: resultPtr = C.generate_oblivious_pseudo_random_uint64(C.uint64_t(seed), C.uint64_t(numberOfBits), sks) + if resultPtr == nil { + return nil, errors.New("GenerateObliviousPseudoRandom: generation failed") + } + defer C.destroy_fhe_uint64(resultPtr) default: return nil, fmt.Errorf("GenerateObliviousPseudoRandom: unsupported ciphertext type %d", generatedType) } - if resultPtr == nil { - return nil, errors.New("GenerateObliviousPseudoRandom: generation failed") - } - defer C.destroy_fhe_bool(resultPtr) + ser := &C.DynamicBuffer{} switch generatedType { - case FheBool: - ret := C.serialize_fhe_bool(resultPtr, ser) - if ret != 0 { - return nil, errors.New("GenerateObliviousPseudoRandom: serialization failed") - } case FheUint4: ret := C.serialize_fhe_uint4(resultPtr, ser) if ret != 0 {