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