diff --git a/Cargo.toml b/Cargo.toml index bff6237fb..11cca8ea8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -78,11 +78,12 @@ base64 = "0.13.0" [features] default = ["sha2", "std"] std = ["borsh/std", "evm/std", "primitive-types/std", "rlp/std", "sha3/std", "ethabi/std", "logos/std", "bn/std"] -testnet = [] engine = [] contract = ["engine"] evm_bully = [] log = [] -exit-precompiles = ["contract"] meta-call = ["contract"] integration-test = ["log"] +mainnet = ["contract", "log"] +testnet = ["contract", "log"] +betanet = ["contract", "log", "meta-call"] diff --git a/Makefile b/Makefile index c8c1cd002..37dca0da8 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CARGO = cargo NEAR = near -FEATURES = contract,log,exit-precompiles +FEATURES = mainnet ifeq ($(evm-bully),yes) FEATURES := $(FEATURES),evm_bully @@ -8,6 +8,15 @@ endif all: release +mainnet: FEATURES=mainnet +mainnet: release + +testnet: FEATURES=testnet +testnet: release + +betanet: FEATURES=betanet +betanet: release + release: release.wasm release.wasm: target/wasm32-unknown-unknown/release/aurora_engine.wasm @@ -32,11 +41,11 @@ target/wasm32-unknown-unknown/debug/aurora_engine.wasm: Cargo.toml Cargo.lock $( $(CARGO) build --target wasm32-unknown-unknown --no-default-features --features=$(FEATURES) -Z avoid-dev-deps test-build: etc/eth-contracts/artifacts/contracts/test/StateTest.sol/StateTest.json etc/eth-contracts/res/EvmErc20.bin - RUSTFLAGS='-C link-arg=-s' $(CARGO) build --target wasm32-unknown-unknown --release --no-default-features --features=contract,integration-test,exit-precompiles,meta-call -Z avoid-dev-deps + RUSTFLAGS='-C link-arg=-s' $(CARGO) build --target wasm32-unknown-unknown --release --no-default-features --features=contract,integration-test,meta-call -Z avoid-dev-deps ln -sf target/wasm32-unknown-unknown/release/aurora_engine.wasm release.wasm ls -l target/wasm32-unknown-unknown/release/aurora_engine.wasm -.PHONY: all release debug eth-contracts +.PHONY: all release debug eth-contracts mainnet testnet betanet deploy: release.wasm $(NEAR) deploy --account-id=$(or $(NEAR_EVM_ACCOUNT),aurora.test.near) --wasm-file=$< diff --git a/README.md b/README.md index 7026afa19..9754482f7 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,9 @@ rustup target add wasm32-unknown-unknown --toolchain nightly-2021-03-25 ### Building the EVM binary ```sh +make -B mainnet # produces Mainnet build +make -B testnet # produces Testnet build +make -B betanet # produces Betanet build make release # produces release.wasm (300+ KiB) make debug # produces debug.wasm (1+ MiB), which includes symbols ``` diff --git a/src/precompiles/mod.rs b/src/precompiles/mod.rs index a28f31959..cac5e7bab 100644 --- a/src/precompiles/mod.rs +++ b/src/precompiles/mod.rs @@ -3,7 +3,6 @@ mod bn128; mod hash; mod identity; mod modexp; -#[cfg(feature = "exit-precompiles")] mod native; mod secp256k1; use evm::{Context, ExitError}; @@ -13,7 +12,6 @@ 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; @@ -145,11 +143,9 @@ pub fn homestead_precompiles( RIPEMD160::::ADDRESS => Some(RIPEMD160::::run( input, target_gas, context, state, is_static, )), - #[cfg(feature = "exit-precompiles")] ExitToNear::::ADDRESS => Some(ExitToNear::::run( input, target_gas, context, state, is_static, )), - #[cfg(feature = "exit-precompiles")] ExitToEthereum::::ADDRESS => Some( ExitToEthereum::::run(input, target_gas, context, state, is_static), ), @@ -199,11 +195,9 @@ pub fn byzantium_precompiles( bn128::addresses::PAIR => Some(BN128Pair::::run( input, target_gas, context, state, is_static, )), - #[cfg(feature = "exit-precompiles")] ExitToNear::::ADDRESS => Some(ExitToNear::::run( input, target_gas, context, state, is_static, )), - #[cfg(feature = "exit-precompiles")] ExitToEthereum::::ADDRESS => Some( ExitToEthereum::::run(input, target_gas, context, state, is_static), ), @@ -256,11 +250,9 @@ pub fn istanbul_precompiles( Blake2F::::ADDRESS => Some(Blake2F::::run( input, target_gas, context, state, is_static, )), - #[cfg(feature = "exit-precompiles")] ExitToNear::::ADDRESS => Some(ExitToNear::::run( input, target_gas, context, state, is_static, )), - #[cfg(feature = "exit-precompiles")] ExitToEthereum::::ADDRESS => Some( ExitToEthereum::::run(input, target_gas, context, state, is_static), ), @@ -313,11 +305,9 @@ pub fn berlin_precompiles( Blake2F::::ADDRESS => Some(Blake2F::::run( input, target_gas, context, state, is_static, )), - #[cfg(feature = "exit-precompiles")] ExitToNear::::ADDRESS => Some(ExitToNear::::run( input, target_gas, context, state, is_static, )), - #[cfg(feature = "exit-precompiles")] ExitToEthereum::::ADDRESS => Some( ExitToEthereum::::run(input, target_gas, context, state, is_static), ), diff --git a/src/precompiles/native.rs b/src/precompiles/native.rs index c5b0bfe54..74a9ae88b 100644 --- a/src/precompiles/native.rs +++ b/src/precompiles/native.rs @@ -1,6 +1,8 @@ use evm::{Context, ExitError}; -use crate::parameters::{PromiseCreateArgs, WithdrawCallArgs}; +use crate::parameters::PromiseCreateArgs; +#[cfg(feature = "engine")] +use crate::parameters::WithdrawCallArgs; use crate::prelude::{is_valid_account_id, Cow, PhantomData, String, ToString, TryInto, U256}; use crate::storage::{bytes_to_key, KeyPrefix}; use crate::types::AccountId; @@ -40,6 +42,7 @@ impl ExitToNear { super::make_address(0xe9217bc7, 0x0b7ed1f598ddd3199e80b093fa71124f); } +#[cfg(feature = "contract")] fn get_nep141_from_erc20(erc20_token: &[u8]) -> AccountId { AccountId::from_utf8( crate::sdk::read_storage(bytes_to_key(KeyPrefix::Erc20Nep141Map, erc20_token).as_slice()) @@ -53,7 +56,7 @@ impl Precompile for ExitToNear { Ok(costs::EXIT_TO_NEAR_GAS) } - #[cfg(not(feature = "exit-precompiles"))] + #[cfg(not(feature = "contract"))] fn run( input: &[u8], target_gas: u64, @@ -61,19 +64,20 @@ impl Precompile for ExitToNear { _state: &mut S, _is_static: bool, ) -> PrecompileResult { + use crate::prelude::Vec; + if Self::required_gas(input)? > target_gas { return Err(ExitError::OutOfGas); } Ok(PrecompileOutput { - exit_status: ExitSucceed::Returned, output: Vec::new(), cost: 0, logs: Vec::new(), }) } - #[cfg(feature = "exit-precompiles")] + #[cfg(feature = "contract")] fn run( input: &[u8], target_gas: u64, @@ -196,7 +200,7 @@ impl Precompile for ExitToEthereum { Ok(costs::EXIT_TO_ETHEREUM_GAS) } - #[cfg(not(feature = "exit-precompiles"))] + #[cfg(not(feature = "contract"))] fn run( input: &[u8], target_gas: u64, @@ -204,19 +208,20 @@ impl Precompile for ExitToEthereum { _state: &mut S, _is_static: bool, ) -> PrecompileResult { + use crate::prelude::Vec; + if Self::required_gas(input)? > target_gas { return Err(ExitError::OutOfGas); } Ok(PrecompileOutput { - exit_status: ExitSucceed::Returned, output: Vec::new(), cost: 0, logs: Vec::new(), }) } - #[cfg(feature = "exit-precompiles")] + #[cfg(feature = "contract")] fn run( input: &[u8], target_gas: u64, @@ -326,7 +331,7 @@ impl Precompile for ExitToEthereum { } } -#[cfg(test)] +#[cfg(all(feature = "contract", test))] mod tests { use super::{ExitToEthereum, ExitToNear}; use crate::types::near_account_to_evm_address;