Skip to content

Commit

Permalink
Merge branch 'v0.38.4-aurora-branch' of github.com:aurora-is-near/spu…
Browse files Browse the repository at this point in the history
…tnikvm into feat/merge-upstream
  • Loading branch information
mrLSD committed Sep 21, 2023
2 parents 7d0a7f6 + c6c23ac commit 9125fbd
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions runtime/src/eval/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,20 @@ pub fn returndatacopy<H: Handler>(runtime: &mut Runtime) -> Control<H> {
pop_u256!(runtime, data_offset);
pop_usize!(runtime, len);

// If `len` is zero then nothing happens, regardless of the
// value of the other parameters. In particular, `memory_offset`
// might be larger than `usize::MAX`, hence why we check this first.
if len == 0 {
return Control::Continue;
}

// SAFETY: this cast is safe because if `len > 0` then gas cost of memory
// would have already been taken into account at this point. It is impossible
// to have a memory offset greater than `usize::MAX` for any gas limit less
// than `u64::MAX` (and gas limits higher than this are disallowed in general).
let memory_offset = memory_offset.as_usize();
// If `len` is zero then nothing happens to the memory, regardless
// of the value of `memory_offset`. In particular, the value taken
// from the stack might be larger than `usize::MAX`, hence why the
// `as_usize` cast is not always safe. But because the value does
// not matter when `len == 0` we can safely set it equal to zero instead.
let memory_offset = if len == 0 {
0
} else {
// SAFETY: this cast is safe because if `len > 0` then gas cost of memory
// would have already been taken into account at this point. It is impossible
// to have a memory offset greater than `usize::MAX` for any gas limit less
// than `u64::MAX` (and gas limits higher than this are disallowed in general).
memory_offset.as_usize()
};

try_or_fail!(runtime
.machine
Expand Down

0 comments on commit 9125fbd

Please sign in to comment.