Skip to content

Commit

Permalink
Fix case where loader is not present (#1558)
Browse files Browse the repository at this point in the history
  • Loading branch information
norhh authored Nov 21, 2021
1 parent b64892b commit 0136b4a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 7 additions & 5 deletions mythril/laser/ethereum/state/world_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from mythril.support.loader import DynLoader
from mythril.laser.smt import symbol_factory, Array, BitVec
from mythril.disassembler.disassembly import Disassembly
from mythril.laser.ethereum.state.account import Account
from mythril.laser.ethereum.state.annotation import StateAnnotation
from mythril.laser.ethereum.state.constraints import Constraints
Expand Down Expand Up @@ -105,14 +106,15 @@ def accounts_exist_or_load(self, addr, dynamic_loader: DynLoader) -> Account:
dynamic_loader=dynamic_loader,
code=dynamic_loader.dynld(addr),
)
except:
except ValueError:
# Initial balance will be a symbolic variable
pass

try:
code = dynamic_loader.dynld(addr)
except ValueError:
code = Disassembly("0x")
return self.create_account(
address=addr_bitvec.value,
dynamic_loader=dynamic_loader,
code=dynamic_loader.dynld(addr),
address=addr_bitvec.value, dynamic_loader=dynamic_loader, code=code,
)

def create_account(
Expand Down
8 changes: 6 additions & 2 deletions mythril/support/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def read_balance(self, address: str) -> str:
if not self.active:
raise ValueError("Cannot load from storage when the loader is disabled")
if not self.eth:
raise ValueError("Cannot load from the chain when eth is None")
raise ValueError(
"Cannot load from the chain when eth is None, please use rpc, or specify infura-id"
)

return self.eth.eth_getBalance(address)

Expand All @@ -67,7 +69,9 @@ def dynld(self, dependency_address: str) -> Optional[Disassembly]:
if not self.active:
raise ValueError("Loader is disabled")
if not self.eth:
raise ValueError("Cannot load from the chain when eth is None")
raise ValueError(
"Cannot load from the chain when eth is None, please use rpc, or specify infura-id"
)

log.debug("Dynld at contract %s", dependency_address)

Expand Down

0 comments on commit 0136b4a

Please sign in to comment.