Skip to content

Commit

Permalink
Pass hash_bytes as ref
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuajbouw committed Jun 21, 2021
1 parent 7f3114b commit 434145b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions core/crypto/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -604,7 +604,7 @@ impl Secp256K1Signature {

pub fn recover(
&self,
msg: [u8; 32],
msg: impl AsRef<[u8]>,
) -> Result<Secp256K1PublicKey, crate::errors::ParseSignatureError> {
let v = self.check_v()?;

Expand All @@ -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(),
})?
Expand Down
2 changes: 1 addition & 1 deletion runtime/near-vm-logic/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down

0 comments on commit 434145b

Please sign in to comment.