Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Separate pyevm implementation from environment #134

Merged
merged 20 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
81258f8
Refactor environment to separate it from pyevm
DanielSchiavini Feb 7, 2024
e9d07ff
Merge branch 'master' of github.com:vyperlang/titanoboa into 104/refa…
DanielSchiavini Feb 8, 2024
f108216
Merge branch 'master' of github.com:vyperlang/titanoboa into 104/refa…
DanielSchiavini Feb 12, 2024
b03d08b
Merge branch 'master' of github.com:vyperlang/titanoboa into 104/refa…
DanielSchiavini Feb 14, 2024
4e83b11
Merge branch 'master' of github.com:vyperlang/titanoboa into 104/refa…
DanielSchiavini Feb 14, 2024
f232387
Merge branch 'master' of github.com:vyperlang/titanoboa into 104/refa…
DanielSchiavini Feb 14, 2024
3e9ac33
Merge branch 'master' of github.com:vyperlang/titanoboa into 104/refa…
DanielSchiavini Mar 7, 2024
1654693
Merge branch 'master' of github.com:vyperlang/titanoboa into 104/refa…
DanielSchiavini Mar 25, 2024
02e2aba
Make mypy happy
DanielSchiavini Mar 25, 2024
cd91753
Merge branch 'master' of github.com:vyperlang/titanoboa into 104/refa…
DanielSchiavini Apr 8, 2024
00d1b72
Merge branch 'master' of github.com:vyperlang/titanoboa into 104/refa…
DanielSchiavini Apr 15, 2024
59a78dd
Review comments, get rid of env.evm calls
DanielSchiavini Apr 15, 2024
ba65161
Move fork variables to py-evm
DanielSchiavini Apr 15, 2024
913840e
Self-review
DanielSchiavini Apr 15, 2024
a6b85c5
Review comments
DanielSchiavini Apr 17, 2024
eb13e77
Lost comment
DanielSchiavini Apr 17, 2024
fc91c8c
Pass canonical address
DanielSchiavini Apr 17, 2024
49c769a
Review comment
DanielSchiavini Apr 17, 2024
d50f0bc
Elevate patch to evm instead of vm
DanielSchiavini Apr 17, 2024
d4794f3
Unused properties
DanielSchiavini Apr 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion boa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from boa.contracts.base_evm_contract import BoaError
from boa.contracts.vyper.vyper_contract import check_boa_error_matches
from boa.debugger import BoaDebug
from boa.environment import Env, enable_pyevm_verbose_logging, patch_opcode
from boa.environment import Env
from boa.interpret import (
from_etherscan,
load,
Expand All @@ -17,6 +17,7 @@
from boa.network import NetworkEnv
from boa.precompile import precompile
from boa.test.strategies import fuzz
from boa.vm.py_evm import enable_pyevm_verbose_logging, patch_opcode

# turn off tracebacks if we are in repl
# https://stackoverflow.com/a/64523765
Expand Down
2 changes: 1 addition & 1 deletion boa/contracts/abi/abi_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def __init__(
self._abi = abi
self._functions = functions

self._bytecode = self.env.vm.state.get_code(address.canonical_address)
self._bytecode = self.env.get_code(address)
if not self._bytecode:
warn(
f"Requested {self} but there is no bytecode at that address!",
Expand Down
7 changes: 4 additions & 3 deletions boa/contracts/vyper/decoder_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
)
from vyper.utils import unsigned_to_signed

from boa.util.abi import Address
from boa.vm.utils import ceil32, floor32


# wrap storage in something which looks like memory
class ByteAddressableStorage:
charles-cooper marked this conversation as resolved.
Show resolved Hide resolved
def __init__(self, db, address, key):
self.db = db
def __init__(self, evm, address: Address, key: int):
self.evm = evm
self.address = address
self.key = key

Expand All @@ -31,7 +32,7 @@ def __getitem__(self, subscript):
stop = subscript.stop
i = self.key + start // 32
while i < self.key + ceil32(stop) // 32:
ret += self.db.get_storage(self.address, i).to_bytes(32, "big")
ret += self.evm.get_storage_slot(self.address, i)
i += 1

start_ofst = floor32(start)
Expand Down
10 changes: 4 additions & 6 deletions boa/contracts/vyper/vyper_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ def at(self, address: Any) -> "VyperContract":
address = Address(address)

ret = self.deploy(override_address=address, skip_initcode=True)
vm = ret.env.vm
bytecode = vm.state.get_code(address.canonical_address)
bytecode = ret.env.get_code(address)

ret._set_bytecode(bytecode)

Expand Down Expand Up @@ -366,8 +365,7 @@ def setpath(lens, path, val):
class StorageVar:
def __init__(self, contract, slot, typ):
self.contract = contract
self.addr = self.contract._address.canonical_address
self.accountdb = contract.env.vm.state._account_db
self.addr = self.contract._address
self.slot = slot
self.typ = typ

Expand All @@ -376,7 +374,7 @@ def _decode(self, slot, typ, truncate_limit=None):
if truncate_limit is not None and n > truncate_limit:
return None # indicate failure to caller

fakemem = ByteAddressableStorage(self.accountdb, self.addr, slot)
fakemem = ByteAddressableStorage(self.contract.env.evm, self.addr, slot)
return decode_vyper_object(fakemem, typ)

def _dealias(self, maybe_address):
Expand Down Expand Up @@ -709,7 +707,7 @@ def marshal_to_python(self, computation, vyper_typ):
self.handle_error(computation)

# cache gas used for call if profiling is enabled
gas_meter = self.env.vm.state.computation_class._gas_meter_class
gas_meter = self.env.get_gas_meter_class()
if gas_meter == ProfilingGasMeter:
cache_gas_used_for_computation(self, computation)

Expand Down
Loading
Loading