diff --git a/Cargo.toml b/Cargo.toml index 11cca8ea8..58bbeb271 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -78,8 +78,7 @@ 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"] -engine = [] -contract = ["engine"] +contract = [] evm_bully = [] log = [] meta-call = ["contract"] diff --git a/etc/state-migration-test/Cargo.toml b/etc/state-migration-test/Cargo.toml index 7a2bc3122..de0f11f77 100644 --- a/etc/state-migration-test/Cargo.toml +++ b/etc/state-migration-test/Cargo.toml @@ -38,4 +38,4 @@ rpath = false [dependencies] borsh = { version = "0.8.2", default-features = false } -aurora-engine = { path = "../../", default-features = false, features = ["sha2", "engine"] } +aurora-engine = { path = "../../", default-features = false, features = ["sha2"] } diff --git a/src/deposit_event.rs b/src/deposit_event.rs index 0cfbf5887..39c80ecf6 100644 --- a/src/deposit_event.rs +++ b/src/deposit_event.rs @@ -46,7 +46,6 @@ impl DepositedEvent { } /// Parses raw Ethereum logs proof's entry data - #[cfg(feature = "engine")] pub fn from_log_entry_data(data: &[u8]) -> Self { let event = EthEvent::fetch_log_entry_data(DEPOSITED_EVENT, Self::event_params(), data); let sender = event.log.params[0].value.clone().into_address().unwrap().0; diff --git a/src/fungible_token.rs b/src/fungible_token.rs index 4b18fd471..c131cf2d2 100644 --- a/src/fungible_token.rs +++ b/src/fungible_token.rs @@ -2,7 +2,6 @@ use crate::prelude::format; use crate::types::*; use borsh::{BorshDeserialize, BorshSerialize}; -#[cfg(feature = "engine")] use { crate::connector, crate::engine, @@ -12,9 +11,7 @@ use { crate::storage, }; -#[cfg(feature = "engine")] const GAS_FOR_RESOLVE_TRANSFER: Gas = 5_000_000_000_000; -#[cfg(feature = "engine")] const GAS_FOR_FT_ON_TRANSFER: Gas = 10_000_000_000_000; #[derive(Debug, Default, BorshDeserialize, BorshSerialize)] @@ -29,7 +26,6 @@ pub struct FungibleToken { pub account_storage_usage: StorageUsage, } -#[cfg(feature = "engine")] impl FungibleToken { pub fn new() -> Self { Self::default() @@ -382,7 +378,6 @@ impl FungibleToken { } else { let min_balance = self.storage_balance_bounds().min; if amount < min_balance { - #[cfg(feature = "log")] sdk::panic_utf8(b"ERR_ATTACHED_DEPOSIT_NOT_ENOUGH"); } diff --git a/src/json.rs b/src/json.rs index f6074f81b..f29068af0 100644 --- a/src/json.rs +++ b/src/json.rs @@ -1,6 +1,5 @@ use super::prelude::*; -use alloc::collections::BTreeMap; use core::convert::From; use rjson::{Array, Null, Object, Value}; diff --git a/src/lib.rs b/src/lib.rs index 8ae87177a..0aae10d4f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,6 @@ extern crate core; use crate::parameters::PromiseCreateArgs; -#[cfg(feature = "engine")] mod map; #[cfg(feature = "meta-call")] pub mod meta_parsing; @@ -20,27 +19,20 @@ pub mod storage; pub mod transaction; pub mod types; -#[cfg(feature = "engine")] mod admin_controlled; -#[cfg(feature = "engine")] +#[cfg_attr(not(feature = "contract"), allow(dead_code))] mod connector; mod deposit_event; -#[cfg(feature = "engine")] pub mod engine; -#[cfg(any(feature = "engine", test))] mod fungible_token; -#[cfg(feature = "engine")] mod json; mod log_entry; mod precompiles; -#[cfg(feature = "engine")] mod prover; -#[cfg(feature = "engine")] pub mod sdk; #[cfg(test)] mod benches; -#[cfg(feature = "engine")] mod state; #[cfg(test)] mod test_utils; diff --git a/src/parameters.rs b/src/parameters.rs index f70ab06ea..69bd6e087 100644 --- a/src/parameters.rs +++ b/src/parameters.rs @@ -2,7 +2,6 @@ use borsh::{BorshDeserialize, BorshSerialize}; use crate::prelude::{String, Vec}; use crate::types::{AccountId, Balance, RawAddress, RawH256, RawU256}; -#[cfg(feature = "engine")] use crate::{ admin_controlled::PausedMask, json, @@ -142,7 +141,6 @@ pub struct NEP141FtOnTransferArgs { pub msg: String, } -#[cfg(feature = "engine")] impl TryFrom for NEP141FtOnTransferArgs { type Error = json::JsonError; @@ -155,7 +153,6 @@ impl TryFrom for NEP141FtOnTransferArgs { } } -#[cfg(feature = "engine")] impl TryFrom for String { type Error = json::ParseError; @@ -183,7 +180,6 @@ pub struct PromiseCreateArgs { pub attached_gas: u64, } /// Eth-connector deposit arguments -#[cfg(feature = "engine")] #[derive(BorshSerialize, BorshDeserialize)] pub struct DepositCallArgs { /// Proof data @@ -193,7 +189,6 @@ pub struct DepositCallArgs { } /// Eth-connector isUsedProof arguments -#[cfg(feature = "engine")] #[derive(BorshSerialize, BorshDeserialize)] pub struct IsUsedProofCallArgs { /// Proof data @@ -201,7 +196,6 @@ pub struct IsUsedProofCallArgs { } /// withdraw result for eth-connector -#[cfg(feature = "engine")] #[derive(BorshSerialize)] pub struct WithdrawResult { pub amount: Balance, @@ -210,7 +204,6 @@ pub struct WithdrawResult { } /// ft_resolve_transfer eth-connector call args -#[cfg(feature = "engine")] #[derive(BorshSerialize)] pub struct FtResolveTransfer { pub receiver_id: AccountId, @@ -219,18 +212,15 @@ pub struct FtResolveTransfer { } /// Fungible token storage balance -#[cfg(feature = "engine")] #[derive(Default)] pub struct StorageBalance { pub total: Balance, pub available: Balance, } -#[cfg(feature = "engine")] impl StorageBalance { pub fn to_json_bytes(&self) -> Vec { - use alloc::format; - format!( + crate::prelude::format!( "{{\"total\": \"{}\", \"available\": \"{}\",}}", self.total.to_string(), self.available.to_string() @@ -241,7 +231,6 @@ impl StorageBalance { } /// resolve_transfer eth-connector call args -#[cfg(feature = "engine")] #[derive(BorshSerialize, BorshDeserialize)] pub struct ResolveTransferCallArgs { pub sender_id: AccountId, @@ -250,7 +239,6 @@ pub struct ResolveTransferCallArgs { } /// Finish deposit NEAR eth-connector call args -#[cfg(feature = "engine")] #[derive(BorshSerialize, BorshDeserialize)] pub struct FinishDepositCallArgs { pub new_owner_id: AccountId, @@ -262,7 +250,6 @@ pub struct FinishDepositCallArgs { } /// Deposit ETH args -#[cfg(feature = "engine")] #[derive(Default, BorshDeserialize, BorshSerialize, Clone)] pub struct DepositEthCallArgs { pub proof: Proof, @@ -270,7 +257,6 @@ pub struct DepositEthCallArgs { } /// Finish deposit NEAR eth-connector call args -#[cfg(feature = "engine")] #[derive(BorshSerialize, BorshDeserialize)] pub struct FinishDepositEthCallArgs { pub new_owner_id: EthAddress, @@ -291,7 +277,6 @@ pub struct InitCallArgs { pub type SetContractDataCallArgs = InitCallArgs; /// transfer eth-connector call args -#[cfg(feature = "engine")] #[derive(BorshSerialize, BorshDeserialize)] pub struct TransferCallCallArgs { pub receiver_id: AccountId, @@ -300,7 +285,6 @@ pub struct TransferCallCallArgs { pub msg: String, } -#[cfg(feature = "engine")] impl From for TransferCallCallArgs { fn from(v: json::JsonValue) -> Self { Self { @@ -313,13 +297,11 @@ impl From for TransferCallCallArgs { } /// storage_balance_of eth-connector call args -#[cfg(feature = "engine")] #[derive(BorshSerialize, BorshDeserialize)] pub struct StorageBalanceOfCallArgs { pub account_id: AccountId, } -#[cfg(feature = "engine")] impl From for StorageBalanceOfCallArgs { fn from(v: json::JsonValue) -> Self { Self { @@ -329,14 +311,12 @@ impl From for StorageBalanceOfCallArgs { } /// storage_deposit eth-connector call args -#[cfg(feature = "engine")] #[derive(BorshSerialize, BorshDeserialize)] pub struct StorageDepositCallArgs { pub account_id: Option, pub registration_only: Option, } -#[cfg(feature = "engine")] impl From for StorageDepositCallArgs { fn from(v: json::JsonValue) -> Self { Self { @@ -347,13 +327,11 @@ impl From for StorageDepositCallArgs { } /// storage_withdraw eth-connector call args -#[cfg(feature = "engine")] #[derive(BorshSerialize, BorshDeserialize)] pub struct StorageWithdrawCallArgs { pub amount: Option, } -#[cfg(feature = "engine")] impl From for StorageWithdrawCallArgs { fn from(v: json::JsonValue) -> Self { Self { @@ -363,7 +341,6 @@ impl From for StorageWithdrawCallArgs { } /// transfer args for json invocation -#[cfg(feature = "engine")] #[derive(BorshSerialize, BorshDeserialize)] pub struct TransferCallArgs { pub receiver_id: AccountId, @@ -371,7 +348,6 @@ pub struct TransferCallArgs { pub memo: Option, } -#[cfg(feature = "engine")] impl From for TransferCallArgs { fn from(v: json::JsonValue) -> Self { Self { @@ -383,7 +359,6 @@ impl From for TransferCallArgs { } /// withdraw NEAR eth-connector call args -#[cfg(feature = "engine")] #[derive(BorshSerialize, BorshDeserialize)] pub struct WithdrawCallArgs { pub recipient_address: EthAddress, @@ -391,19 +366,16 @@ pub struct WithdrawCallArgs { } /// balance_of args for json invocation -#[cfg(feature = "engine")] #[derive(BorshSerialize, BorshDeserialize)] pub struct BalanceOfCallArgs { pub account_id: AccountId, } -#[cfg(feature = "engine")] #[derive(BorshSerialize, BorshDeserialize)] pub struct BalanceOfEthCallArgs { pub address: EthAddress, } -#[cfg(feature = "engine")] impl From for BalanceOfCallArgs { fn from(v: json::JsonValue) -> Self { Self { @@ -412,24 +384,20 @@ impl From for BalanceOfCallArgs { } } -#[cfg(feature = "engine")] #[derive(BorshSerialize, BorshDeserialize)] pub struct RegisterRelayerCallArgs { pub address: EthAddress, } -#[cfg(feature = "engine")] #[derive(BorshSerialize, BorshDeserialize)] pub struct PauseEthConnectorCallArgs { pub paused_mask: PausedMask, } -#[cfg(feature = "engine")] pub trait ExpectUtf8 { fn expect_utf8(self, message: &[u8]) -> T; } -#[cfg(feature = "engine")] impl ExpectUtf8 for Option { fn expect_utf8(self, message: &[u8]) -> T { match self { @@ -439,7 +407,6 @@ impl ExpectUtf8 for Option { } } -#[cfg(feature = "engine")] impl ExpectUtf8 for core::result::Result { fn expect_utf8(self, message: &[u8]) -> T { match self { @@ -449,7 +416,6 @@ impl ExpectUtf8 for core::result::Result { } } -#[cfg(feature = "engine")] impl From for ResolveTransferCallArgs { fn from(v: json::JsonValue) -> Self { Self { diff --git a/src/precompiles/blake2.rs b/src/precompiles/blake2.rs index 6511cc80d..f78b82fa2 100644 --- a/src/precompiles/blake2.rs +++ b/src/precompiles/blake2.rs @@ -18,7 +18,6 @@ mod consts { pub(super) struct Blake2F(PhantomData); impl Blake2F { - #[cfg_attr(not(feature = "engine"), allow(dead_code))] pub(super) const ADDRESS: [u8; 20] = super::make_address(0, 9); } diff --git a/src/precompiles/bn128.rs b/src/precompiles/bn128.rs index 3d352f127..73b46f57e 100644 --- a/src/precompiles/bn128.rs +++ b/src/precompiles/bn128.rs @@ -48,11 +48,8 @@ mod consts { pub(super) mod addresses { use crate::precompiles; - #[cfg_attr(not(feature = "engine"), allow(dead_code))] pub const ADD: [u8; 20] = precompiles::make_address(0, 6); - #[cfg_attr(not(feature = "engine"), allow(dead_code))] pub const MUL: [u8; 20] = precompiles::make_address(0, 7); - #[cfg_attr(not(feature = "engine"), allow(dead_code))] pub const PAIR: [u8; 20] = precompiles::make_address(0, 8); } diff --git a/src/precompiles/hash.rs b/src/precompiles/hash.rs index c0f437545..51ae03632 100644 --- a/src/precompiles/hash.rs +++ b/src/precompiles/hash.rs @@ -24,7 +24,6 @@ mod consts { pub struct SHA256(PhantomData); impl SHA256 { - #[cfg_attr(not(feature = "engine"), allow(dead_code))] pub(super) const ADDRESS: [u8; 20] = super::make_address(0, 2); } @@ -90,7 +89,6 @@ impl Precompile for SHA256 { pub struct RIPEMD160(PhantomData); impl RIPEMD160 { - #[cfg_attr(not(feature = "engine"), allow(dead_code))] pub(super) const ADDRESS: [u8; 20] = super::make_address(0, 3); } diff --git a/src/precompiles/identity.rs b/src/precompiles/identity.rs index 36515505b..4053fe652 100644 --- a/src/precompiles/identity.rs +++ b/src/precompiles/identity.rs @@ -21,7 +21,6 @@ mod consts { pub struct Identity(PhantomData); impl Identity { - #[cfg_attr(not(feature = "engine"), allow(dead_code))] pub(super) const ADDRESS: [u8; 20] = super::make_address(0, 4); } diff --git a/src/precompiles/mod.rs b/src/precompiles/mod.rs index 4660303aa..de50d069c 100644 --- a/src/precompiles/mod.rs +++ b/src/precompiles/mod.rs @@ -3,6 +3,7 @@ mod bn128; mod hash; mod identity; mod modexp; +#[cfg_attr(not(feature = "contract"), allow(dead_code))] mod native; mod secp256k1; use evm::{Context, ExitError}; @@ -10,7 +11,6 @@ use evm::{Context, ExitError}; pub(crate) use crate::precompiles::secp256k1::ecrecover; use crate::prelude::Vec; use crate::AuroraState; -#[cfg(feature = "engine")] use crate::{ precompiles::blake2::Blake2F, precompiles::bn128::{BN128Add, BN128Mul, BN128Pair}, @@ -66,7 +66,6 @@ impl From for evm::executor::PrecompileOutput { /// A precompile operation result. type PrecompileResult = Result; -#[cfg(feature = "engine")] type EvmPrecompileResult = Result; /// A precompiled function for use in the EVM. @@ -211,7 +210,6 @@ pub fn byzantium_precompiles( } /// Matches the address given to Istanbul precompiles. -#[cfg(feature = "engine")] #[allow(dead_code)] pub fn istanbul_precompiles( address: Address, @@ -323,7 +321,6 @@ pub fn berlin_precompiles( /// const fn for making an address by concatenating the bytes from two given numbers, /// Note that 32 + 128 = 160 = 20 bytes (the length of an address). This function is used /// as a convenience for specifying the addresses of the various precompiles. -#[cfg_attr(not(feature = "engine"), allow(dead_code))] const fn make_address(x: u32, y: u128) -> [u8; 20] { let x_bytes = x.to_be_bytes(); let y_bytes = y.to_be_bytes(); diff --git a/src/precompiles/modexp.rs b/src/precompiles/modexp.rs index 26410f054..c1be8dbc8 100644 --- a/src/precompiles/modexp.rs +++ b/src/precompiles/modexp.rs @@ -6,7 +6,6 @@ use crate::AuroraState; use evm::{Context, ExitError}; use num::{BigUint, Integer}; -#[cfg_attr(not(feature = "engine"), allow(dead_code))] pub(super) const ADDRESS: [u8; 20] = super::make_address(0, 5); pub(super) struct ModExp(PhantomData, PhantomData); diff --git a/src/precompiles/native.rs b/src/precompiles/native.rs index 9b3382eae..1c85c6948 100644 --- a/src/precompiles/native.rs +++ b/src/precompiles/native.rs @@ -4,7 +4,7 @@ use crate::prelude::PhantomData; #[cfg(not(feature = "contract"))] use crate::prelude::Vec; use crate::AuroraState; -#[cfg(feature = "engine")] +#[cfg(feature = "contract")] use { crate::parameters::PromiseCreateArgs, crate::parameters::WithdrawCallArgs, @@ -16,7 +16,6 @@ use { use super::{Precompile, PrecompileResult}; -#[cfg_attr(not(feature = "engine"), allow(dead_code))] const ERR_TARGET_TOKEN_NOT_FOUND: &str = "Target token not found"; use crate::precompiles::PrecompileOutput; @@ -31,11 +30,9 @@ mod costs { pub(super) const EXIT_TO_ETHEREUM_GAS: Gas = 0; // TODO(#51): Determine the correct amount of gas - #[cfg_attr(not(feature = "engine"), allow(dead_code))] pub(super) const FT_TRANSFER_GAS: Gas = 100_000_000_000_000; // TODO(#51): Determine the correct amount of gas - #[cfg_attr(not(feature = "engine"), allow(dead_code))] pub(super) const WITHDRAWAL_GAS: Gas = 100_000_000_000_000; } @@ -46,7 +43,6 @@ impl ExitToNear { /// /// Address: `0xe9217bc70b7ed1f598ddd3199e80b093fa71124f` /// This address is computed as: `&keccak("exitToNear")[12..]` - #[cfg_attr(not(feature = "engine"), allow(dead_code))] pub(super) const ADDRESS: [u8; 20] = super::make_address(0xe9217bc7, 0x0b7ed1f598ddd3199e80b093fa71124f); } @@ -194,7 +190,6 @@ impl ExitToEthereum { /// /// Address: `0xb0bd02f6a392af548bdf1cfaee5dfa0eefcc8eab` /// This address is computed as: `&keccak("exitToEthereum")[12..]` - #[cfg_attr(not(feature = "engine"), allow(dead_code))] pub(super) const ADDRESS: [u8; 20] = super::make_address(0xb0bd02f6, 0xa392af548bdf1cfaee5dfa0eefcc8eab); } diff --git a/src/precompiles/secp256k1.rs b/src/precompiles/secp256k1.rs index 15b764883..f82f545ae 100644 --- a/src/precompiles/secp256k1.rs +++ b/src/precompiles/secp256k1.rs @@ -44,7 +44,6 @@ pub fn ecrecover(hash: H256, signature: &[u8]) -> Result { pub(super) struct ECRecover(PhantomData); impl ECRecover { - #[cfg_attr(not(feature = "engine"), allow(dead_code))] pub(super) const ADDRESS: [u8; 20] = super::make_address(0, 1); } diff --git a/src/prelude.rs b/src/prelude.rs index d76444da4..fb55e90be 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -4,6 +4,7 @@ pub use alloc::{ borrow::{Cow, Cow::*}, boxed::Box, collections::BTreeMap as HashMap, + collections::BTreeMap, fmt, format, str, string::String, string::ToString, diff --git a/src/sdk.rs b/src/sdk.rs index 7c3b80168..8a78c3124 100644 --- a/src/sdk.rs +++ b/src/sdk.rs @@ -173,11 +173,13 @@ pub fn read_input() -> Vec { } } +#[cfg_attr(not(feature = "contract"), allow(dead_code))] pub(crate) fn read_input_borsh() -> Result { let bytes = read_input(); T::try_from_slice(&bytes).map_err(|_| ArgParseErr) } +#[cfg_attr(not(feature = "contract"), allow(dead_code))] pub(crate) fn read_input_arr20() -> Result<[u8; 20], IncorrectInputLength> { unsafe { exports::input(INPUT_REGISTER_ID); diff --git a/src/test_utils/exit_precompile.rs b/src/test_utils/exit_precompile.rs index 3892cefef..6149529d4 100644 --- a/src/test_utils/exit_precompile.rs +++ b/src/test_utils/exit_precompile.rs @@ -2,8 +2,6 @@ use crate::parameters::SubmitResult; use crate::prelude::{Address, U256}; use crate::test_utils::{solidity, AuroraRunner, Signer}; use crate::transaction::EthTransaction; -#[cfg(feature = "engine")] -use {crate::parameters::FunctionCallArgs, borsh::BorshSerialize, std::convert::TryInto}; pub(crate) struct TesterConstructor(pub solidity::ContractConstructor); diff --git a/src/tests/contract_call.rs b/src/tests/contract_call.rs index 02e8da91f..531da120f 100644 --- a/src/tests/contract_call.rs +++ b/src/tests/contract_call.rs @@ -2,15 +2,6 @@ use crate::test_utils::{origin, AuroraRunner, Signer}; use crate::test_utils; use crate::test_utils::exit_precompile::{Tester, TesterConstructor}; -#[cfg(feature = "engine")] -use { - crate::prelude::U256, - crate::test_utils::solidity, - crate::transaction::EthTransaction, - ethabi::Address, - near_crypto::SecretKey, - std::path::{Path, PathBuf}, -}; fn setup_test() -> (AuroraRunner, Signer, [u8; 20], Tester) { let mut runner = AuroraRunner::new(); diff --git a/src/types.rs b/src/types.rs index bf165650b..d8951756c 100644 --- a/src/types.rs +++ b/src/types.rs @@ -12,10 +12,8 @@ use ethabi::{ParamType, Token}; #[cfg(not(feature = "contract"))] use sha3::{Digest, Keccak256}; -#[cfg(feature = "engine")] use crate::engine::EngineResult; use crate::log_entry::LogEntry; -#[cfg(feature = "engine")] use crate::sdk; #[cfg(not(feature = "contract"))] @@ -207,7 +205,6 @@ pub struct StorageBalanceBounds { } /// promise results structure -#[cfg(feature = "engine")] pub enum PromiseResult { NotReady, Successful(Vec), @@ -215,7 +212,6 @@ pub enum PromiseResult { } /// ft_resolve_transfer result of eth-connector -#[cfg(feature = "engine")] pub struct FtResolveTransferResult { pub amount: Balance, pub refund_amount: Balance, @@ -302,7 +298,6 @@ impl Stack { self.stack } } -#[cfg(feature = "engine")] pub fn str_from_slice(inp: &[u8]) -> &str { str::from_utf8(inp).unwrap() } @@ -332,12 +327,10 @@ impl ExpectUtf8 for core::result::Result { } } -#[cfg(feature = "engine")] pub trait SdkExpect { fn sdk_expect(self, msg: &str) -> T; } -#[cfg(feature = "engine")] impl SdkExpect for Option { fn sdk_expect(self, msg: &str) -> T { match self { @@ -347,7 +340,6 @@ impl SdkExpect for Option { } } -#[cfg(feature = "engine")] impl SdkExpect for core::result::Result { fn sdk_expect(self, msg: &str) -> T { match self { @@ -357,12 +349,10 @@ impl SdkExpect for core::result::Result { } } -#[cfg(feature = "engine")] pub trait SdkUnwrap { fn sdk_unwrap(self) -> T; } -#[cfg(feature = "engine")] impl SdkUnwrap for Option { fn sdk_unwrap(self) -> T { match self { @@ -372,7 +362,6 @@ impl SdkUnwrap for Option { } } -#[cfg(feature = "engine")] impl> SdkUnwrap for core::result::Result { fn sdk_unwrap(self) -> T { match self { @@ -382,12 +371,10 @@ impl> SdkUnwrap for core::result::Result { } } -#[cfg(feature = "engine")] pub(crate) trait SdkProcess { fn sdk_process(self); } -#[cfg(feature = "engine")] impl> SdkProcess for EngineResult { fn sdk_process(self) { match self {