diff --git a/Cargo.lock b/Cargo.lock index 22cecc618..f4bf89eec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1185,9 +1185,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", @@ -1203,9 +1203,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", @@ -1214,9 +1214,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", @@ -1225,9 +1225,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", @@ -7611,7 +7611,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04f8ab788026715fa63b31960869617cba39117e520eb415b0139543e325ab59" dependencies = [ "cfg-if 0.1.10", - "rand 0.3.23", + "rand 0.7.3", "static_assertions", ] diff --git a/client/rpc/src/eth.rs b/client/rpc/src/eth.rs index 29f5e83e1..664274241 100644 --- a/client/rpc/src/eth.rs +++ b/client/rpc/src/eth.rs @@ -632,6 +632,7 @@ impl EthApiT for EthApi 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)))?; @@ -650,6 +651,7 @@ impl EthApiT for EthApi 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)))?; @@ -689,6 +691,7 @@ impl EthApiT for EthApi 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)))?; @@ -707,6 +710,7 @@ impl EthApiT for EthApi 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/ethereum/Cargo.toml b/frame/ethereum/Cargo.toml index 26554373b..e376b1f82 100644 --- a/frame/ethereum/Cargo.toml +++ b/frame/ethereum/Cargo.toml @@ -19,7 +19,7 @@ sp-runtime = { version = "2.0.0-dev", default-features = false, git = "https://g sp-std = { version = "2.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "frontier" } sp-io = { version = "2.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "frontier" } fp-evm = { version = "0.8.0", default-features = false, path = "../../primitives/evm" } -evm = { version = "0.18.0", features = ["with-codec"], default-features = false } +evm = { version = "0.19.0", features = ["with-codec"], default-features = false } ethereum = { version = "0.5", default-features = false, features = ["with-codec"] } ethereum-types = { version = "0.9", default-features = false } rlp = { version = "0.4", default-features = false } diff --git a/frame/ethereum/src/lib.rs b/frame/ethereum/src/lib.rs index a1616576a..c365ce381 100644 --- a/frame/ethereum/src/lib.rs +++ b/frame/ethereum/src/lib.rs @@ -133,6 +133,7 @@ decl_module! { Some(transaction.gas_price), Some(transaction.nonce), transaction.action, + None, )?; let (reason, status, used_gas) = match info { @@ -372,7 +373,7 @@ impl Module { CurrentReceipts::get() } - /// Execute an Ethereum transaction, ignoring transaction signatures. + /// Execute an Ethereum transaction. pub fn execute( from: H160, input: Vec, @@ -381,6 +382,7 @@ impl Module { gas_price: Option, nonce: Option, action: TransactionAction, + config: Option, ) -> Result<(Option, CallOrCreateInfo), DispatchError> { match action { ethereum::TransactionAction::Call(target) => { @@ -392,6 +394,7 @@ impl Module { gas_limit.low_u32(), gas_price, nonce, + config.as_ref().unwrap_or(T::config()), ).map_err(Into::into)?))) }, ethereum::TransactionAction::Create => { @@ -402,6 +405,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/ethereum/src/tests.rs b/frame/ethereum/src/tests.rs index 0fca53c1d..a210209e3 100644 --- a/frame/ethereum/src/tests.rs +++ b/frame/ethereum/src/tests.rs @@ -66,6 +66,7 @@ fn transaction_should_increment_nonce() { Some(t.gas_price), Some(t.nonce), t.action, + None, )); assert_eq!(Evm::account_basic(&alice.address).nonce, U256::from(1)); }); @@ -115,6 +116,7 @@ fn transaction_with_invalid_nonce_should_not_work() { Some(t.gas_price), Some(t.nonce), t.action, + None, )); transaction.nonce = U256::from(0); @@ -143,6 +145,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 @@ -204,6 +207,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); }); @@ -226,6 +230,7 @@ fn transaction_should_generate_correct_gas_used() { Some(t.gas_price), Some(t.nonce), t.action, + None, ).unwrap(); match info { @@ -270,6 +275,7 @@ fn call_should_handle_errors() { Some(t.gas_price), Some(t.nonce), t.action, + None, )); let contract_address: Vec = FromHex::from_hex("32dcab0ef3fb2de2fce1d2e0799d36239671f04a").unwrap(); @@ -285,6 +291,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 { @@ -302,7 +309,8 @@ fn call_should_handle_errors() { U256::from(1048576), Some(U256::from(1)), Some(U256::from(2)), - TransactionAction::Call(H160::from_slice(&contract_address)) + TransactionAction::Call(H160::from_slice(&contract_address)), + None, ).ok().unwrap(); }); } diff --git a/frame/evm/Cargo.toml b/frame/evm/Cargo.toml index 742740470..dc5fc790f 100644 --- a/frame/evm/Cargo.toml +++ b/frame/evm/Cargo.toml @@ -26,9 +26,9 @@ sp-io = { version = "2.0.0", default-features = false, git = "https://github.com fp-evm = { version = "0.8.0", default-features = false, path = "../../primitives/evm" } primitive-types = { version = "0.7.0", default-features = false, features = ["rlp", "byteorder"] } rlp = { version = "0.4", default-features = false } -evm = { version = "0.18.5", default-features = false, features = ["with-codec"] } -evm-runtime = { version = "0.18", default-features = false } -evm-gasometer = { version = "0.18", default-features = false } +evm = { version = "0.19.0", default-features = false, features = ["with-codec"] } +evm-runtime = { version = "0.19.0", default-features = false } +evm-gasometer = { version = "0.19.0", default-features = false } sha3 = { version = "0.8", default-features = false } impl-trait-for-tuples = "0.1" ripemd160 = { version = "0.9", default-features = false } diff --git a/frame/evm/src/lib.rs b/frame/evm/src/lib.rs index ed4ee14f6..f32840492 100644 --- a/frame/evm/src/lib.rs +++ b/frame/evm/src/lib.rs @@ -391,6 +391,7 @@ decl_module! { gas_limit, Some(gas_price), nonce, + T::config(), )?; match info.exit_reason { @@ -429,6 +430,7 @@ decl_module! { gas_limit, Some(gas_price), nonce, + T::config(), )?; match info { @@ -476,6 +478,7 @@ decl_module! { gas_limit, Some(gas_price), nonce, + T::config(), )?; match info { diff --git a/frame/evm/src/runner/builtin.rs b/frame/evm/src/runner/builtin.rs index 92c8503a4..fc1ef0dc4 100644 --- a/frame/evm/src/runner/builtin.rs +++ b/frame/evm/src/runner/builtin.rs @@ -55,6 +55,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) => { @@ -77,8 +78,6 @@ impl RunnerT for Runner { origin: source, }; - let config = T::config(); - let mut substate = Handler::::new_with_precompile( &vicinity, gas_limit as usize, @@ -123,6 +122,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) => { @@ -145,8 +145,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) => { @@ -225,8 +224,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 0a65c378d..0ea87c64d 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 15cfa1599..894008655 100644 --- a/frame/evm/src/runner/stack.rs +++ b/frame/evm/src/runner/stack.rs @@ -44,6 +44,7 @@ impl Runner { gas_limit: u32, gas_price: Option, nonce: Option, + config: &evm::Config, f: F, ) -> Result, Error> where F: FnOnce(&mut StackExecutor>) -> (ExitReason, R), @@ -66,7 +67,7 @@ impl Runner { let mut executor = StackExecutor::new_with_precompile( &backend, gas_limit as usize, - T::config(), + config, T::Precompiles::execute, ); @@ -120,6 +121,7 @@ impl RunnerT for Runner { gas_limit: u32, gas_price: Option, nonce: Option, + config: &evm::Config, ) -> Result { Self::execute( source, @@ -127,6 +129,7 @@ impl RunnerT for Runner { gas_limit, gas_price, nonce, + config, |executor| executor.transact_call( source, target, @@ -144,6 +147,7 @@ impl RunnerT for Runner { gas_limit: u32, gas_price: Option, nonce: Option, + config: &evm::Config, ) -> Result { Self::execute( source, @@ -151,6 +155,7 @@ impl RunnerT for Runner { gas_limit, gas_price, nonce, + config, |executor| { let address = executor.create_address( evm::CreateScheme::Legacy { caller: source }, @@ -173,6 +178,7 @@ 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( @@ -181,6 +187,7 @@ impl RunnerT for Runner { gas_limit, gas_price, nonce, + config, |executor| { let address = executor.create_address( evm::CreateScheme::Create2 { caller: source, code_hash, salt }, diff --git a/primitives/evm/Cargo.toml b/primitives/evm/Cargo.toml index d3226d2be..abd3c692d 100644 --- a/primitives/evm/Cargo.toml +++ b/primitives/evm/Cargo.toml @@ -18,7 +18,7 @@ sp-core = { version = "2.0.0", git = "https://github.com/paritytech/substrate.gi sp-std = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", branch = "frontier", default-features = false } serde = { version = "1.0.101", optional = true, features = ["derive"] } codec = { package = "parity-scale-codec", version = "1.3.4", default-features = false } -evm = { version = "0.18.5", default-features = false, features = ["with-codec"] } +evm = { version = "0.19.0", default-features = false, features = ["with-codec"] } [features] default = ["std"] diff --git a/primitives/rpc/src/lib.rs b/primitives/rpc/src/lib.rs index c94d95a48..bdc2ed7e3 100644 --- a/primitives/rpc/src/lib.rs +++ b/primitives/rpc/src/lib.rs @@ -63,7 +63,7 @@ sp_api::decl_runtime_apis! { fn author() -> H160; /// For a given account address and index, returns pallet_evm::AccountStorages. fn storage_at(address: H160, index: U256) -> H256; - /// Returns a frame_ethereum::call response. + /// Returns a frame_ethereum::call response. If `estimate` is true, fn call( from: H160, to: H160, @@ -72,6 +72,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( @@ -81,6 +82,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/template/runtime/src/lib.rs b/template/runtime/src/lib.rs index 0c20e7e2c..434a295ae 100644 --- a/template/runtime/src/lib.rs +++ b/template/runtime/src/lib.rs @@ -500,7 +500,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, @@ -509,6 +518,7 @@ impl_runtime_apis! { gas_limit.low_u32(), gas_price, nonce, + config.as_ref().unwrap_or(::config()), ).map_err(|err| err.into()) } @@ -519,7 +529,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, @@ -527,6 +546,7 @@ impl_runtime_apis! { gas_limit.low_u32(), gas_price, nonce, + config.as_ref().unwrap_or(::config()), ).map_err(|err| err.into()) }