diff --git a/Cargo.lock b/Cargo.lock index 83165b7e80..a3001293ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2216,9 +2216,9 @@ checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" [[package]] name = "evm" -version = "0.18.5" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5286da2277b078e7033491d62e674eeccd01d913a87bb60ec0cabbcf80ec62e9" +checksum = "ea0da85b407262b8caaffec7c5cb04c255538afdc1245de482d6216580d1f5e2" dependencies = [ "ethereum", "evm-core", @@ -2234,9 +2234,9 @@ dependencies = [ [[package]] name = "evm-core" -version = "0.18.3" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63c6c39300d7779427f461408d867426e202ea72ac7ece2455689ff0e4bddb6f" +checksum = "decb1397cbc7c7e3c3fee6564eed1f294612a0365c66c90ab92726d19d253a6e" dependencies = [ "parity-scale-codec", "primitive-types 0.7.3", @@ -2245,9 +2245,9 @@ dependencies = [ [[package]] name = "evm-gasometer" -version = "0.18.3" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "689c481648c3f45b64b1278077c04284ad535e068c9d6872153c7b74da7ccb03" +checksum = "da079283764366124ee955f0bd049e691c3d00895e88c79d9c3b744ff4cd6595" dependencies = [ "evm-core", "evm-runtime", @@ -2256,9 +2256,9 @@ dependencies = [ [[package]] name = "evm-runtime" -version = "0.18.3" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a148ad1b3e0af31aa03c6c3cc9df3a529e279dad8e29b4ef90dccad32601e4" +checksum = "95524d03dfcd11ca540fa3481d76dcc891db1abf704c2bec7a67fc51cdf95e67" dependencies = [ "evm-core", "primitive-types 0.7.3", diff --git a/bin/node/runtime/pangolin/src/lib.rs b/bin/node/runtime/pangolin/src/lib.rs index e1743da005..9d1d1776b0 100644 --- a/bin/node/runtime/pangolin/src/lib.rs +++ b/bin/node/runtime/pangolin/src/lib.rs @@ -1473,7 +1473,16 @@ impl_runtime_apis! { gas_limit: U256, gas_price: Option, nonce: Option, + estimate: bool, ) -> Result { + let config = if estimate { + let mut config = ::config().clone(); + config.estimate = true; + Some(config) + } else { + None + }; + ::Runner::call( from, to, @@ -1482,6 +1491,7 @@ impl_runtime_apis! { gas_limit.low_u32(), gas_price, nonce, + config.as_ref().unwrap_or(::config()), ).map_err(|err| err.into()) } @@ -1492,7 +1502,16 @@ impl_runtime_apis! { gas_limit: U256, gas_price: Option, nonce: Option, + estimate: bool, ) -> Result { + let config = if estimate { + let mut config = ::config().clone(); + config.estimate = true; + Some(config) + } else { + None + }; + ::Runner::create( from, data, @@ -1500,6 +1519,7 @@ impl_runtime_apis! { gas_limit.low_u32(), gas_price, nonce, + config.as_ref().unwrap_or(::config()), ).map_err(|err| err.into()) } diff --git a/client/dvm/rpc/src/eth.rs b/client/dvm/rpc/src/eth.rs index a66c095b92..41182eadf7 100644 --- a/client/dvm/rpc/src/eth.rs +++ b/client/dvm/rpc/src/eth.rs @@ -665,6 +665,7 @@ where gas_limit, gas_price, nonce, + false, ) .map_err(|err| internal_err(format!("runtime error: {:?}", err)))? .map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?; @@ -683,6 +684,7 @@ where gas_limit, gas_price, nonce, + false, ) .map_err(|err| internal_err(format!("runtime error: {:?}", err)))? .map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?; @@ -724,6 +726,7 @@ where gas_limit, gas_price, nonce, + true, ) .map_err(|err| internal_err(format!("runtime error: {:?}", err)))? .map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?; @@ -744,6 +747,7 @@ where gas_limit, gas_price, nonce, + true, ) .map_err(|err| internal_err(format!("runtime error: {:?}", err)))? .map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?; diff --git a/frame/dvm/Cargo.toml b/frame/dvm/Cargo.toml index 6e4929c5b9..1d69a642ea 100644 --- a/frame/dvm/Cargo.toml +++ b/frame/dvm/Cargo.toml @@ -14,7 +14,7 @@ version = "1.2.2" codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false } ethereum = { version = "0.5", default-features = false, features = ["with-codec"] } ethereum-types = { version = "0.9", default-features = false } -evm = { version = "0.18.0", features = ["with-codec"], default-features = false } +evm = { version = "0.19.0", features = ["with-codec"], default-features = false } libsecp256k1 = { version = "0.3", default-features = false } rlp = { version = "0.4", default-features = false } rustc-hex = { version = "2.1.0", default-features = false } diff --git a/frame/dvm/rpc/runtime-api/src/lib.rs b/frame/dvm/rpc/runtime-api/src/lib.rs index c99156fcba..bb70d99e29 100644 --- a/frame/dvm/rpc/runtime-api/src/lib.rs +++ b/frame/dvm/rpc/runtime-api/src/lib.rs @@ -71,6 +71,7 @@ sp_api::decl_runtime_apis! { gas_limit: U256, gas_price: Option, nonce: Option, + estimate: bool, ) -> Result; /// Returns a frame_ethereum::create response. fn create( @@ -80,6 +81,7 @@ sp_api::decl_runtime_apis! { gas_limit: U256, gas_price: Option, nonce: Option, + estimate: bool, ) -> Result; /// Return the current block. fn current_block() -> Option; diff --git a/frame/dvm/src/lib.rs b/frame/dvm/src/lib.rs index d0243a5496..ec5554b17d 100644 --- a/frame/dvm/src/lib.rs +++ b/frame/dvm/src/lib.rs @@ -146,6 +146,7 @@ decl_module! { Some(transaction.gas_price), Some(transaction.nonce), transaction.action, + None, )?; let (reason, status, used_gas) = match info { @@ -411,7 +412,7 @@ impl Module { CurrentReceipts::get() } - /// Execute an Ethereum transaction, ignoring transaction signatures. + /// Execute an Ethereum transaction pub fn execute( from: H160, input: Vec, @@ -420,6 +421,7 @@ impl Module { gas_price: Option, nonce: Option, action: TransactionAction, + config: Option, ) -> Result<(Option, CallOrCreateInfo), DispatchError> { match action { ethereum::TransactionAction::Call(target) => Ok(( @@ -433,6 +435,7 @@ impl Module { gas_limit.low_u32(), gas_price, nonce, + config.as_ref().unwrap_or(T::config()), ) .map_err(Into::into)?, ), @@ -447,6 +450,7 @@ impl Module { gas_limit.low_u32(), gas_price, nonce, + config.as_ref().unwrap_or(T::config()), ) .map_err(Into::into)?, ), diff --git a/frame/dvm/src/tests.rs b/frame/dvm/src/tests.rs index ebb3f0d68a..35ebb43be0 100644 --- a/frame/dvm/src/tests.rs +++ b/frame/dvm/src/tests.rs @@ -63,6 +63,7 @@ fn transaction_should_increment_nonce() { Some(t.gas_price), Some(t.nonce), t.action, + None, )); assert_eq!( ::AccountBasicMapping::account_basic(&alice.address).nonce, @@ -117,6 +118,7 @@ fn transaction_with_invalid_nonce_should_not_work() { Some(t.gas_price), Some(t.nonce), t.action, + None, )); transaction.nonce = U256::from(0); @@ -147,6 +149,7 @@ fn contract_constructor_should_get_executed() { Some(t.gas_price), Some(t.nonce), t.action, + None, )); assert_eq!( Evm::account_storages(erc20_address, alice_storage_address), @@ -214,6 +217,7 @@ fn contract_should_be_created_at_given_address() { Some(t.gas_price), Some(t.nonce), t.action, + None, )); assert_ne!(Evm::account_codes(erc20_address).len(), 0); }); @@ -236,6 +240,7 @@ fn transaction_should_generate_correct_gas_used() { Some(t.gas_price), Some(t.nonce), t.action, + None, ) .unwrap(); @@ -282,6 +287,7 @@ fn call_should_handle_errors() { Some(t.gas_price), Some(t.nonce), t.action, + None, )); let contract_address: Vec = @@ -298,6 +304,7 @@ fn call_should_handle_errors() { Some(U256::from(1)), Some(U256::from(1)), TransactionAction::Call(H160::from_slice(&contract_address)), + None, ) .unwrap(); match info { @@ -319,6 +326,7 @@ fn call_should_handle_errors() { Some(U256::from(1)), Some(U256::from(2)), TransactionAction::Call(H160::from_slice(&contract_address)), + None, ) .ok() .unwrap(); diff --git a/frame/evm/Cargo.toml b/frame/evm/Cargo.toml index 851ff48478..8e1715fb38 100644 --- a/frame/evm/Cargo.toml +++ b/frame/evm/Cargo.toml @@ -12,9 +12,9 @@ version = "1.2.2" [dependencies] # crates codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false } -evm = { version = "0.18", default-features = false, features = ["with-codec"] } -evm-gasometer = { version = "0.18", default-features = false } -evm-runtime = { version = "0.18", default-features = false } +evm = { version = "0.19.0", default-features = false, features = ["with-codec"] } +evm-gasometer = { version = "0.19.0", default-features = false } +evm-runtime = { version = "0.19.0", default-features = false } impl-trait-for-tuples = { version = "0.1" } primitive-types = { version = "0.7.0", default-features = false, features = ["rlp", "byteorder"] } ripemd160 = { version = "0.9", default-features = false } diff --git a/frame/evm/src/lib.rs b/frame/evm/src/lib.rs index 771aead077..8afa9a0576 100644 --- a/frame/evm/src/lib.rs +++ b/frame/evm/src/lib.rs @@ -357,20 +357,6 @@ decl_module! { fn deposit_event() = default; - /// Withdraw balance from EVM into currency/balances module. - #[weight = 0] - fn withdraw(origin, address: H160, value: BalanceOf) { - let destination = T::WithdrawOrigin::ensure_address_origin(&address, origin)?; - let address_account_id = T::AddressMapping::into_account_id(address); - - T::Currency::transfer( - &address_account_id, - &destination, - value, - ExistenceRequirement::AllowDeath - )?; - } - /// Issue an EVM call operation. This is similar to a message call transaction in Ethereum. #[weight = T::GasToWeight::gas_to_weight(*gas_limit)] fn call( @@ -393,6 +379,7 @@ decl_module! { gas_limit, Some(gas_price), nonce, + T::config(), )?; match info.exit_reason { @@ -431,6 +418,7 @@ decl_module! { gas_limit, Some(gas_price), nonce, + T::config(), )?; match info { CreateInfo { @@ -477,6 +465,7 @@ decl_module! { gas_limit, Some(gas_price), nonce, + T::config(), )?; match info { CreateInfo { diff --git a/frame/evm/src/runner/builtin.rs b/frame/evm/src/runner/builtin.rs index a1cf8522a5..2942dab834 100644 --- a/frame/evm/src/runner/builtin.rs +++ b/frame/evm/src/runner/builtin.rs @@ -57,6 +57,7 @@ impl RunnerT for Runner { gas_limit: u32, gas_price: Option, nonce: Option, + config: &evm::Config, ) -> Result { let gas_price = match gas_price { Some(gas_price) => { @@ -85,8 +86,6 @@ impl RunnerT for Runner { origin: source, }; - let config = T::config(); - let mut substate = Handler::::new_with_precompile( &vicinity, gas_limit as usize, @@ -125,6 +124,7 @@ impl RunnerT for Runner { gas_limit: u32, gas_price: Option, nonce: Option, + config: &evm::Config, ) -> Result { let gas_price = match gas_price { Some(gas_price) => { @@ -153,8 +153,6 @@ impl RunnerT for Runner { origin: source, }; - let config = T::config(); - let mut substate = Handler::::new_with_precompile( &vicinity, gas_limit as usize, @@ -203,6 +201,7 @@ impl RunnerT for Runner { gas_limit: u32, gas_price: Option, nonce: Option, + config: &evm::Config, ) -> Result { let gas_price = match gas_price { Some(gas_price) => { @@ -231,8 +230,6 @@ impl RunnerT for Runner { origin: source, }; - let config = T::config(); - let mut substate = Handler::::new_with_precompile( &vicinity, gas_limit as usize, diff --git a/frame/evm/src/runner/mod.rs b/frame/evm/src/runner/mod.rs index 64fa42a2fa..2018445b00 100644 --- a/frame/evm/src/runner/mod.rs +++ b/frame/evm/src/runner/mod.rs @@ -34,6 +34,7 @@ pub trait Runner { gas_limit: u32, gas_price: Option, nonce: Option, + config: &evm::Config, ) -> Result; fn create( @@ -43,6 +44,7 @@ pub trait Runner { gas_limit: u32, gas_price: Option, nonce: Option, + config: &evm::Config, ) -> Result; fn create2( @@ -53,5 +55,6 @@ pub trait Runner { gas_limit: u32, gas_price: Option, nonce: Option, + config: &evm::Config, ) -> Result; } diff --git a/frame/evm/src/runner/stack.rs b/frame/evm/src/runner/stack.rs index 6da6e58c81..a6c44b41ba 100644 --- a/frame/evm/src/runner/stack.rs +++ b/frame/evm/src/runner/stack.rs @@ -50,6 +50,7 @@ impl Runner { gas_limit: u32, gas_price: Option, nonce: Option, + config: &evm::Config, f: F, ) -> Result, Error> where @@ -76,7 +77,7 @@ impl Runner { let mut executor = StackExecutor::new_with_precompile( &backend, gas_limit as usize, - T::config(), + config, T::Precompiles::execute, ); @@ -138,10 +139,17 @@ impl RunnerT for Runner { gas_limit: u32, gas_price: Option, nonce: Option, + config: &evm::Config, ) -> Result { - Self::execute(source, value, gas_limit, gas_price, nonce, |executor| { - executor.transact_call(source, target, value, input, gas_limit as usize) - }) + Self::execute( + source, + value, + gas_limit, + gas_price, + nonce, + config, + |executor| executor.transact_call(source, target, value, input, gas_limit as usize), + ) } fn create( @@ -151,14 +159,23 @@ impl RunnerT for Runner { gas_limit: u32, gas_price: Option, nonce: Option, + config: &evm::Config, ) -> Result { - Self::execute(source, value, gas_limit, gas_price, nonce, |executor| { - let address = executor.create_address(evm::CreateScheme::Legacy { caller: source }); - ( - executor.transact_create(source, value, init, gas_limit as usize), - address, - ) - }) + Self::execute( + source, + value, + gas_limit, + gas_price, + nonce, + config, + |executor| { + let address = executor.create_address(evm::CreateScheme::Legacy { caller: source }); + ( + executor.transact_create(source, value, init, gas_limit as usize), + address, + ) + }, + ) } fn create2( @@ -169,19 +186,28 @@ impl RunnerT for Runner { gas_limit: u32, gas_price: Option, nonce: Option, + config: &evm::Config, ) -> Result { let code_hash = H256::from_slice(Keccak256::digest(&init).as_slice()); - Self::execute(source, value, gas_limit, gas_price, nonce, |executor| { - let address = executor.create_address(evm::CreateScheme::Create2 { - caller: source, - code_hash, - salt, - }); - ( - executor.transact_create2(source, value, init, salt, gas_limit as usize), - address, - ) - }) + Self::execute( + source, + value, + gas_limit, + gas_price, + nonce, + config, + |executor| { + let address = executor.create_address(evm::CreateScheme::Create2 { + caller: source, + code_hash, + salt, + }); + ( + executor.transact_create2(source, value, init, salt, gas_limit as usize), + address, + ) + }, + ) } } diff --git a/frame/header-mmr/src/lib.rs b/frame/header-mmr/src/lib.rs index 3dc7c1cdf3..b5886f8cc6 100644 --- a/frame/header-mmr/src/lib.rs +++ b/frame/header-mmr/src/lib.rs @@ -166,13 +166,13 @@ impl Module { fn _find_parent_mmr_root(header: T::Header) -> Option { let id = OpaqueDigestItemId::Other; - let filter_log = - |MerkleMountainRangeRootLog { prefix, parent_mmr_root }: MerkleMountainRangeRootLog< - T::Hash, - >| match prefix { - PARENT_MMR_ROOT_LOG_ID => Some(parent_mmr_root), - _ => None, - }; + let filter_log = |MerkleMountainRangeRootLog { + prefix, + parent_mmr_root, + }: MerkleMountainRangeRootLog| match prefix { + PARENT_MMR_ROOT_LOG_ID => Some(parent_mmr_root), + _ => None, + }; // find the first other digest with the right prefix which converts to // the right kind of mmr root log. diff --git a/primitives/evm/Cargo.toml b/primitives/evm/Cargo.toml index a144227e04..b3fd8ea1d9 100644 --- a/primitives/evm/Cargo.toml +++ b/primitives/evm/Cargo.toml @@ -12,7 +12,7 @@ version = "1.2.2" [dependencies] # crates codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false } -evm = { version = "0.18", default-features = false, features = ["with-codec"] } +evm = { version = "0.19.0", default-features = false, features = ["with-codec"] } serde = { version = "1.0.118", optional = true, features = ["derive"] } # substrate sp-core = { default-features = false, git = "https://github.com/darwinia-network/substrate.git", branch = "common-library" }