From c04cf175f4a8b830c4594f39f3c12187764bb26b Mon Sep 17 00:00:00 2001 From: youben11 Date: Fri, 5 Jan 2024 15:31:37 +0100 Subject: [PATCH] fix: remove the need for cks except for tests --- fhevm/tfhe.go | 17 ++++------------- fhevm/tfhe_test.go | 2 +- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/fhevm/tfhe.go b/fhevm/tfhe.go index 3de5a33..05c6d6f 100644 --- a/fhevm/tfhe.go +++ b/fhevm/tfhe.go @@ -1572,7 +1572,7 @@ func generateFhevmKeys() (unsafe.Pointer, unsafe.Pointer, unsafe.Pointer) { return keys.sks, keys.cks, keys.pks } -func globalKeysPresent() bool { +func allGlobalKeysPresent() bool { return sks != nil && cks != nil && pks != nil } @@ -1604,11 +1604,6 @@ func InitGlobalKeysFromFiles(keysDir string) error { if err != nil { return err } - var cksPath = path.Join(keysDir, "cks") - cksBytes, err := os.ReadFile(cksPath) - if err != nil { - fmt.Println("INFO: cks not loaded from: " + keysDir) - } var pksPath = path.Join(keysDir, "pks") pksBytes, err := os.ReadFile(pksPath) if err != nil { @@ -1620,12 +1615,6 @@ func InitGlobalKeysFromFiles(keysDir string) error { pksHash = crypto.Keccak256Hash(pksBytes) pks = C.deserialize_compact_public_key(toBufferView(pksBytes)) - // cks will be handled by the KMS from now on - // TODO: completely remove after KMS is well tested - if len(cksBytes) > 0 { - cks = C.deserialize_client_key(toBufferView(cksBytes)) - } - initCiphertextSizes() fmt.Println("INFO: global keys loaded from: " + keysDir) @@ -1999,7 +1988,6 @@ func (lhs *tfheCiphertext) executeBinaryCiphertextOperation(rhs *tfheCiphertext, return res, nil } - func (first *tfheCiphertext) executeTernaryCiphertextOperation(lhs *tfheCiphertext, rhs *tfheCiphertext, op8 func(first unsafe.Pointer, lhs unsafe.Pointer, rhs unsafe.Pointer) unsafe.Pointer, op16 func(first unsafe.Pointer, lhs unsafe.Pointer, rhs unsafe.Pointer) unsafe.Pointer, @@ -2743,6 +2731,9 @@ func (ct *tfheCiphertext) castTo(castToType FheUintType) (*tfheCiphertext, error } func (ct *tfheCiphertext) decrypt() (big.Int, error) { + if cks == nil { + return *new(big.Int).SetUint64(0), errors.New("cks is not initialized") + } var value uint64 var ret C.int switch ct.fheUintType { diff --git a/fhevm/tfhe_test.go b/fhevm/tfhe_test.go index 9b2f1ae..b0da366 100644 --- a/fhevm/tfhe_test.go +++ b/fhevm/tfhe_test.go @@ -27,7 +27,7 @@ import ( // generate keys if not present func setup() { - if !globalKeysPresent() { + if !allGlobalKeysPresent() { fmt.Println("INFO: initializing global keys in tests") initGlobalKeysWithNewKeys() }