From 920046c47397210392f99136c719688902261981 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Thu, 2 May 2024 17:49:13 +0100 Subject: [PATCH] feat: support transient storage (EIP-1153) --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- frame/evm/src/runner/stack.rs | 13 +++++++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index afa83a1edf..5178b2280a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2291,7 +2291,7 @@ dependencies = [ [[package]] name = "evm" version = "0.41.1" -source = "git+https://github.com/moonbeam-foundation/evm?branch=moonbeam-polkadot-v1.7.2#d8991ec727ad0fb64fe9957a3cd307387a6701e4" +source = "git+https://github.com/moonbeam-foundation/evm?branch=v0.4.1-eip1153#f04b630487f63335cc95e33a66be2d83cae2bb70" dependencies = [ "auto_impl", "environmental", @@ -2311,7 +2311,7 @@ dependencies = [ [[package]] name = "evm-core" version = "0.41.0" -source = "git+https://github.com/moonbeam-foundation/evm?branch=moonbeam-polkadot-v1.7.2#d8991ec727ad0fb64fe9957a3cd307387a6701e4" +source = "git+https://github.com/moonbeam-foundation/evm?branch=v0.4.1-eip1153#f04b630487f63335cc95e33a66be2d83cae2bb70" dependencies = [ "parity-scale-codec", "primitive-types", @@ -2322,7 +2322,7 @@ dependencies = [ [[package]] name = "evm-gasometer" version = "0.41.0" -source = "git+https://github.com/moonbeam-foundation/evm?branch=moonbeam-polkadot-v1.7.2#d8991ec727ad0fb64fe9957a3cd307387a6701e4" +source = "git+https://github.com/moonbeam-foundation/evm?branch=v0.4.1-eip1153#f04b630487f63335cc95e33a66be2d83cae2bb70" dependencies = [ "environmental", "evm-core", @@ -2333,7 +2333,7 @@ dependencies = [ [[package]] name = "evm-runtime" version = "0.41.0" -source = "git+https://github.com/moonbeam-foundation/evm?branch=moonbeam-polkadot-v1.7.2#d8991ec727ad0fb64fe9957a3cd307387a6701e4" +source = "git+https://github.com/moonbeam-foundation/evm?branch=v0.4.1-eip1153#f04b630487f63335cc95e33a66be2d83cae2bb70" dependencies = [ "auto_impl", "environmental", diff --git a/Cargo.toml b/Cargo.toml index 6b7583e787..d02dbd13af 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,7 +52,7 @@ 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 = { git = "https://github.com/moonbeam-foundation/evm", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +evm = { git = "https://github.com/moonbeam-foundation/evm", branch = "v0.4.1-eip1153", 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/runner/stack.rs b/frame/evm/src/runner/stack.rs index b252c95c08..8b0a792b5b 100644 --- a/frame/evm/src/runner/stack.rs +++ b/frame/evm/src/runner/stack.rs @@ -725,6 +725,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, storage_meter: Option, @@ -750,6 +751,7 @@ impl<'vicinity, 'config, T: Config> SubstrateStackState<'vicinity, 'config, T> { }, _marker: PhantomData, original_storage: BTreeMap::new(), + transient_storage: BTreeMap::new(), recorded: Default::default(), weight_info, storage_meter, @@ -844,6 +846,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 @@ -930,6 +939,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);