diff --git a/Cargo.lock b/Cargo.lock index 0b24f9ef57218..bd178702a3557 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1280,9 +1280,9 @@ dependencies = [ [[package]] name = "evm" -version = "0.16.1" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23a5c0ebf219b2b878bde1838282e0bb69828338df37fd136f1e93182ae35a59" +checksum = "68224b0aa788720ef0c8a23030a4412a021ed73df069a922bee8f0db9ed617e2" dependencies = [ "evm-core", "evm-gasometer", @@ -1295,18 +1295,18 @@ dependencies = [ [[package]] name = "evm-core" -version = "0.16.1" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d944a07232006a3435df8aa014fd364ed04cb28d731782339e9c56436594f2d4" +checksum = "4a040378759577447945c89da1b07d6e33fda32a97a104afe0ec3fa1c382949d" dependencies = [ "primitive-types", ] [[package]] name = "evm-gasometer" -version = "0.16.1" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a0d986953234d3786d0ca1beaaabab6a581d2128f8ec36c8c57e9c45e3d2b32" +checksum = "7bb5bc051afad6bb0735c82b46656bbdfac41917861307a608b1404a546fec42" dependencies = [ "evm-core", "evm-runtime", @@ -1315,9 +1315,9 @@ dependencies = [ [[package]] name = "evm-runtime" -version = "0.16.1" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1833c22f9518007d3cc28e14ff586263543516a1c7a147b260c603e4deb95403" +checksum = "7410f5677a52203d3fca02b0eb8f96f9799f3a45cff82946a8ed28379e6b1b04" dependencies = [ "evm-core", "primitive-types", diff --git a/frame/evm/Cargo.toml b/frame/evm/Cargo.toml index 8b030be4b7a54..e21a210a3ba90 100644 --- a/frame/evm/Cargo.toml +++ b/frame/evm/Cargo.toml @@ -24,7 +24,7 @@ sp-std = { version = "2.0.0-rc4", default-features = false, path = "../../primit sp-io = { version = "2.0.0-rc4", default-features = false, path = "../../primitives/io" } primitive-types = { version = "0.7.0", default-features = false, features = ["rlp"] } rlp = { version = "0.4", default-features = false } -evm = { version = "0.16", default-features = false } +evm = { version = "0.17", default-features = false } sha3 = { version = "0.8", default-features = false } [features] diff --git a/frame/evm/src/lib.rs b/frame/evm/src/lib.rs index e2d99827dc954..1ecd65e193f7a 100644 --- a/frame/evm/src/lib.rs +++ b/frame/evm/src/lib.rs @@ -310,11 +310,12 @@ decl_module! { gas_limit, gas_price, nonce, + true, )? { - ExitReason::Succeed(_) => { + (ExitReason::Succeed(_), _, _) => { Module::::deposit_event(Event::::Executed(target)); }, - ExitReason::Error(_) | ExitReason::Revert(_) | ExitReason::Fatal(_) => { + (_, _, _) => { Module::::deposit_event(Event::::ExecutedFailed(target)); }, } @@ -344,12 +345,13 @@ decl_module! { value, gas_limit, gas_price, - nonce + nonce, + true, )? { - (create_address, ExitReason::Succeed(_)) => { + (ExitReason::Succeed(_), create_address, _) => { Module::::deposit_event(Event::::Created(create_address)); }, - (create_address, _) => { + (_, create_address, _) => { Module::::deposit_event(Event::::CreatedFailed(create_address)); }, } @@ -380,12 +382,13 @@ decl_module! { value, gas_limit, gas_price, - nonce + nonce, + true, )? { - (create_address, ExitReason::Succeed(_)) => { + (ExitReason::Succeed(_), create_address, _) => { Module::::deposit_event(Event::::Created(create_address)); }, - (create_address, _) => { + (_, create_address, _) => { Module::::deposit_event(Event::::CreatedFailed(create_address)); }, } @@ -435,23 +438,26 @@ impl Module { value: U256, gas_limit: u32, gas_price: U256, - nonce: Option - ) -> Result<(H160, ExitReason), Error> { + nonce: Option, + apply_state: bool, + ) -> Result<(ExitReason, H160, U256), Error> { Self::execute_evm( source, value, gas_limit, gas_price, nonce, + apply_state, |executor| { - (executor.create_address( + let address = executor.create_address( evm::CreateScheme::Legacy { caller: source }, - ), executor.transact_create( + ); + (executor.transact_create( source, value, init, gas_limit as usize, - )) + ), address) }, ) } @@ -464,8 +470,9 @@ impl Module { value: U256, gas_limit: u32, gas_price: U256, - nonce: Option - ) -> Result<(H160, ExitReason), Error> { + nonce: Option, + apply_state: bool, + ) -> Result<(ExitReason, H160, U256), Error> { let code_hash = H256::from_slice(Keccak256::digest(&init).as_slice()); Self::execute_evm( source, @@ -473,16 +480,18 @@ impl Module { gas_limit, gas_price, nonce, + apply_state, |executor| { - (executor.create_address( + let address = executor.create_address( evm::CreateScheme::Create2 { caller: source, code_hash, salt }, - ), executor.transact_create2( + ); + (executor.transact_create2( source, value, init, salt, gas_limit as usize, - )) + ), address) }, ) } @@ -496,21 +505,23 @@ impl Module { gas_limit: u32, gas_price: U256, nonce: Option, - ) -> Result> { - Ok(Self::execute_evm( + apply_state: bool, + ) -> Result<(ExitReason, Vec, U256), Error> { + Self::execute_evm( source, value, gas_limit, gas_price, nonce, - |executor| ((), executor.transact_call( + apply_state, + |executor| executor.transact_call( source, target, value, input, gas_limit as usize, - )), - )?.1) + ), + ) } /// Execute an EVM operation. @@ -520,9 +531,10 @@ impl Module { gas_limit: u32, gas_price: U256, nonce: Option, + apply_state: bool, f: F, - ) -> Result<(R, ExitReason), Error> where - F: FnOnce(&mut StackExecutor>) -> (R, ExitReason), + ) -> Result<(ExitReason, R, U256), Error> where + F: FnOnce(&mut StackExecutor>) -> (ExitReason, R), { let vicinity = Vicinity { gas_price, @@ -550,12 +562,15 @@ impl Module { let (retv, reason) = f(&mut executor); + let used_gas = U256::from(executor.used_gas()); let actual_fee = executor.fee(gas_price); executor.deposit(source, total_fee.saturating_sub(actual_fee)); - let (values, logs) = executor.deconstruct(); - backend.apply(values, logs, true); + if apply_state { + let (values, logs) = executor.deconstruct(); + backend.apply(values, logs, true); + } - Ok((retv, reason)) + Ok((retv, reason, used_gas)) } }