Skip to content

Commit

Permalink
avoid copying returndata when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
0xkarmacoma committed Jan 16, 2025
1 parent 778fbde commit 48424ca
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/halmos/sevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2172,10 +2172,17 @@ def callback(new_ex: Exec, stack, step_id):
new_ex.jumpis = deepcopy(ex.jumpis)

# copy return data to memory
effective_ret_size = min(ret_size, new_ex.returndatasize())
actual_ret_size = new_ex.returndatasize()
effective_ret_size = min(ret_size, actual_ret_size)
if effective_ret_size > 0:
returndata_slice = subcall.output.data.slice(0, effective_ret_size)
new_ex.st.set_mslice(ret_loc, returndata_slice)
# fast path: if the requested ret size is the actual size of the return data,
# we can skip the slice (copy) operation and directly write the return data to memory
ret_data = (
subcall.output.data.slice(0, effective_ret_size)
if effective_ret_size < actual_ret_size
else subcall.output.data
)
new_ex.st.set_mslice(ret_loc, ret_data)

# set status code on the stack
subcall_success = subcall.output.error is None
Expand Down

0 comments on commit 48424ca

Please sign in to comment.