diff --git a/boa/contracts/vyper/decoder_utils.py b/boa/contracts/vyper/decoder_utils.py index 9102dd95..bbe03031 100644 --- a/boa/contracts/vyper/decoder_utils.py +++ b/boa/contracts/vyper/decoder_utils.py @@ -22,7 +22,7 @@ class ByteAddressableStorage: def __init__(self, evm, address: Address, key: int): self.evm = evm - self.address = address.canonical_address + self.address = address self.key = key def __getitem__(self, subscript): diff --git a/boa/environment.py b/boa/environment.py index 90657e9a..ede96e63 100644 --- a/boa/environment.py +++ b/boa/environment.py @@ -151,8 +151,12 @@ def reset_gas_used(self): # to the snapshot on exiting the with statement @contextlib.contextmanager def anchor(self): - with self.evm.anchor(): - yield + snapshot_id = self.evm.snapshot() + try: + with self.evm.patch.anchor(): + yield + finally: + self.evm.revert(snapshot_id) @contextlib.contextmanager def sender(self, address): @@ -312,11 +316,11 @@ def get_code(self, address): @property def block_number(self): - return self.evm.block_number + return self.evm.patch.block_number @property def timestamp(self): - return self.evm.timestamp + return self.evm.patch.timestamp # function to time travel def time_travel( @@ -332,4 +336,6 @@ def time_travel( else: assert blocks is not None # mypy hint seconds = blocks * block_delta - self.evm.time_travel(seconds, blocks) + + self.evm.patch.timestamp += seconds + self.evm.patch.block_number += blocks diff --git a/boa/network.py b/boa/network.py index d528d339..4efaa33c 100644 --- a/boa/network.py +++ b/boa/network.py @@ -133,7 +133,7 @@ def anchor(self): if not self._rpc_has_snapshot: raise RuntimeError("RPC does not have `evm_snapshot` capability!") try: - block_id = self.evm.block_id + block_id = self.evm.patch.block_id snapshot_id = self._rpc.fetch("evm_snapshot", []) yield # note we cannot call super.anchor() because vm/accountdb fork diff --git a/boa/vm/py_evm.py b/boa/vm/py_evm.py index 0ae15a7a..dc961b69 100644 --- a/boa/vm/py_evm.py +++ b/boa/vm/py_evm.py @@ -364,7 +364,7 @@ def _init_vm(self, account_db_class=AccountDB): self.vm = self.chain.get_vm() self.vm.__class__._state_class.account_db_class = account_db_class - self.vm.patch = VMPatcher(self.vm) + self.patch = VMPatcher(self.vm) c: Type[titanoboa_computation] = type( "TitanoboaComputation", @@ -392,8 +392,8 @@ def fork_rpc(self, rpc: RPC, block_identifier: str, **kwargs): self._init_vm(account_db_class) block_info = self.vm.state._account_db._block_info - self.vm.patch.timestamp = int(block_info["timestamp"], 16) - self.vm.patch.block_number = int(block_info["number"], 16) + self.patch.timestamp = int(block_info["timestamp"], 16) + self.patch.block_number = int(block_info["number"], 16) # TODO patch the other stuff self.vm.state._account_db._rpc._init_mem_db() @@ -430,15 +430,6 @@ def reset_access_counters(self): def snapshot(self) -> Any: return self.vm.state.snapshot() - @contextlib.contextmanager - def anchor(self): - snapshot_id = self.snapshot() - try: - with self.vm.patch.anchor(): - yield - finally: - self.revert(snapshot_id) - def revert(self, snapshot_id: Any) -> None: self.vm.state.revert(snapshot_id) @@ -516,26 +507,10 @@ def execute_code( tx_ctx = BaseTransactionContext(origin=origin, gas_price=gas_price) return self.vm.state.computation_class.apply_message(self.vm.state, msg, tx_ctx) - @property - def block_id(self): - return self.vm.state._account_db._block_id - - @property - def block_number(self): - return self.vm.state.block_number - - @property - def timestamp(self): - return self.vm.state.timestamp - def get_storage_slot(self, address: Address, slot: int) -> bytes: data = self.vm.state._account_db.get_storage(address.canonical_address, slot) return data.to_bytes(32, "big") - def time_travel(self, add_seconds: int, add_blocks: int): - self.vm.patch.timestamp += add_seconds - self.vm.patch.block_number += add_blocks - GENESIS_PARAMS = {"difficulty": constants.GENESIS_DIFFICULTY, "gas_limit": int(1e8)}