From f7b015cd1bade8d04c932e6882644c95e7bd4832 Mon Sep 17 00:00:00 2001 From: nhtyy Date: Tue, 19 Nov 2024 10:26:01 -0800 Subject: [PATCH] fix: write 0 to hook caller on recovery failure --- crates/core/executor/src/hook.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/core/executor/src/hook.rs b/crates/core/executor/src/hook.rs index 3e54eca71c..374f6a52aa 100644 --- a/crates/core/executor/src/hook.rs +++ b/crates/core/executor/src/hook.rs @@ -131,14 +131,18 @@ pub fn hook_ecrecover(_: HookEnv, buf: &[u8]) -> Vec> { recovery_id ^= 1; }; let recid = RecoveryId::from_byte(recovery_id).expect("Computed recovery ID is invalid!"); + + // recovery failed, indicate to the caller + let Ok(recovered_key) = VerifyingKey::recover_from_prehash(&msg_hash[..], &sig, recid) else { + return vec![vec![0]]; + }; - let recovered_key = VerifyingKey::recover_from_prehash(&msg_hash[..], &sig, recid).unwrap(); let bytes = recovered_key.to_sec1_bytes(); let (_, s) = sig.split_scalars(); let s_inverse = s.invert(); - vec![bytes.to_vec(), s_inverse.to_bytes().to_vec()] + vec![vec![1], bytes.to_vec(), s_inverse.to_bytes().to_vec()] } #[cfg(test)]