Skip to content

Commit d219010

Browse files
committed
chore(coprocessor): map verify_and_expand panics (if any) to an error
1 parent 7e7c3a9 commit d219010

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

coprocessor/fhevm-engine/zkproof-worker/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ pub enum ExecutionError {
6262

6363
#[error("Too many inputs: {0}")]
6464
TooManyInputs(usize),
65+
66+
#[error("Panic occurred during verify and expand: {0}")]
67+
VerifyExpandPanic(String),
6568
}
6669

6770
impl From<ExecutionError> for ServiceError {

coprocessor/fhevm-engine/zkproof-worker/src/verifier.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use fhevm_engine_common::tfhe_ops::{current_ciphertext_version, extract_ct_list}
77
use fhevm_engine_common::types::SupportedFheCiphertexts;
88

99
use fhevm_engine_common::utils::safe_deserialize_conformant;
10+
use fhevm_engine_common::with_panic_guard;
1011
use hex::encode;
1112
use lru::LruCache;
1213
use sha3::Digest;
@@ -353,7 +354,7 @@ pub(crate) fn verify_proof(
353354
set_server_key(keys.server_key.clone());
354355

355356
let mut s = span.child_span("verify_and_expand");
356-
let mut cts = match try_verify_and_expand_ciphertext_list(request_id, raw_ct, keys, aux_data) {
357+
let mut cts = match verify_and_expand_with_guard(request_id, raw_ct, keys, aux_data) {
357358
Ok(cts) => {
358359
telemetry::attribute(&mut s, "count", cts.len().to_string());
359360
telemetry::end_span(s);
@@ -382,6 +383,24 @@ pub(crate) fn verify_proof(
382383
Ok((cts, blob_hash))
383384
}
384385

386+
fn verify_and_expand_with_guard(
387+
request_id: i64,
388+
raw_ct: &[u8],
389+
keys: &FetchTenantKeyResult,
390+
aux_data: &auxiliary::ZkData,
391+
) -> Result<Vec<SupportedFheCiphertexts>, ExecutionError> {
392+
with_panic_guard!(try_verify_and_expand_ciphertext_list(
393+
request_id, raw_ct, keys, aux_data
394+
))
395+
.map_err(|err| {
396+
// Map panic to VerifyExpandPanic
397+
ExecutionError::VerifyExpandPanic(format!(
398+
"Panic occurred while verifying and expanding: {}",
399+
err
400+
))
401+
})?
402+
}
403+
385404
fn try_verify_and_expand_ciphertext_list(
386405
request_id: i64,
387406
raw_ct: &[u8],

0 commit comments

Comments
 (0)