Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/precompiles/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub struct RIPEMD160;
impl RIPEMD160 {
pub(super) const ADDRESS: Address = super::make_address(0, 3);

#[cfg(not(feature = "testnet"))]
#[cfg(not(feature = "contract"))]
fn internal_impl(input: &[u8]) -> [u8; 20] {
use ripemd160::Digest;
let hash = ripemd160::Ripemd160::digest(input);
Expand Down Expand Up @@ -119,9 +119,9 @@ impl Precompile for RIPEMD160 {
if cost > target_gas {
Err(ExitError::OutOfGas)
} else {
#[cfg(not(feature = "testnet"))]
#[cfg(not(feature = "contract"))]
let hash = Self::internal_impl(input);
#[cfg(feature = "testnet")]
#[cfg(feature = "contract")]
let hash = crate::sdk::ripemd160(input);
// The result needs to be padded with leading zeros because it is only 20 bytes, but
// the evm works with 32-byte words.
Expand Down
6 changes: 3 additions & 3 deletions src/precompiles/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ mod consts {
pub(crate) fn ecrecover(hash: H256, signature: &[u8]) -> Result<Address, ExitError> {
assert_eq!(signature.len(), 65);

#[cfg(feature = "testnet")]
#[cfg(feature = "contract")]
return crate::sdk::ecrecover(hash, signature)
.map_err(|e| ExitError::Other(Borrowed(e.as_str())));

#[cfg(not(feature = "testnet"))]
#[cfg(not(feature = "contract"))]
internal_impl(hash, signature)
}

#[cfg(not(feature = "testnet"))]
#[cfg(not(feature = "contract"))]
fn internal_impl(hash: H256, signature: &[u8]) -> Result<Address, ExitError> {
use sha3::Digest;

Expand Down
7 changes: 0 additions & 7 deletions src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ use borsh::{BorshDeserialize, BorshSerialize};

const READ_STORAGE_REGISTER_ID: u64 = 0;
const INPUT_REGISTER_ID: u64 = 0;
#[cfg(feature = "testnet")]
const ECRECOVER_MESSAGE_SIZE: u64 = 32;
#[cfg(feature = "testnet")]
const ECRECOVER_SIGNATURE_LENGTH: u64 = 64;
#[cfg(feature = "testnet")]
const ECRECOVER_MALLEABILITY_FLAG: u64 = 1;

/// Register used to record evicted values from the storage.
Expand Down Expand Up @@ -51,9 +48,7 @@ mod exports {
fn random_seed(register_id: u64);
pub(crate) fn sha256(value_len: u64, value_ptr: u64, register_id: u64);
pub(crate) fn keccak256(value_len: u64, value_ptr: u64, register_id: u64);
#[cfg(feature = "testnet")]
pub(crate) fn ripemd160(value_len: u64, value_ptr: u64, register_id: u64);
#[cfg(feature = "testnet")]
pub(crate) fn ecrecover(
hash_len: u64,
hash_ptr: u64,
Expand Down Expand Up @@ -393,7 +388,6 @@ pub fn keccak(input: &[u8]) -> H256 {
}

/// Calls environment ripemd160 on given input.
#[cfg(feature = "testnet")]
pub fn ripemd160(input: &[u8]) -> [u8; 20] {
unsafe {
const REGISTER_ID: u64 = 1;
Expand All @@ -405,7 +399,6 @@ pub fn ripemd160(input: &[u8]) -> [u8; 20] {
}

/// Recover address from message hash and signature.
#[cfg(feature = "testnet")]
pub fn ecrecover(hash: H256, signature: &[u8]) -> Result<crate::prelude::Address, ECRecoverErr> {
unsafe {
let hash_ptr = hash.as_ptr() as u64;
Expand Down