revm_precompile/secp256k1/
k256.rsuse k256::ecdsa::{Error, RecoveryId, Signature, VerifyingKey};
use primitives::{alloy_primitives::B512, keccak256, B256};
pub fn ecrecover(sig: &B512, mut recid: u8, msg: &B256) -> Result<B256, Error> {
let mut sig = Signature::from_slice(sig.as_slice())?;
if let Some(sig_normalized) = sig.normalize_s() {
sig = sig_normalized;
recid ^= 1;
}
let recid = RecoveryId::from_byte(recid).expect("recovery ID is valid");
let recovered_key = VerifyingKey::recover_from_prehash(&msg[..], &sig, recid)?;
let mut hash = keccak256(
&recovered_key
.to_encoded_point(false)
.as_bytes()[1..],
);
hash[..12].fill(0);
Ok(hash)
}