Skip to content

Commit

Permalink
ethereum: Improve some error messages when preconditions don't hold (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ekilmer committed Aug 1, 2022
1 parent 04cc68d commit fa640b7
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions manticore/ethereum/manticore.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,14 +727,15 @@ def create_contract(self, owner, balance=0, address=None, init=None, name=None,
if name in self._accounts:
# Account name already used
raise EthereumError("Name already used")

self._transaction("CREATE", owner, balance, address, data=init, gas=gas)
# TODO detect failure in the constructor
if self.count_ready_states():
self._accounts[name] = EVMContract(
address=address, manticore=self, default_caller=owner, name=name
)
return self.accounts[name]
else:
logger.warning("No ready states")

def _get_uniq_name(self, stem):
count = 0
Expand Down Expand Up @@ -930,24 +931,24 @@ def _transaction(self, sort, caller, value=0, address=None, data=None, gas=None,
if isinstance(data, str):
data = bytes(data)
if not isinstance(data, (bytes, Array)):
raise TypeError("code bad type")
raise TypeError(f"code bad type {type(data)}")

# Check types
if not isinstance(caller, (int, BitVec)):
raise TypeError("Caller invalid type")
raise TypeError(f"Caller invalid type {type(caller)}")

if not isinstance(value, (int, BitVec)):
raise TypeError("Value invalid type")
raise TypeError(f"Value invalid type: {type(value)}")

if not isinstance(address, (int, BitVec)):
raise TypeError("address invalid type")
raise TypeError(f"address invalid type: {type(address)}")

if not isinstance(price, int):
raise TypeError("Price invalid type")
raise TypeError(f"Price invalid type: {type(price)}")

# Check argument consistency and set defaults ...
if sort not in ("CREATE", "CALL"):
raise ValueError("unsupported transaction type")
raise ValueError(f"unsupported transaction type: {sort}")

if sort == "CREATE":
# When creating data is the init_bytecode + arguments
Expand Down

0 comments on commit fa640b7

Please sign in to comment.