Skip to content

Commit 778fbde

Browse files
committed
readability: factor out loc + size
1 parent 86b7eae commit 778fbde

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/halmos/sevm.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -483,12 +483,11 @@ def mslice(self, loc: int, size: int) -> ByteVec:
483483
if not size:
484484
return ByteVec()
485485

486-
if loc + size > MAX_MEMORY_SIZE:
487-
raise OutOfGasError(
488-
f"memory access with {loc=} {size=} exceeds MAX_MEMORY_SIZE"
489-
)
486+
stop = loc + size
487+
if stop > MAX_MEMORY_SIZE:
488+
raise OutOfGasError(f"memory read {loc=} {size=} > MAX_MEMORY_SIZE")
490489

491-
return self.memory.slice(start=loc, stop=loc + size)
490+
return self.memory.slice(start=loc, stop=stop)
492491

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

500-
if loc + size > MAX_MEMORY_SIZE:
501-
raise OutOfGasError(
502-
f"memory write with {loc=} {size=} exceeds MAX_MEMORY_SIZE"
503-
)
499+
stop = loc + size
500+
if stop > MAX_MEMORY_SIZE:
501+
raise OutOfGasError(f"memory write {loc=} {size=} > MAX_MEMORY_SIZE")
504502

505-
self.memory.set_slice(start=loc, stop=loc + size, value=data)
503+
self.memory.set_slice(start=loc, stop=stop, value=data)
506504

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

0 commit comments

Comments
 (0)