From 7f110a33e80abda0fbf408a57511af5c3643d00a Mon Sep 17 00:00:00 2001 From: David Kazlauskas Date: Fri, 22 Nov 2024 07:34:42 +0200 Subject: [PATCH 1/2] fix: executor key cloning --- fhevm-engine/executor/src/server.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fhevm-engine/executor/src/server.rs b/fhevm-engine/executor/src/server.rs index 6062f3af..6cf74898 100644 --- a/fhevm-engine/executor/src/server.rs +++ b/fhevm-engine/executor/src/server.rs @@ -14,7 +14,7 @@ use fhevm_engine_common::{ types::{get_ct_type, FhevmError, Handle, SupportedFheCiphertexts, HANDLE_LEN, SCALAR_LEN}, }; use sha3::{Digest, Keccak256}; -use std::{borrow::Borrow, cell::Cell, collections::HashMap}; +use std::{cell::Cell, collections::HashMap}; use tfhe::{set_server_key, zk::CompactPkePublicParams}; use tokio::task::spawn_blocking; use tonic::{transport::Server, Code, Request, Response, Status}; @@ -78,6 +78,7 @@ impl FhevmExecutor for FhevmExecutorService { req: Request, ) -> Result, Status> { let public_params = self.keys.public_params.clone(); + let sks = self.keys.server_key.clone(); let resp = spawn_blocking(move || { let req = req.get_ref(); let mut state = ComputationState::default(); @@ -113,7 +114,6 @@ impl FhevmExecutor for FhevmExecutorService { let mut sched = Scheduler::new(&mut graph.graph, LOCAL_RAYON_THREADS.get()); let now = std::time::SystemTime::now(); - let sks: tfhe::ServerKey = SERVER_KEY.borrow().take().expect("Server key missing"); SERVER_KEY.set(Some(sks.clone())); if sched.schedule(sks).await.is_err() { return Some(Resp::Error(SyncComputeError::ComputationFailed.into())); From 9f93fc643a023b96af49a59fd787e5e7d84d0a1f Mon Sep 17 00:00:00 2001 From: David Kazlauskas Date: Fri, 22 Nov 2024 11:14:57 +0200 Subject: [PATCH 2/2] fix: remove SERVER_KEY thread local variable --- fhevm-engine/executor/src/server.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/fhevm-engine/executor/src/server.rs b/fhevm-engine/executor/src/server.rs index 6cf74898..0fcc9c46 100644 --- a/fhevm-engine/executor/src/server.rs +++ b/fhevm-engine/executor/src/server.rs @@ -27,13 +27,11 @@ pub mod executor { } thread_local! { - pub static SERVER_KEY: Cell> = const {Cell::new(None)}; pub static LOCAL_RAYON_THREADS: Cell = const {Cell::new(8)}; } pub fn start(args: &crate::cli::Args) -> Result<()> { let keys: FhevmKeys = SerializedFhevmKeys::load_from_disk(&args.fhe_keys_directory).into(); - SERVER_KEY.set(Some(keys.server_key.clone())); LOCAL_RAYON_THREADS.set(args.policy_fhe_compute_threads); let executor = FhevmExecutorService::new(keys.clone()); let runtime = tokio::runtime::Builder::new_multi_thread() @@ -114,7 +112,6 @@ impl FhevmExecutor for FhevmExecutorService { let mut sched = Scheduler::new(&mut graph.graph, LOCAL_RAYON_THREADS.get()); let now = std::time::SystemTime::now(); - SERVER_KEY.set(Some(sks.clone())); if sched.schedule(sks).await.is_err() { return Some(Resp::Error(SyncComputeError::ComputationFailed.into())); }