Skip to content

Commit 64bc5ba

Browse files
Merge pull request ethereum#62 from zama-ai/louis-patch-cks-bug
fix(tfhe): warn when key file not found Patch the bug where a full node would silently fail when not finding the client key `cks`. Nodes now only look for the client key `cks` if they are configured in `oracle` mode and emit a warning when either the server key `sks` or the client key `cks` is not found.
2 parents a3fc1a7 + f1cd803 commit 64bc5ba

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

core/vm/tfhe.go

+14-9
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ void* trivial_encrypt(void* sks, uint64_t value) {
153153
return ct;
154154
}
155155
156-
size_t get_message_modulus(void* cks) {
156+
size_t get_message_modulus(void* sks) {
157157
size_t modulus = 0;
158158
159-
const int r = shortint_client_key_get_message_modulus(cks, &modulus);
159+
const int r = shortint_server_key_get_message_modulus(sks, &modulus);
160160
assert(r == 0);
161161
162162
return modulus;
@@ -167,8 +167,10 @@ import "C"
167167
import (
168168
"crypto/rand"
169169
"errors"
170+
"fmt"
170171
"os"
171172
"runtime"
173+
"strings"
172174
"sync/atomic"
173175
"time"
174176
"unsafe"
@@ -223,24 +225,27 @@ func init() {
223225

224226
sks_bytes, err := os.ReadFile(networkKeysDir + "sks")
225227
if err != nil {
228+
fmt.Print("WARNING: file sks not found.\n")
226229
return
227230
}
231+
sks = C.deserialize_server_key(toBufferView(sks_bytes))
228232

229-
cks_bytes, err := os.ReadFile(networkKeysDir + "cks")
230-
if err != nil {
231-
return
233+
if strings.ToLower(tomlConfig.Oracle.Mode) == "oracle" {
234+
cks_bytes, err := os.ReadFile(networkKeysDir + "cks")
235+
if err != nil {
236+
fmt.Print("WARNING: file cks not found.\n")
237+
return
238+
}
239+
cks = C.deserialize_client_key(toBufferView(cks_bytes))
232240
}
233241

234-
sks = C.deserialize_server_key(toBufferView(sks_bytes))
235-
cks = C.deserialize_client_key(toBufferView(cks_bytes))
236-
237242
// Use trivial encryption to determine the ciphertext size for the used parameters.
238243
// Note: parameters are embedded in the client `cks` key.
239244
ct := new(tfheCiphertext)
240245
ct.trivialEncrypt(1)
241246
fheCiphertextSize = len(ct.serialize())
242247

243-
fheMessageModulus = uint64(C.get_message_modulus(cks))
248+
fheMessageModulus = uint64(C.get_message_modulus(sks))
244249

245250
go runGc()
246251
}

0 commit comments

Comments
 (0)