Skip to content

Commit

Permalink
fix(levm): mcopy should resize to the biggest offset (#1558)
Browse files Browse the repository at this point in the history
**Motivation**

There is a bug in the `MCOPY` opcode, memory is not being resized to the
correct value.

**Description**

The `memory::try_copy_within` function has two parameters `from_offset`
and `to_offset`, when resizing the memory we now use the biggest of the
two values.
  • Loading branch information
LeanSerra authored Dec 23, 2024
1 parent 65d846b commit b9081ac
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crates/vm/levm/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ pub fn try_copy_within(
.map_err(|_err| VMError::VeryLargeNumber)?;
try_resize(
memory,
to_offset.checked_add(size).ok_or(VMError::OutOfBounds)?,
to_offset
.max(from_offset)
.checked_add(size)
.ok_or(VMError::OutOfBounds)?,
)?;

let mut temporary_buffer = vec![0u8; size];
Expand Down

0 comments on commit b9081ac

Please sign in to comment.