From 13936265bc9849b7cab5169ede9ce318ba66943c Mon Sep 17 00:00:00 2001 From: Jacob <61052369+jacob-chia@users.noreply.github.com> Date: Thu, 18 Apr 2024 08:59:24 +0800 Subject: [PATCH] Feat: spport tload, tstore, and mcopy (#468) * support-tload-tstore-mcopy * temporarily enable onchain-test on feat-tload-tstore-mcopy * revert ci/rust.yml --- Cargo.lock | 8 ++++---- Cargo.toml | 6 +++--- src/evm/host.rs | 19 +++++++++++++++++++ src/evm/vm.rs | 3 +++ 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a930df94d..872e73bef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10812,7 +10812,7 @@ dependencies = [ [[package]] name = "revm" version = "3.3.0" -source = "git+https://github.com/fuzzland/revm?rev=33b46b9#33b46b91e7189a6c378f31ceaaf288d59a97aebf" +source = "git+https://github.com/fuzzland/revm?rev=1dead51#1dead511260119867b220b38298ddca07f406357" dependencies = [ "auto_impl", "revm-interpreter 1.1.2", @@ -10856,7 +10856,7 @@ dependencies = [ [[package]] name = "revm-interpreter" version = "1.1.2" -source = "git+https://github.com/fuzzland/revm?rev=33b46b9#33b46b91e7189a6c378f31ceaaf288d59a97aebf" +source = "git+https://github.com/fuzzland/revm?rev=1dead51#1dead511260119867b220b38298ddca07f406357" dependencies = [ "derive_more", "enumn", @@ -10878,7 +10878,7 @@ dependencies = [ [[package]] name = "revm-precompile" version = "2.0.3" -source = "git+https://github.com/fuzzland/revm?rev=33b46b9#33b46b91e7189a6c378f31ceaaf288d59a97aebf" +source = "git+https://github.com/fuzzland/revm?rev=1dead51#1dead511260119867b220b38298ddca07f406357" dependencies = [ "k256 0.13.3", "num 0.4.1", @@ -10911,7 +10911,7 @@ dependencies = [ [[package]] name = "revm-primitives" version = "1.1.2" -source = "git+https://github.com/fuzzland/revm?rev=33b46b9#33b46b91e7189a6c378f31ceaaf288d59a97aebf" +source = "git+https://github.com/fuzzland/revm?rev=1dead51#1dead511260119867b220b38298ddca07f406357" dependencies = [ "auto_impl", "bitflags 2.5.0", diff --git a/Cargo.toml b/Cargo.toml index d081ba259..c6ae84bed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -80,17 +80,17 @@ typetag = "0.2.13" lazy_static = "1.4.0" num_cpus = "1.0" -revm = { git = "https://github.com/fuzzland/revm", rev = "33b46b9", features = [ +revm = { git = "https://github.com/fuzzland/revm", rev = "1dead51", features = [ "no_gas_measuring", "serde", "memory_limit", ] } -revm-primitives = { git = "https://github.com/fuzzland/revm", rev = "33b46b9", features = [ +revm-primitives = { git = "https://github.com/fuzzland/revm", rev = "1dead51", features = [ "no_gas_measuring", "serde", "memory_limit", ] } -revm-interpreter = { git = "https://github.com/fuzzland/revm", rev = "33b46b9", features = [ +revm-interpreter = { git = "https://github.com/fuzzland/revm", rev = "1dead51", features = [ "no_gas_measuring", "serde", "memory_limit", diff --git a/src/evm/host.rs b/src/evm/host.rs index 17d6c04cd..b5717889d 100644 --- a/src/evm/host.rs +++ b/src/evm/host.rs @@ -38,6 +38,7 @@ use revm_primitives::{ BerlinSpec, Bytecode, ByzantiumSpec, + CancunSpec, Env, FrontierSpec, HomesteadSpec, @@ -164,6 +165,8 @@ where SC: Scheduler + Clone, { pub evmstate: EVMState, + /// [EIP-1153[(https://eips.ethereum.org/EIPS/eip-1153) transient storage that is discarded after every transactions + pub transient_storage: HashMap<(EVMAddress, EVMU256), EVMU256>, // these are internal to the host pub env: Env, pub code: HashMap>, @@ -270,6 +273,7 @@ where fn clone(&self) -> Self { Self { evmstate: self.evmstate.clone(), + transient_storage: self.transient_storage.clone(), env: self.env.clone(), code: self.code.clone(), hash_to_address: self.hash_to_address.clone(), @@ -331,6 +335,7 @@ where pub fn new(scheduler: SC, workdir: String) -> Self { Self { evmstate: EVMState::new(), + transient_storage: HashMap::new(), env: Env::default(), code: HashMap::new(), hash_to_address: HashMap::new(), @@ -400,6 +405,7 @@ where SpecId::LONDON => interp.run_inspect::, LondonSpec>(self, state), SpecId::MERGE => interp.run_inspect::, MergeSpec>(self, state), SpecId::SHANGHAI => interp.run_inspect::, ShanghaiSpec>(self, state), + SpecId::CANCUN => interp.run_inspect::, CancunSpec>(self, state), _ => interp.run_inspect::, LatestSpec>(self, state), } } @@ -1269,6 +1275,19 @@ where Some((EVMU256::from(0), EVMU256::from(0), EVMU256::from(0), true)) } + fn tload(&mut self, address: EVMAddress, index: EVMU256) -> EVMU256 { + if let Some(slot) = self.transient_storage.get(&(address, index)) { + *slot + } else { + self.transient_storage.insert((address, index), self.next_slot); + self.next_slot + } + } + + fn tstore(&mut self, address: EVMAddress, index: EVMU256, value: EVMU256) { + self.transient_storage.insert((address, index), value); + } + fn log(&mut self, _address: EVMAddress, _topics: Vec, _data: Bytes) { // flag check if _topics.len() == 1 { diff --git a/src/evm/vm.rs b/src/evm/vm.rs index 78bcd5d4f..2a1014817 100644 --- a/src/evm/vm.rs +++ b/src/evm/vm.rs @@ -455,6 +455,7 @@ macro_rules! init_host { $host.jumpi_trace = 37; $host.current_typed_bug = vec![]; $host.randomness = vec![9]; + $host.transient_storage = HashMap::new(); // Uncomment the next line if middleware is needed. // $host.add_middlewares(middleware.clone()); }; @@ -556,6 +557,7 @@ where self.host.jumpi_trace = 37; self.host.current_self_destructs = vec![]; self.host.current_arbitrary_calls = vec![]; + self.host.transient_storage = HashMap::new(); // Initially, there is no state change unsafe { STATE_CHANGE = false; @@ -1058,6 +1060,7 @@ where unsafe { IS_FAST_CALL_STATIC = true; self.host.evmstate = vm_state.as_any().downcast_ref_unchecked::().clone(); + self.host.transient_storage = HashMap::new(); self.host.current_self_destructs = vec![]; self.host.current_arbitrary_calls = vec![]; self.host.call_count = 0;