diff --git a/Cargo.lock b/Cargo.lock index 418185be83..abb28086de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2059,9 +2059,8 @@ dependencies = [ [[package]] name = "evm" -version = "0.41.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "767f43e9630cc36cf8ff2777cbb0121b055f0d1fd6eaaa13b46a1808f0d0e7e9" +version = "0.41.2" +source = "git+https://github.com/bifrost-platform/evm?branch=bifrost-polkadot-stable2407#e5ae66a5884d8b0914b4872c862dbb92e2bb05f8" dependencies = [ "auto_impl", "environmental", @@ -2081,8 +2080,7 @@ dependencies = [ [[package]] name = "evm-core" version = "0.41.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1da6cedc5cedb4208e59467106db0d1f50db01b920920589f8e672c02fdc04f" +source = "git+https://github.com/bifrost-platform/evm?branch=bifrost-polkadot-stable2407#e5ae66a5884d8b0914b4872c862dbb92e2bb05f8" dependencies = [ "parity-scale-codec", "primitive-types", @@ -2093,8 +2091,7 @@ dependencies = [ [[package]] name = "evm-gasometer" version = "0.41.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dc0eb591abc5cd7b05bef6a036c2bb6c66ab6c5e0c5ce94bfe377ab670b1fd7" +source = "git+https://github.com/bifrost-platform/evm?branch=bifrost-polkadot-stable2407#e5ae66a5884d8b0914b4872c862dbb92e2bb05f8" dependencies = [ "environmental", "evm-core", @@ -2105,8 +2102,7 @@ dependencies = [ [[package]] name = "evm-runtime" version = "0.41.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84bbe09b64ae13a29514048c1bb6fda6374ac0b4f6a1f15a443348ab88ef42cd" +source = "git+https://github.com/bifrost-platform/evm?branch=bifrost-polkadot-stable2407#e5ae66a5884d8b0914b4872c862dbb92e2bb05f8" dependencies = [ "auto_impl", "environmental", diff --git a/Cargo.toml b/Cargo.toml index babcf2ab12..a86c9a0754 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,9 +69,9 @@ derive_more = "0.99" environmental = { version = "1.1.4", default-features = false } ethereum = { version = "0.15.0", default-features = false } ethereum-types = { version = "0.14.1", default-features = false } -evm = { version = "0.41.1", default-features = false } -evm-gasometer = { version = "0.41.0", default-features = false } -evm-runtime = { version = "0.41.0", default-features = false } +evm = { git = "https://github.com/bifrost-platform/evm", branch = "bifrost-polkadot-stable2407", default-features = false } +evm-gasometer = { git = "https://github.com/bifrost-platform/evm", branch = "bifrost-polkadot-stable2407", default-features = false } +evm-runtime = { git = "https://github.com/bifrost-platform/evm", branch = "bifrost-polkadot-stable2407", default-features = false } futures = "0.3.30" hash-db = { version = "0.16.0", default-features = false } hex = { version = "0.4.3", default-features = false, features = ["alloc"] } diff --git a/frame/evm/src/lib.rs b/frame/evm/src/lib.rs index c03b67cce7..464aa9c58a 100644 --- a/frame/evm/src/lib.rs +++ b/frame/evm/src/lib.rs @@ -79,7 +79,7 @@ use scale_info::TypeInfo; // Substrate use frame_support::{ dispatch::{DispatchResultWithPostInfo, Pays, PostDispatchInfo}, - storage::{child::KillStorageResult, KeyPrefixIterator}, + storage::KeyPrefixIterator, traits::{ fungible::{Balanced, Credit, Debt}, tokens::{ @@ -184,7 +184,7 @@ pub mod pallet { /// EVM config used in the module. fn config() -> &'static EvmConfig { - &SHANGHAI_CONFIG + &CANCUN_CONFIG } } @@ -792,7 +792,7 @@ impl GasWeightMapping for FixedGasWeightMapping { } } -static SHANGHAI_CONFIG: EvmConfig = EvmConfig::shanghai(); +static CANCUN_CONFIG: EvmConfig = EvmConfig::cancun(); impl Pallet { /// Check whether an account is empty. @@ -821,32 +821,13 @@ impl Pallet { /// Remove an account. pub fn remove_account(address: &H160) { if >::contains_key(address) { - // Remember to call `dec_sufficients` when clearing Suicided. - >::insert(address, ()); - - // In theory, we can always have pre-EIP161 contracts, so we - // make sure the account nonce is at least one. let account_id = T::AddressMapping::into_account_id(*address); - frame_system::Pallet::::inc_account_nonce(&account_id); + let _ = frame_system::Pallet::::dec_sufficients(&account_id); } >::remove(address); >::remove(address); - - if T::SuicideQuickClearLimit::get() > 0 { - #[allow(deprecated)] - let res = >::remove_prefix(address, Some(T::SuicideQuickClearLimit::get())); - - match res { - KillStorageResult::AllRemoved(_) => { - >::remove(address); - - let account_id = T::AddressMapping::into_account_id(*address); - let _ = frame_system::Pallet::::dec_sufficients(&account_id); - } - KillStorageResult::SomeRemaining(_) => (), - } - } + let _ = >::clear_prefix(address, u32::max_value(), None); } /// Create an account. diff --git a/frame/evm/src/runner/stack.rs b/frame/evm/src/runner/stack.rs index 0707159cd2..01ed5d3432 100644 --- a/frame/evm/src/runner/stack.rs +++ b/frame/evm/src/runner/stack.rs @@ -571,6 +571,7 @@ where struct SubstrateStackSubstate<'config> { metadata: StackSubstateMetadata<'config>, deletes: BTreeSet, + creates: BTreeSet, logs: Vec, parent: Option>>, } @@ -589,6 +590,7 @@ impl<'config> SubstrateStackSubstate<'config> { metadata: self.metadata.spit_child(gas_limit, is_static), parent: None, deletes: BTreeSet::new(), + creates: BTreeSet::new(), logs: Vec::new(), }; mem::swap(&mut entering, self); @@ -605,7 +607,7 @@ impl<'config> SubstrateStackSubstate<'config> { self.metadata.swallow_commit(exited.metadata)?; self.logs.append(&mut exited.logs); self.deletes.append(&mut exited.deletes); - + self.creates.append(&mut exited.creates); sp_io::storage::commit_transaction(); Ok(()) } @@ -640,10 +642,24 @@ impl<'config> SubstrateStackSubstate<'config> { false } + pub fn created(&self, address: H160) -> bool { + if self.creates.contains(&address) { + return true; + } + if let Some(parent) = self.parent.as_ref() { + return parent.created(address); + } + false + } + pub fn set_deleted(&mut self, address: H160) { self.deletes.insert(address); } + pub fn set_created(&mut self, address: H160) { + self.creates.insert(address); + } + pub fn log(&mut self, address: H160, topics: Vec, data: Vec) { self.logs.push(Log { address, @@ -676,6 +692,7 @@ pub struct SubstrateStackState<'vicinity, 'config, T> { vicinity: &'vicinity Vicinity, substate: SubstrateStackSubstate<'config>, original_storage: BTreeMap<(H160, H256), H256>, + transient_storage: BTreeMap<(H160, H256), H256>, recorded: Recorded, weight_info: Option, _marker: PhantomData, @@ -693,11 +710,13 @@ impl<'vicinity, 'config, T: Config> SubstrateStackState<'vicinity, 'config, T> { substate: SubstrateStackSubstate { metadata, deletes: BTreeSet::new(), + creates: BTreeSet::new(), logs: Vec::new(), parent: None, }, _marker: PhantomData, original_storage: BTreeMap::new(), + transient_storage: BTreeMap::new(), recorded: Default::default(), weight_info, } @@ -791,6 +810,13 @@ where >::get(address, index) } + fn transient_storage(&self, address: H160, index: H256) -> H256 { + self.transient_storage + .get(&(address, index)) + .copied() + .unwrap_or_default() + } + fn original_storage(&self, address: H160, index: H256) -> Option { Some( self.original_storage @@ -838,6 +864,10 @@ where self.substate.deleted(address) } + fn created(&self, address: H160) -> bool { + self.substate.created(address) + } + fn inc_nonce(&mut self, address: H160) -> Result<(), ExitError> { let account_id = T::AddressMapping::into_account_id(address); frame_system::Pallet::::inc_account_nonce(&account_id); @@ -877,6 +907,10 @@ where } } + fn set_transient_storage(&mut self, address: H160, key: H256, value: H256) { + self.transient_storage.insert((address, key), value); + } + fn reset_storage(&mut self, address: H160) { #[allow(deprecated)] let _ = >::remove_prefix(address, None); @@ -890,6 +924,10 @@ where self.substate.set_deleted(address) } + fn set_created(&mut self, address: H160) { + self.substate.set_created(address); + } + fn set_code(&mut self, address: H160, code: Vec) { log::debug!( target: "evm", diff --git a/frame/evm/src/tests.rs b/frame/evm/src/tests.rs index 32136d1b9c..7c7267db88 100644 --- a/frame/evm/src/tests.rs +++ b/frame/evm/src/tests.rs @@ -1037,7 +1037,7 @@ fn handle_sufficient_reference() { assert_eq!(account_2.sufficients, 1); EVM::remove_account(&addr_2); let account_2 = frame_system::Account::::get(substrate_addr_2); - assert_eq!(account_2.sufficients, 1); + assert_eq!(account_2.sufficients, 0); }); } diff --git a/precompiles/src/testing/handle.rs b/precompiles/src/testing/handle.rs index ab6207786a..0228bcca43 100644 --- a/precompiles/src/testing/handle.rs +++ b/precompiles/src/testing/handle.rs @@ -117,7 +117,7 @@ impl PrecompileHandle for MockHandle { if self .record_cost(crate::evm::costs::call_cost( context.apparent_value, - &evm::Config::london(), + &evm::Config::cancun(), )) .is_err() { diff --git a/primitives/evm/src/validation.rs b/primitives/evm/src/validation.rs index 4359dcaef1..b69172e795 100644 --- a/primitives/evm/src/validation.rs +++ b/primitives/evm/src/validation.rs @@ -263,7 +263,7 @@ mod tests { UnknownError, } - static SHANGHAI_CONFIG: evm::Config = evm::Config::shanghai(); + static CANCUN_CONFIG: evm::Config = evm::Config::cancun(); impl From for TestError { fn from(e: TransactionValidationError) -> Self { @@ -337,7 +337,7 @@ mod tests { } = input; CheckEvmTransaction::::new( CheckEvmTransactionConfig { - evm_config: &SHANGHAI_CONFIG, + evm_config: &CANCUN_CONFIG, block_gas_limit: blockchain_gas_limit, base_fee: blockchain_base_fee, chain_id: blockchain_chain_id,