From d79fa917929b1a0289cb1ed3a0af3245dfaa3f26 Mon Sep 17 00:00:00 2001 From: Damian Ramirez Date: Thu, 26 Dec 2024 09:22:49 -0300 Subject: [PATCH] fix(levm): key of transient storage (#1561) **Motivation** We were setting the transient storage key wrong. We need to use the `to` of the current `callframe`. **Description** Change the key in `tload` and `tstore`:`(current_call_frame.to, key): value` --- .../levm/src/opcode_handlers/stack_memory_storage_flow.rs | 4 ++-- crates/vm/levm/tests/tests.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/vm/levm/src/opcode_handlers/stack_memory_storage_flow.rs b/crates/vm/levm/src/opcode_handlers/stack_memory_storage_flow.rs index 483c46a63..b6eef53c5 100644 --- a/crates/vm/levm/src/opcode_handlers/stack_memory_storage_flow.rs +++ b/crates/vm/levm/src/opcode_handlers/stack_memory_storage_flow.rs @@ -30,7 +30,7 @@ impl VM { let value = self .env .transient_storage - .get(&(current_call_frame.msg_sender, key)) + .get(&(current_call_frame.to, key)) .cloned() .unwrap_or(U256::zero()); @@ -53,7 +53,7 @@ impl VM { let value = current_call_frame.stack.pop()?; self.env .transient_storage - .insert((current_call_frame.msg_sender, key), value); + .insert((current_call_frame.to, key), value); Ok(OpcodeSuccess::Continue) } diff --git a/crates/vm/levm/tests/tests.rs b/crates/vm/levm/tests/tests.rs index a4b1993fa..0826f9149 100644 --- a/crates/vm/levm/tests/tests.rs +++ b/crates/vm/levm/tests/tests.rs @@ -3737,10 +3737,10 @@ fn transient_store() { let mut current_call_frame = vm.call_frames.pop().unwrap(); vm.execute(&mut current_call_frame).unwrap(); - let msg_sender = current_call_frame.msg_sender; + let callee = current_call_frame.to; assert_eq!( - *vm.env.transient_storage.get(&(msg_sender, key)).unwrap(), + *vm.env.transient_storage.get(&(callee, key)).unwrap(), value ) } @@ -3774,9 +3774,9 @@ fn transient_load() { let mut vm = new_vm_with_ops(&operations).unwrap(); - let caller = vm.current_call_frame_mut().unwrap().msg_sender; + let callee = vm.current_call_frame_mut().unwrap().to; - vm.env.transient_storage.insert((caller, key), value); + vm.env.transient_storage.insert((callee, key), value); let mut current_call_frame = vm.call_frames.pop().unwrap(); vm.execute(&mut current_call_frame).unwrap();