From 0daa07bd3c93491c103613904295370e69137ac2 Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Sun, 1 Mar 2020 20:55:04 +0800 Subject: [PATCH] Black --- mythril/analysis/symbolic.py | 1 + mythril/ethereum/interface/rpc/client.py | 7 +------ mythril/interfaces/cli.py | 4 +--- mythril/laser/ethereum/state/account.py | 10 +++++++++- mythril/support/loader.py | 16 ++++++++++++++++ 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/mythril/analysis/symbolic.py b/mythril/analysis/symbolic.py index e06ac817..a71bff54 100644 --- a/mythril/analysis/symbolic.py +++ b/mythril/analysis/symbolic.py @@ -176,6 +176,7 @@ class SymExecWrapper: contract.disassembly, dynamic_loader=dynloader, contract_name=contract.name, + balances=world_state.balances, concrete_storage=True if (dynloader is not None and dynloader.storage_loading) else False, diff --git a/mythril/ethereum/interface/rpc/client.py b/mythril/ethereum/interface/rpc/client.py index b7ace33a..28f81704 100644 --- a/mythril/ethereum/interface/rpc/client.py +++ b/mythril/ethereum/interface/rpc/client.py @@ -52,12 +52,7 @@ class EthJsonRpc(BaseClient): :return: """ params = params or [] - data = { - "jsonrpc": "2.0", - "method": method, - "params": params, - "id": _id, - } + data = {"jsonrpc": "2.0", "method": method, "params": params, "id": _id} scheme = "http" if self.tls: scheme += "s" diff --git a/mythril/interfaces/cli.py b/mythril/interfaces/cli.py index 763332a3..6a061824 100644 --- a/mythril/interfaces/cli.py +++ b/mythril/interfaces/cli.py @@ -387,9 +387,7 @@ def create_analyzer_parser(analyzer_parser: ArgumentParser): action="store_true", help="analyze a truffle project (run from project dir)", ) - commands.add_argument( - "--infura-id", help="set infura id for onchain analysis", - ) + commands.add_argument("--infura-id", help="set infura id for onchain analysis") options = analyzer_parser.add_argument_group("options") options.add_argument( diff --git a/mythril/laser/ethereum/state/account.py b/mythril/laser/ethereum/state/account.py index f602fde2..05539591 100644 --- a/mythril/laser/ethereum/state/account.py +++ b/mythril/laser/ethereum/state/account.py @@ -112,10 +112,12 @@ class Account: concrete_storage, address=self.address, dynamic_loader=dynamic_loader ) + formatted_address = "{0:#0{1}x}".format(self.address.value, 42); + # Metadata if contract_name is None: self.contract_name = ( - "{0:#0{1}x}".format(self.address.value, 40) + formatted_address if not self.address.symbolic else "unknown" ) @@ -127,6 +129,12 @@ class Account: self._balances = balances self.balance = lambda: self._balances[self.address] + if not self.address.symbolic and dynamic_loader is not None: + _balance = dynamic_loader.read_balance(formatted_address) + self.set_balance( + _balance + ) + def __str__(self) -> str: return str(self.as_dict) diff --git a/mythril/support/loader.py b/mythril/support/loader.py index 2da25d7b..72e01075 100644 --- a/mythril/support/loader.py +++ b/mythril/support/loader.py @@ -47,6 +47,22 @@ class DynLoader: contract_address, position=index, block="latest" ) + @functools.lru_cache(LRU_CACHE_SIZE) + def read_balance(self, address: str) -> str: + """ + + :param address: + :return: + """ + if not self.storage_loading: + raise ValueError( + "Cannot load from the storage when the storage_loading flag is false" + ) + if not self.eth: + raise ValueError("Cannot load from the storage when eth is None") + + return self.eth.eth_getBalance(address) + @functools.lru_cache(LRU_CACHE_SIZE) def dynld(self, dependency_address: str) -> Optional[Disassembly]: """