diff --git a/Cargo.lock b/Cargo.lock index 0473e2440ea..887b6e70a1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1500,19 +1500,18 @@ dependencies = [ [[package]] name = "ethjson" version = "0.1.0" -source = "git+https://github.com/openethereum/openethereum?rev=v2.6.2#25936ae0f6d48f5ac6fb93cd467c15f4f8a631c2" +source = "git+https://github.com/openethereum/openethereum?rev=v2.6.8#9bf6ed8450ec2eb61f14b362574c453ed68bd761" dependencies = [ "ethereum-types", "rustc-hex 1.0.0", "serde", - "serde_derive", "serde_json", ] [[package]] name = "evm" version = "0.1.0" -source = "git+https://github.com/openethereum/openethereum?rev=v2.6.2#25936ae0f6d48f5ac6fb93cd467c15f4f8a631c2" +source = "git+https://github.com/openethereum/openethereum?rev=v2.6.8#9bf6ed8450ec2eb61f14b362574c453ed68bd761" dependencies = [ "bit-set", "ethereum-types", @@ -1522,7 +1521,7 @@ dependencies = [ "memory-cache", "parity-bytes", "parity-util-mem", - "parking_lot 0.7.1", + "parking_lot 0.9.0", "vm", ] @@ -2366,7 +2365,7 @@ dependencies = [ [[package]] name = "keccak-hasher" version = "0.1.1" -source = "git+https://github.com/openethereum/openethereum?rev=v2.6.2#25936ae0f6d48f5ac6fb93cd467c15f4f8a631c2" +source = "git+https://github.com/openethereum/openethereum?rev=v2.6.8#9bf6ed8450ec2eb61f14b362574c453ed68bd761" dependencies = [ "ethereum-types", "hash-db", @@ -2648,7 +2647,7 @@ dependencies = [ [[package]] name = "memory-cache" version = "0.1.0" -source = "git+https://github.com/openethereum/openethereum?rev=v2.6.2#25936ae0f6d48f5ac6fb93cd467c15f4f8a631c2" +source = "git+https://github.com/openethereum/openethereum?rev=v2.6.8#9bf6ed8450ec2eb61f14b362574c453ed68bd761" dependencies = [ "lru-cache", "parity-util-mem", @@ -3764,6 +3763,17 @@ dependencies = [ "parking_lot_core 0.4.0", ] +[[package]] +name = "parking_lot" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" +dependencies = [ + "lock_api 0.3.4", + "parking_lot_core 0.6.2", + "rustc_version", +] + [[package]] name = "parking_lot" version = "0.10.2" @@ -3798,6 +3808,21 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "parking_lot_core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" +dependencies = [ + "cfg-if", + "cloudabi 0.0.3", + "libc", + "redox_syscall", + "rustc_version", + "smallvec 0.6.13", + "winapi 0.3.8", +] + [[package]] name = "parking_lot_core" version = "0.7.2" @@ -3830,7 +3855,7 @@ dependencies = [ [[package]] name = "patricia-trie-ethereum" version = "0.1.0" -source = "git+https://github.com/openethereum/openethereum?rev=v2.6.2#25936ae0f6d48f5ac6fb93cd467c15f4f8a631c2" +source = "git+https://github.com/openethereum/openethereum?rev=v2.6.8#9bf6ed8450ec2eb61f14b362574c453ed68bd761" dependencies = [ "elastic-array 0.10.3", "ethereum-types", @@ -5656,7 +5681,7 @@ checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce" [[package]] name = "vm" version = "0.1.0" -source = "git+https://github.com/openethereum/openethereum?rev=v2.6.2#25936ae0f6d48f5ac6fb93cd467c15f4f8a631c2" +source = "git+https://github.com/openethereum/openethereum?rev=v2.6.8#9bf6ed8450ec2eb61f14b362574c453ed68bd761" dependencies = [ "ethereum-types", "ethjson", diff --git a/runtime/near-evm-runner/Cargo.toml b/runtime/near-evm-runner/Cargo.toml index 604fad9eb2d..b8a93874762 100644 --- a/runtime/near-evm-runner/Cargo.toml +++ b/runtime/near-evm-runner/Cargo.toml @@ -24,8 +24,8 @@ keccak-hash = "0.2.0" ripemd160 = "0.9.0" libsecp256k1 = "0.3.5" -evm = { git = "https://github.com/openethereum/openethereum", rev = "v2.6.2" } -vm = { git = "https://github.com/openethereum/openethereum", rev = "v2.6.2" } +evm = { git = "https://github.com/openethereum/openethereum", rev = "v2.6.8" } +vm = { git = "https://github.com/openethereum/openethereum", rev = "v2.6.8" } bn = { git = "https://github.com/paritytech/bn", default-features = false } parity-bytes = "0.1.0" ethereum-types = "0.6.0" diff --git a/runtime/near-evm-runner/src/interpreter.rs b/runtime/near-evm-runner/src/interpreter.rs index f767cf85e55..554a0599acc 100644 --- a/runtime/near-evm-runner/src/interpreter.rs +++ b/runtime/near-evm-runner/src/interpreter.rs @@ -26,6 +26,7 @@ pub fn deploy_code( code: &[u8], gas: &U256, evm_gas_config: &EvmCostConfig, + chain_id: u128, ) -> Result { let mut nonce = U256::zero(); if address_type == CreateContractAddress::FromSenderAndNonce { @@ -49,6 +50,7 @@ pub fn deploy_code( code, gas, evm_gas_config, + chain_id, )?; // Apply known gas amount changes (all reverts are NeedsReturn) @@ -82,6 +84,7 @@ pub fn _create( code: &[u8], gas: &U256, evm_gas_config: &EvmCostConfig, + chain_id: u128, ) -> Result<(ExecTrapResult, Option)> { let mut store = StateStore::default(); let mut sub_state = SubState::new(sender, &mut store, state); @@ -110,6 +113,7 @@ pub fn _create( call_stack_depth + 1, false, evm_gas_config, + chain_id, ); ext.info.gas_limit = U256::from(gas); ext.schedule = Schedule::new_constantinople(); @@ -133,6 +137,7 @@ pub fn call( should_commit: bool, gas: &U256, evm_gas_config: &EvmCostConfig, + chain_id: u128, ) -> Result { run_and_commit_if_success( state, @@ -148,6 +153,7 @@ pub fn call( should_commit, gas, evm_gas_config, + chain_id, ) } @@ -161,6 +167,7 @@ pub fn delegate_call( input: &[u8], gas: &U256, evm_gas_config: &EvmCostConfig, + chain_id: u128, ) -> Result { run_and_commit_if_success( state, @@ -176,6 +183,7 @@ pub fn delegate_call( true, gas, evm_gas_config, + chain_id, ) } @@ -188,6 +196,7 @@ pub fn static_call( input: &[u8], gas: &U256, evm_gas_config: &EvmCostConfig, + chain_id: u128, ) -> Result { run_and_commit_if_success( state, @@ -203,6 +212,7 @@ pub fn static_call( false, gas, evm_gas_config, + chain_id, ) } @@ -221,6 +231,7 @@ fn run_and_commit_if_success( should_commit: bool, gas: &U256, evm_gas_config: &EvmCostConfig, + chain_id: u128, ) -> Result { // run the interpreter and let (result, state_updates) = run_against_state( @@ -236,6 +247,7 @@ fn run_and_commit_if_success( is_static, gas, evm_gas_config, + chain_id, )?; // Apply known gas amount changes (all reverts are NeedsReturn) @@ -279,6 +291,7 @@ fn run_against_state( is_static: bool, gas: &U256, evm_gas_config: &EvmCostConfig, + chain_id: u128, ) -> Result<(ExecTrapResult, Option)> { let code = state.code_at(code_address)?.unwrap_or_else(Vec::new); @@ -319,6 +332,7 @@ fn run_against_state( call_stack_depth + 1, is_static, evm_gas_config, + chain_id, ); // Gas limit is evm block gas limit, should at least prepaid gas. ext.info.gas_limit = *gas; diff --git a/runtime/near-evm-runner/src/lib.rs b/runtime/near-evm-runner/src/lib.rs index 13b5ccd8296..b1b3f2fa9f2 100644 --- a/runtime/near-evm-runner/src/lib.rs +++ b/runtime/near-evm-runner/src/lib.rs @@ -39,6 +39,7 @@ pub struct EvmContext<'a> { gas_counter: GasCounter, pub evm_gas_counter: EvmGasCounter, fees_config: &'a RuntimeFeesConfig, + chain_id: u128, domain_separator: RawU256, } @@ -181,6 +182,7 @@ impl<'a> EvmContext<'a> { ), evm_gas_counter: EvmGasCounter::new(0.into(), evm_gas), fees_config, + chain_id, domain_separator, } } @@ -203,6 +205,7 @@ impl<'a> EvmContext<'a> { &bytecode, &self.evm_gas_counter.gas_left(), &self.fees_config.evm_config, + self.chain_id, )? { ContractCreateResult::Created(address, gas_left) => { self.evm_gas_counter.set_gas_left(gas_left); @@ -241,6 +244,7 @@ impl<'a> EvmContext<'a> { true, &self.evm_gas_counter.gas_left(), &self.fees_config.evm_config, + self.chain_id, )?; match result { MessageCallResult::Success(gas_left, data) => { @@ -277,6 +281,7 @@ impl<'a> EvmContext<'a> { true, &self.evm_gas_counter.gas_left(), &self.fees_config.evm_config, + self.chain_id, )?; match result { MessageCallResult::Success(gas_left, data) => { @@ -313,6 +318,7 @@ impl<'a> EvmContext<'a> { false, &self.evm_gas_counter.gas_left(), &self.fees_config.evm_config, + self.chain_id, )?; let result = match result { MessageCallResult::Success(gas_left, data) => { diff --git a/runtime/near-evm-runner/src/near_ext.rs b/runtime/near-evm-runner/src/near_ext.rs index 409a6220330..29ea2ee3331 100644 --- a/runtime/near-evm-runner/src/near_ext.rs +++ b/runtime/near-evm-runner/src/near_ext.rs @@ -1,3 +1,4 @@ +use std::convert::TryInto; use std::sync::Arc; use ethereum_types::{Address, H256, U256}; @@ -26,6 +27,7 @@ pub struct NearExt<'a> { pub static_flag: bool, pub depth: usize, pub evm_gas_config: &'a EvmCostConfig, + pub chain_id: u128, } impl std::fmt::Debug for NearExt<'_> { @@ -36,6 +38,7 @@ impl std::fmt::Debug for NearExt<'_> { write!(f, "\n\tcontext_addr: {:?}", self.context_addr)?; write!(f, "\n\tstatic_flag: {:?}", self.static_flag)?; write!(f, "\n\tdepth: {:?}", self.depth)?; + write!(f, "\n\tchain_id: {:?}", self.chain_id)?; write!(f, "\n}}") } } @@ -48,6 +51,7 @@ impl<'a> NearExt<'a> { depth: usize, static_flag: bool, evm_gas_config: &'a EvmCostConfig, + chain_id: u128, ) -> Self { Self { info: Default::default(), @@ -59,11 +63,18 @@ impl<'a> NearExt<'a> { static_flag, depth, evm_gas_config, + chain_id, } } } impl<'a> vm::Ext for NearExt<'a> { + /// EIP-1344: Returns the current chain's EIP-155 unique identifier. + /// See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1344.md + fn chain_id(&self) -> u64 { + self.chain_id.try_into().unwrap() + } + /// Returns the storage value for a given key if reversion happens on the current transaction. fn initial_storage_at(&self, key: &H256) -> EvmResult { let raw_val = self @@ -150,6 +161,7 @@ impl<'a> vm::Ext for NearExt<'a> { &code.to_vec(), gas, &self.evm_gas_config, + self.chain_id, ) .map_err(|_| TrapKind::Call(ActionParams::default())) } @@ -200,6 +212,7 @@ impl<'a> vm::Ext for NearExt<'a> { true, // should_commit gas, &self.evm_gas_config, + self.chain_id, ), CallType::StaticCall => interpreter::static_call( self.sub_state, @@ -210,6 +223,7 @@ impl<'a> vm::Ext for NearExt<'a> { &data.to_vec(), gas, &self.evm_gas_config, + self.chain_id, ), CallType::CallCode => { // Call another contract using storage of the current contract. No longer used. @@ -225,6 +239,7 @@ impl<'a> vm::Ext for NearExt<'a> { &data.to_vec(), gas, &self.evm_gas_config, + self.chain_id, ), }; result.map_err(|_| TrapKind::Call(ActionParams::default()))