Skip to content

[Ethereum] Manticore API and EVM implementation disagree on type of code field #1370

@Joool

Description

@Joool

OS / Environment

macOS 10.14.2

Manticore version

Version: 0.2.4

Python version

Python 3.7.1

Summary of the problem

When creating a new account using the Manticore API as shown below, the API and the actual EVM implementation disagree on the type of the code field.

I have identified three problems/behaviours so far:

  1. When creating an account using supplying simply a str argument, the manticore api tries to convert it into a bytearray (manticore/ethereum/manticore.py line 770):
        if isinstance(code, str):
            code = bytearray(code)
        if code is not None and not isinstance(code, (bytearray, Array)):
            raise EthereumError("code bad type")

However this call fails since we do not supply an encoding:

TypeError: string argument without an encoding

  1. When supplying a bytearray as asked, the api tries to create the account in the underlying evm implementation, which however expects a bytes type (manticore/platforms/evm.py line 2388):
        if code is None:
            code = bytes()
        else:
            if not isinstance(code, (bytes, Array)):
                raise EthereumError('Wrong code type')
  1. When supplying a bytes type, we fail the check for a bytearray in the manticore API.

Step to reproduce the behavior

Any of the uncommented lines produces an error:

from manticore.ethereum import ManticoreEVM
m = ManticoreEVM()

# test_account = m.create_account(code="0x00AAFF")
# test_account = m.create_account(code=bytearray("0x00AAFF", "utf-8"))
# test_account = m.create_account(code=bytes("0x00AAFF", "utf-8"))

Expected behavior

Account created in the environment

Actual behavior

See above

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions