Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to run mythril in a python script #1429

Closed
Mikerah opened this issue Oct 1, 2020 · 7 comments
Closed

Error when trying to run mythril in a python script #1429

Mikerah opened this issue Oct 1, 2020 · 7 comments

Comments

@Mikerah
Copy link

Mikerah commented Oct 1, 2020

Description

When attempting to get a list of all the detection modules in a python script, I get

TypeError: '<' not supported between instances of 'int' and 'NoneType'

due to the fact that support/model.py at line 28, timeout is of type None in my code.

How to Reproduce

Input:

from mythril.mythril import MythrilAnalyzer, MythrilDisassembler
from mythril.analysis.module import ModuleLoader
from mythril.ethereum.interface.rpc.client import EthJsonRpc

modules = [type(m).__name__ for m in ModuleLoader()._modules]
eth = EthJsonRpc("mainnet.infura.io/v3/{some_infura_id}", None, True)

disassembler = MythrilDisassembler(eth=eth)
disassembler.load_from_address(some_contract_addr)
analyzer = MythrilAnalyzer(
    strategy="bfs",
    disassembler=disassembler,
    address=some_contract_addr)

report = analyzer.fire_lasers(modules=modules, transaction_count=10)
print(report.as_text())

Output:

Traceback (most recent call last):
  File "contract_analyzer.py", line 30, in <module>
    address=addr)
NameError: name 'addr' is not defined
(beacon_env) [mikerah@localhost beacon_project]$ vi contract_analyzer.py
(beacon_env) [mikerah@localhost beacon_project]$ python3 contract_analyzer.py
Laser plugin with name dependency-pruner was already loaded, skipping...
Exception occurred, aborting analysis. Please report this issue to the Mythril GitHub page.
Traceback (most recent call last):
  File "/home/mikerah/Documents/Projects/beacon_project/beacon_env/lib/python3.8/site-packages/mythril/mythril/mythril_analyzer.py", line 147, in fire_lasers
    sym = SymExecWrapper(
  File "/home/mikerah/Documents/Projects/beacon_project/beacon_env/lib/python3.8/site-packages/mythril/analysis/symbolic.py", line 215, in __init__
    self.laser.sym_exec(world_state=world_state, target_address=address.value)
  File "/home/mikerah/Documents/Projects/beacon_project/beacon_env/lib/python3.8/site-packages/mythril/laser/ethereum/svm.py", line 155, in sym_exec
    self._execute_transactions(symbol_factory.BitVecVal(target_address, 256))
  File "/home/mikerah/Documents/Projects/beacon_project/beacon_env/lib/python3.8/site-packages/mythril/laser/ethereum/svm.py", line 201, in _execute_transactions
    self.open_states = [
  File "/home/mikerah/Documents/Projects/beacon_project/beacon_env/lib/python3.8/site-packages/mythril/laser/ethereum/svm.py", line 202, in <listcomp>
    state for state in self.open_states if state.constraints.is_possible
  File "/home/mikerah/Documents/Projects/beacon_project/beacon_env/lib/python3.8/site-packages/mythril/laser/ethereum/state/constraints.py", line 32, in is_possible
    get_model(tuple(self[:]))
  File "/home/mikerah/Documents/Projects/beacon_project/beacon_env/lib/python3.8/site-packages/mythril/support/model.py", line 28, in get_model
    timeout = min(timeout, time_handler.time_remaining() - 500)
TypeError: '<' not supported between instances of 'int' and 'NoneType'

Expected behavior

I expect to see a string version of a report for the given smart contract located at the address some_contract_addr in which all the detection modules were run on that smart contract.

Environment

Mythril version: 0.22.9
Solidity compiler and version: solc version 0.6.7+commit.b8d736ae.Linux.g++
Python version: 3.8.5
OS and Version: Fedora 32

@norhh
Copy link
Collaborator

norhh commented Oct 4, 2020

You should also initialise execution timeout in MythrilAnalyzer()

@Mikerah
Copy link
Author

Mikerah commented Oct 4, 2020

Ahh. I see. So, the default for the execution timeout in MythrilAnalyzer() isn't an int but a NoneType. I'll try that and see if this fixes it.

@Mikerah
Copy link
Author

Mikerah commented Oct 4, 2020

So, I tried adding the execution_timeout argument to the MythrilAnalyzer object but it still fails. I think it might have to do with the fact that timeout in model.py is being set to args.solver_timeout. But looking at where args.solver_timeout is set, it is being set to an integer.

@norhh
Copy link
Collaborator

norhh commented Oct 5, 2020

@Mikerah Yes, I think you should also add the solver timeout.

@Mikerah
Copy link
Author

Mikerah commented Oct 5, 2020

But args.solver_timeout is already set in https://github.com/ConsenSys/mythril/blob/develop/mythril/support/support_args.py#L8. So, I shouldn't have to set it myself.

@norhh
Copy link
Collaborator

norhh commented Oct 5, 2020

@Mikerah It gets reset by MythrilAnalyzer which might set it to None when nothing is mentioned.

@Mikerah
Copy link
Author

Mikerah commented Oct 5, 2020

Thank you very much. The code snippet is working.

@Mikerah Mikerah closed this as completed Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants