diff --git a/core/crypto/src/signature.rs b/core/crypto/src/signature.rs index 47bfacebc63..46f03bdc9f8 100644 --- a/core/crypto/src/signature.rs +++ b/core/crypto/src/signature.rs @@ -7,11 +7,11 @@ use std::str::FromStr; use borsh::{BorshDeserialize, BorshSerialize}; use ed25519_dalek::ed25519::signature::{Signature as _, Signer as _, Verifier as _}; +use ethereum_types::U256; use lazy_static::lazy_static; use rand_core::OsRng; use secp256k1::Message; use serde::{Deserialize, Serialize}; -use ethereum_types::U256; lazy_static! { pub static ref SECP256K1: secp256k1::Secp256k1 = secp256k1::Secp256k1::new(); @@ -604,7 +604,7 @@ impl Secp256K1Signature { pub fn recover( &self, - msg: [u8; 32], + msg: impl AsRef<[u8]>, ) -> Result { let v = self.check_v()?; @@ -616,10 +616,12 @@ impl Secp256K1Signature { .map_err(|err| crate::errors::ParseSignatureError::InvalidData { error_message: err.to_string(), })?; - let msg = Message::from(msg); + let msg = &Message::from_slice(msg.as_ref()).map_err(|err| { + crate::errors::ParseSignatureError::InvalidData { error_message: err.to_string() } + })?; let res = SECP256K1 - .recover(&msg, &recoverable_sig) + .recover(msg, &recoverable_sig) .map_err(|err| crate::errors::ParseSignatureError::InvalidData { error_message: err.to_string(), })? diff --git a/runtime/near-vm-logic/src/logic.rs b/runtime/near-vm-logic/src/logic.rs index f37cae487fd..29e4d2af67a 100644 --- a/runtime/near-vm-logic/src/logic.rs +++ b/runtime/near-vm-logic/src/logic.rs @@ -1016,7 +1016,7 @@ impl<'a> VMLogic<'a> { let mut hash_bytes = [0u8; 32]; self.memory_get_into(hash_ptr, &mut hash_bytes)?; - if let Ok(pk) = signature.recover(hash_bytes) { + if let Ok(pk) = signature.recover(&hash_bytes) { self.internal_write_register(register_id, pk.as_ref().to_vec())?; return Ok(true as u64); };