Skip to content

Commit

Permalink
readability: factor out loc + size
Browse files Browse the repository at this point in the history
  • Loading branch information
0xkarmacoma committed Jan 16, 2025
1 parent 86b7eae commit 778fbde
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/halmos/sevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,11 @@ def mslice(self, loc: int, size: int) -> ByteVec:
if not size:
return ByteVec()

if loc + size > MAX_MEMORY_SIZE:
raise OutOfGasError(
f"memory access with {loc=} {size=} exceeds MAX_MEMORY_SIZE"
)
stop = loc + size
if stop > MAX_MEMORY_SIZE:
raise OutOfGasError(f"memory read {loc=} {size=} > MAX_MEMORY_SIZE")

return self.memory.slice(start=loc, stop=loc + size)
return self.memory.slice(start=loc, stop=stop)

def set_mslice(self, loc: int, data: ByteVec) -> None:
"""Wraps a memory slice write with a size check."""
Expand All @@ -497,12 +496,11 @@ def set_mslice(self, loc: int, data: ByteVec) -> None:
if not size:
return

if loc + size > MAX_MEMORY_SIZE:
raise OutOfGasError(
f"memory write with {loc=} {size=} exceeds MAX_MEMORY_SIZE"
)
stop = loc + size
if stop > MAX_MEMORY_SIZE:
raise OutOfGasError(f"memory write {loc=} {size=} > MAX_MEMORY_SIZE")

self.memory.set_slice(start=loc, stop=loc + size, value=data)
self.memory.set_slice(start=loc, stop=stop, value=data)

def ret(self, subst: dict = None) -> ByteVec:
loc: int = self.mloc(subst)
Expand Down

0 comments on commit 778fbde

Please sign in to comment.