Skip to content

Commit

Permalink
Implement Storage.__copy__.
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Jun 12, 2020
1 parent 7a38281 commit 3446e21
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 7 additions & 4 deletions manticore/platforms/evm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1954,10 +1954,13 @@ def SSTORE_gas(self, offset, value):
self.fail_if(Operators.ULT(self.gas, SSSTORESENTRYGAS))

# Get the storage from the snapshot took before this call
original_value = 0
try:
original_value = self.world._callstack[-1][-2].get(offset, 0)
except AttributeError:
original_value = 0
storage = self.world._callstack[-1][-2]
if storage is not None:
original_value = storage.get(offset, 0)
except IndexError:
pass

current_value = self.world.get_storage_data(storage_address, offset)

Expand Down Expand Up @@ -2634,7 +2637,7 @@ def _open_transaction(self, sort, address, price, bytecode_or_data, caller, valu
vm = self._make_vm_for_tx(tx)

self._callstack.append(
(tx, self.logs, self.deleted_accounts, copy.copy(self.get_storage(address)), vm,)
(tx, self.logs, self.deleted_accounts, copy.copy(self.get_storage(address)), vm)
)
self.forward_events_from(vm)
self._publish("did_open_transaction", tx)
Expand Down
6 changes: 6 additions & 0 deletions manticore/platforms/evm_world_state.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import copy
from abc import abstractmethod
from eth_typing import ChecksumAddress, URI
from io import TextIOBase
Expand Down Expand Up @@ -33,6 +34,11 @@ def __init__(self, constraints: ConstraintSet, address: int):
# default=0,
)

def __copy__(self):
other = Storage.__new__(Storage)
other._data = copy.copy(self._data)
return other

def __getitem__(self, offset: Union[int, BitVec]) -> Union[int, BitVec]:
return self.get(offset, 0)

Expand Down

0 comments on commit 3446e21

Please sign in to comment.