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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ engine = []
contract = ["engine"]
evm_bully = []
log = []
exit-precompiles = ["contract"]
integration-test = ["log"]
12 changes: 10 additions & 2 deletions src/precompiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod bn128;
mod hash;
mod identity;
mod modexp;
#[cfg(feature = "exit-precompiles")]
mod native;
mod secp256k1;

Expand All @@ -11,6 +12,7 @@ use crate::precompiles::bn128::{BN128Add, BN128Mul, BN128Pair};
use crate::precompiles::hash::{RIPEMD160, SHA256};
use crate::precompiles::identity::Identity;
use crate::precompiles::modexp::ModExp;
#[cfg(feature = "exit-precompiles")]
use crate::precompiles::native::{ExitToEthereum, ExitToNear};
pub(crate) use crate::precompiles::secp256k1::ecrecover;
use crate::precompiles::secp256k1::ECRecover;
Expand Down Expand Up @@ -80,7 +82,9 @@ pub fn homestead_precompiles(
ECRecover::ADDRESS => Some(ECRecover::run(input, target_gas, context)),
SHA256::ADDRESS => Some(SHA256::run(input, target_gas, context)),
RIPEMD160::ADDRESS => Some(RIPEMD160::run(input, target_gas, context)),
#[cfg(feature = "exit-precompiles")]
ExitToNear::ADDRESS => Some(ExitToNear::run(input, target_gas, context)),
#[cfg(feature = "exit-precompiles")]
ExitToEthereum::ADDRESS => Some(ExitToEthereum::run(input, target_gas, context)),
_ => None,
}
Expand Down Expand Up @@ -108,7 +112,9 @@ pub fn byzantium_precompiles(
bn128::addresses::ADD => Some(BN128Add::<Byzantium>::run(input, target_gas, context)),
bn128::addresses::MUL => Some(BN128Mul::<Byzantium>::run(input, target_gas, context)),
bn128::addresses::PAIR => Some(BN128Pair::<Byzantium>::run(input, target_gas, context)),
#[cfg(feature = "exit-precompiles")]
ExitToNear::ADDRESS => Some(ExitToNear::run(input, target_gas, context)),
#[cfg(feature = "exit-precompiles")]
ExitToEthereum::ADDRESS => Some(ExitToEthereum::run(input, target_gas, context)),
_ => None,
}
Expand Down Expand Up @@ -137,7 +143,9 @@ pub fn istanbul_precompiles(
bn128::addresses::MUL => Some(BN128Mul::<Istanbul>::run(input, target_gas, context)),
bn128::addresses::PAIR => Some(BN128Pair::<Istanbul>::run(input, target_gas, context)),
Blake2F::ADDRESS => Some(Blake2F::run(input, target_gas, context)),
#[cfg(feature = "exit-precompiles")]
ExitToNear::ADDRESS => Some(ExitToNear::run(input, target_gas, context)),
#[cfg(feature = "exit-precompiles")]
ExitToEthereum::ADDRESS => Some(ExitToEthereum::run(input, target_gas, context)),
_ => None,
}
Expand Down Expand Up @@ -166,9 +174,9 @@ pub fn berlin_precompiles(
bn128::addresses::MUL => Some(BN128Mul::<Istanbul>::run(input, target_gas, context)),
bn128::addresses::PAIR => Some(BN128Pair::<Istanbul>::run(input, target_gas, context)),
Blake2F::ADDRESS => Some(Blake2F::run(input, target_gas, context)),
#[cfg(feature = "contract")]
#[cfg(feature = "exit-precompiles")]
ExitToNear::ADDRESS => Some(ExitToNear::run(input, target_gas, context)),
#[cfg(feature = "contract")]
#[cfg(feature = "exit-precompiles")]
ExitToEthereum::ADDRESS => Some(ExitToEthereum::run(input, target_gas, context)),
_ => None,
}
Expand Down
24 changes: 15 additions & 9 deletions src/precompiles/native.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
use evm::{Context, ExitError, ExitSucceed};

use super::{Precompile, PrecompileResult};
use crate::prelude::{is_valid_account_id, Cow, String, Vec, U256};
use crate::types::AccountId;

use crate::prelude::Vec;
#[cfg(feature = "exit-precompiles")]
use crate::{
prelude::{is_valid_account_id, Cow, String, U256},
types::AccountId,
};

#[cfg(feature = "exit-precompiles")]
mod costs {
use crate::types::Gas;

Expand All @@ -22,6 +27,7 @@ mod costs {

/// Get the current nep141 token associated with the current erc20 token.
/// This will fail is none is associated.
#[cfg(feature = "exit-precompiles")]
fn get_nep141_from_erc20(_erc20_token: &[u8]) -> Vec<u8> {
// TODO(#51): Already implemented
Vec::new()
Expand All @@ -43,16 +49,16 @@ impl Precompile for ExitToNear {
Ok(costs::EXIT_TO_NEAR_GAS)
}

#[cfg(not(feature = "contract"))]
fn run(input: &[u8], target_gas: u64, context: &Context) -> PrecompileResult {
#[cfg(not(feature = "exit-precompiles"))]
fn run(input: &[u8], target_gas: u64, _context: &Context) -> PrecompileResult {
if Self::required_gas(input)? > target_gas {
return Err(ExitError::OutOfGas);
}

Ok((ExitSucceed::Returned, Vec::new(), 0))
}

#[cfg(feature = "contract")]
#[cfg(feature = "exit-precompiles")]
fn run(input: &[u8], target_gas: u64, context: &Context) -> PrecompileResult {
if Self::required_gas(input)? > target_gas {
return Err(ExitError::OutOfGas);
Expand Down Expand Up @@ -142,16 +148,16 @@ impl Precompile for ExitToEthereum {
Ok(costs::EXIT_TO_ETHEREUM_GAS)
}

#[cfg(not(feature = "contract"))]
fn run(input: &[u8], target_gas: u64, context: &Context) -> PrecompileResult {
#[cfg(not(feature = "exit-precompiles"))]
fn run(input: &[u8], target_gas: u64, _context: &Context) -> PrecompileResult {
if Self::required_gas(input)? > target_gas {
return Err(ExitError::OutOfGas);
}

Ok((ExitSucceed::Returned, Vec::new(), 0))
}

#[cfg(feature = "contract")]
#[cfg(feature = "exit-precompiles")]
fn run(input: &[u8], target_gas: u64, context: &Context) -> PrecompileResult {
if Self::required_gas(input)? > target_gas {
return Err(ExitError::OutOfGas);
Expand Down