|
|
|
@ -2,7 +2,7 @@ |
|
|
|
|
from copy import copy |
|
|
|
|
from random import randint |
|
|
|
|
from typing import Dict, List, Iterator, Optional, TYPE_CHECKING |
|
|
|
|
|
|
|
|
|
from ethereum.utils import mk_contract_address |
|
|
|
|
from mythril.laser.ethereum.state.account import Account |
|
|
|
|
from mythril.laser.ethereum.state.annotation import StateAnnotation |
|
|
|
|
|
|
|
|
@ -50,7 +50,12 @@ class WorldState: |
|
|
|
|
return new_world_state |
|
|
|
|
|
|
|
|
|
def create_account( |
|
|
|
|
self, balance=0, address=None, concrete_storage=False, dynamic_loader=None |
|
|
|
|
self, |
|
|
|
|
balance=0, |
|
|
|
|
address=None, |
|
|
|
|
concrete_storage=False, |
|
|
|
|
dynamic_loader=None, |
|
|
|
|
creator=None, |
|
|
|
|
) -> Account: |
|
|
|
|
"""Create non-contract account. |
|
|
|
|
|
|
|
|
@ -60,7 +65,7 @@ class WorldState: |
|
|
|
|
:param dynamic_loader: used for dynamically loading storage from the block chain |
|
|
|
|
:return: The new account |
|
|
|
|
""" |
|
|
|
|
address = address if address else self._generate_new_address() |
|
|
|
|
address = address if address else self._generate_new_address(creator) |
|
|
|
|
new_account = Account( |
|
|
|
|
address, |
|
|
|
|
balance=balance, |
|
|
|
@ -111,11 +116,14 @@ class WorldState: |
|
|
|
|
""" |
|
|
|
|
return filter(lambda x: isinstance(x, annotation_type), self.annotations) |
|
|
|
|
|
|
|
|
|
def _generate_new_address(self) -> str: |
|
|
|
|
def _generate_new_address(self, creator=None) -> str: |
|
|
|
|
"""Generates a new address for the global state. |
|
|
|
|
|
|
|
|
|
:return: |
|
|
|
|
""" |
|
|
|
|
if creator: |
|
|
|
|
# TODO: Use nounce |
|
|
|
|
return "0x" + str(mk_contract_address(creator, 0).hex()) |
|
|
|
|
while True: |
|
|
|
|
address = "0x" + "".join([str(hex(randint(0, 16)))[-1] for _ in range(40)]) |
|
|
|
|
if address not in self.accounts.keys(): |
|
|
|
|