Skip to content

Commit

Permalink
fix: write 0 to hook caller on recovery failure
Browse files Browse the repository at this point in the history
  • Loading branch information
nhtyy committed Nov 19, 2024
1 parent 41532ee commit f7b015c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/core/executor/src/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,18 @@ pub fn hook_ecrecover(_: HookEnv, buf: &[u8]) -> Vec<Vec<u8>> {
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)]
Expand Down

0 comments on commit f7b015c

Please sign in to comment.