From 0136b4a1f9bdfcd008485751c39882e460f196f4 Mon Sep 17 00:00:00 2001 From: Nikhil Parasaram Date: Sun, 21 Nov 2021 03:08:35 +0000 Subject: [PATCH] Fix case where loader is not present (#1558) --- mythril/laser/ethereum/state/world_state.py | 12 +++++++----- mythril/support/loader.py | 8 ++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/mythril/laser/ethereum/state/world_state.py b/mythril/laser/ethereum/state/world_state.py index 6e6692e84..2c9c76508 100644 --- a/mythril/laser/ethereum/state/world_state.py +++ b/mythril/laser/ethereum/state/world_state.py @@ -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 @@ -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( diff --git a/mythril/support/loader.py b/mythril/support/loader.py index 4715dba27..8ea16ca93 100644 --- a/mythril/support/loader.py +++ b/mythril/support/loader.py @@ -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) @@ -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)