Skip to content

Commit

Permalink
fix(levm): key of transient storage (#1561)
Browse files Browse the repository at this point in the history
**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`
  • Loading branch information
damiramirez authored Dec 26, 2024
1 parent 3b440a8 commit d79fa91
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions crates/vm/levm/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit d79fa91

Please sign in to comment.