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
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
CARGO = cargo
NEAR = near
FEATURES = contract,log,exit-precompiles
FEATURES = mainnet

ifeq ($(evm-bully),yes)
FEATURES := $(FEATURES),evm_bully
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
Expand All @@ -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=$<
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
10 changes: 0 additions & 10 deletions src/precompiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ mod bn128;
mod hash;
mod identity;
mod modexp;
#[cfg(feature = "exit-precompiles")]
mod native;
mod secp256k1;
use evm::{Context, ExitError};
Expand All @@ -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;
Expand Down Expand Up @@ -145,11 +143,9 @@ pub fn homestead_precompiles(
RIPEMD160::<AuroraStackState>::ADDRESS => Some(RIPEMD160::<AuroraStackState>::run(
input, target_gas, context, state, is_static,
)),
#[cfg(feature = "exit-precompiles")]
ExitToNear::<AuroraStackState>::ADDRESS => Some(ExitToNear::<AuroraStackState>::run(
input, target_gas, context, state, is_static,
)),
#[cfg(feature = "exit-precompiles")]
ExitToEthereum::<AuroraStackState>::ADDRESS => Some(
ExitToEthereum::<AuroraStackState>::run(input, target_gas, context, state, is_static),
),
Expand Down Expand Up @@ -199,11 +195,9 @@ pub fn byzantium_precompiles(
bn128::addresses::PAIR => Some(BN128Pair::<Byzantium, _>::run(
input, target_gas, context, state, is_static,
)),
#[cfg(feature = "exit-precompiles")]
ExitToNear::<AuroraStackState>::ADDRESS => Some(ExitToNear::<AuroraStackState>::run(
input, target_gas, context, state, is_static,
)),
#[cfg(feature = "exit-precompiles")]
ExitToEthereum::<AuroraStackState>::ADDRESS => Some(
ExitToEthereum::<AuroraStackState>::run(input, target_gas, context, state, is_static),
),
Expand Down Expand Up @@ -256,11 +250,9 @@ pub fn istanbul_precompiles(
Blake2F::<AuroraStackState>::ADDRESS => Some(Blake2F::<AuroraStackState>::run(
input, target_gas, context, state, is_static,
)),
#[cfg(feature = "exit-precompiles")]
ExitToNear::<AuroraStackState>::ADDRESS => Some(ExitToNear::<AuroraStackState>::run(
input, target_gas, context, state, is_static,
)),
#[cfg(feature = "exit-precompiles")]
ExitToEthereum::<AuroraStackState>::ADDRESS => Some(
ExitToEthereum::<AuroraStackState>::run(input, target_gas, context, state, is_static),
),
Expand Down Expand Up @@ -313,11 +305,9 @@ pub fn berlin_precompiles(
Blake2F::<AuroraStackState>::ADDRESS => Some(Blake2F::<AuroraStackState>::run(
input, target_gas, context, state, is_static,
)),
#[cfg(feature = "exit-precompiles")]
ExitToNear::<AuroraStackState>::ADDRESS => Some(ExitToNear::<AuroraStackState>::run(
input, target_gas, context, state, is_static,
)),
#[cfg(feature = "exit-precompiles")]
ExitToEthereum::<AuroraStackState>::ADDRESS => Some(
ExitToEthereum::<AuroraStackState>::run(input, target_gas, context, state, is_static),
),
Expand Down
21 changes: 13 additions & 8 deletions src/precompiles/native.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -40,6 +42,7 @@ impl<S> ExitToNear<S> {
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())
Expand All @@ -53,27 +56,28 @@ impl<S: AuroraState> Precompile<S> for ExitToNear<S> {
Ok(costs::EXIT_TO_NEAR_GAS)
}

#[cfg(not(feature = "exit-precompiles"))]
#[cfg(not(feature = "contract"))]
fn run(
input: &[u8],
target_gas: u64,
context: &Context,
_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,
Expand Down Expand Up @@ -196,27 +200,28 @@ impl<S: AuroraState> Precompile<S> for ExitToEthereum<S> {
Ok(costs::EXIT_TO_ETHEREUM_GAS)
}

#[cfg(not(feature = "exit-precompiles"))]
#[cfg(not(feature = "contract"))]
fn run(
input: &[u8],
target_gas: u64,
context: &Context,
_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,
Expand Down Expand Up @@ -326,7 +331,7 @@ impl<S: AuroraState> Precompile<S> for ExitToEthereum<S> {
}
}

#[cfg(test)]
#[cfg(all(feature = "contract", test))]
mod tests {
use super::{ExitToEthereum, ExitToNear};
use crate::types::near_account_to_evm_address;
Expand Down