Skip to main content

Security analysis tool for Ethereum smart contracts

Project description

Mythril is a security analysis tool for Ethereum smart contracts. It uses concolic analysis to detect various types of issues. Use it to analyze source code or as a nmap-style black-box blockchain scanner (an “ethermap” if you will).

Installation and setup

Install from Pypi:

$ pip install mythril

Or, clone the GitHub repo to install the newest master branch:

$ git clone https://github.com/b-mueller/mythril/
$ cd mythril
$ python setup.py install

Note that Mythril requires Python 3.5 to work.

Function signatures

Whenever you disassemble or analyze binary code, Mythril will try to resolve function names using its local signature database. The database must be provided at ~/.mythril/signatures.json. You can start out with the default file as follows:

$ cd ~/.mythril
$ wget https://raw.githubusercontent.com/b-mueller/mythril/master/signatures.json

When you analyze Solidity code, new function signatures are added to the database automatically.

Security analysis

Run myth -x with one of the input options described below to run the analysis. This will run the Python modules in the /analysis/modules directory.

Mythril detects a range of security issues, including integer underflows, owner-overwrite-to-Ether-withdrawal, and others. However, the analysis will not detect business logic issues and is not equivalent to formal verification.

Analyzing Solidity code

In order to work with Solidity source code files, the solc command line compiler needs to be installed and in path. You can then provide the source file(s) as positional arguments, e.g.:

$ myth -x myContract.sol

Alternatively, compile the code on Remix and pass the runtime binary code to Mythril:

$ myth -x -c "0x5060(...)"

If you have multiple interdependent contracts, pass them to Mythril as separate input files. Mythril will map the first contract to address “0x0000(..)”, the second one to “0x1111(…)”, and so forth (make sure that contract addresses are set accordingly in the source). The contract passed in the first argument will be executed as the “main” contract.

$ myth -x myContract.sol myLibrary.sol

Working with on-chain contracts

To analyze contracts on the blockchain you need an Ethereum node. By default, Mythril will query a local node via RPC. Alternatively, you can use INFURA:

$ myth --infura-mainnet -x -a 0x5c436ff914c458983414019195e0f4ecbef9e6dd

If you are planning to do batch operations or use the contract search features, running a go-ethereum node is recommended. Start your local node as follows:

$ geth --rpc --rpcapi eth,debug --syncmode fast

Specify the target contract with the -a option:

$ myth -x -a 0x5c436ff914c458983414019195e0f4ecbef9e6dd -v1

Adding the -l flag will cause Mythril to automatically retrieve dependencies, such as library contracts:

$  myth -x -a 0xEbFD99838cb0c132016B9E117563CB41f2B02264 -l -v1

Control flow graph

The -g FILENAME option generates an interactive jsViz graph:

$ myth -g ./graph.html -a 0xEbFD99838cb0c132016B9E117563CB41f2B02264 -l
Call graph

callgraph

[STRIKEOUT:The “bounce” effect, while awesome (and thus enabled by default), sometimes messes up the graph layout.] Try adding the --enable-physics flag for a very entertaining “bounce” effect that unfortunately completely destroys usability.

Blockchain exploration

Mythril allows to search geth contract database directly as well as perform other operations targetting local geth database instead of exposed RPC/IPC API. This enables operations like those described in the legendary “Mitch Brenner” blog post in [STRIKEOUT:seconds] minutes instead of days.

You may also use geth database directly for fetching contracts instead of using IPC/RPC APIs by specifying --leveldb flag. This is useful because search will return hashed addresses which will not be accepted by IPC/RPC APIs.

By default database operations will target default geth data directory on your system. You may edit the generated configuration at ~/.mythril/config.ini or you may supply --leveldb-dir <PATH> parameter in command line.

Searching from the command line

The search feature allows you to find contract instances that contain specific function calls and opcode sequences. It supports simple boolean expressions, such as:

$ myth --search "func#changeMultisig(address)#"
$ myth --search "code#PUSH1 0x50,POP#" --search-all
$ myth --search "func#changeMultisig(address)# and code#PUSH1 0x50#"
$ myth -s "code#PUSH#" --leveldb-dir /Volumes/MyPassport/Ether/Rinkeby/geth/chaindata

Reading contract storage

You can read the contents of storage slots from a deployed contract as follows.

./myth --storage 0 -a "0x76799f77587738bfeef09452df215b63d2cfb08a"
0x0000000000000000000000000000000000000000000000000000000000000003

Utilities

Disassembler

Use the -d flag to disassemble code. The disassembler accepts a bytecode string or a contract address as its input.

$ myth -d -c "0x6060"
0 PUSH1 0x60

Specifying an address via -a ADDRESS will download the contract code from your node.

$ myth -d -a "0x2a0c0dbecc7e4d658f48e01e3fa353f44050c208"
0 PUSH1 0x60
2 PUSH1 0x40
4 MSTORE
(...)
1135 - FUNCTION safeAdd(uint256,uint256) -
1136 CALLVALUE
1137 ISZERO

Finding cross-references

It is often useful to find other contracts referenced by a particular contract. E.g.:

$ myth --search "code#DELEGATECALL#"
Matched contract with code hash 07459966443977122e639cbf7804c446
Address: 0x76799f77587738bfeef09452df215b63d2cfb08a, balance: 1000000000000000
$ myth --xrefs -a 0x76799f77587738bfeef09452df215b63d2cfb08a
5b9e8728e316bbeb692d22daaab74f6cbf2c4691

Calculating function hashes

To print the Keccak hash for a given function signature:

$ myth --hash "setOwner(address)"
0x13af4035

Credit

  • JSON RPC library is adapted from ethjsonrpc (it doesn’t seem to be maintained anymore, and I needed to make some changes to it).
  • The signature data in signatures.json was initially obtained from the Ethereum Function Signature Database.

Project details


Release history Release notifications

This version
History Node

0.18.9

History Node

0.18.8

History Node

0.18.6

History Node

0.18.5

History Node

0.18.4

History Node

0.18.3

History Node

0.18.2

History Node

0.18.1

History Node

0.18.0

History Node

0.17.15

History Node

0.17.14

History Node

0.17.13

History Node

0.17.12

History Node

0.17.9

History Node

0.17.8

History Node

0.17.7

History Node

0.17.6

History Node

0.17.5

History Node

0.17.4

History Node

0.17.3

History Node

0.17.1

History Node

0.17.0

History Node

0.16.31

History Node

0.16.30

History Node

0.16.27

History Node

0.16.26

History Node

0.16.25

History Node

0.16.23

History Node

0.16.21

History Node

0.16.18

History Node

0.16.6

History Node

0.16.4

History Node

0.16.3

History Node

0.16.2

History Node

0.16.1

History Node

0.16.0

History Node

0.15.9

History Node

0.15.8

History Node

0.15.7

History Node

0.15.6

History Node

0.15.5

History Node

0.15.4

History Node

0.15.3

History Node

0.15.2

History Node

0.15.1

History Node

0.15.0

History Node

0.14.9

History Node

0.14.8

History Node

0.14.7

History Node

0.14.6

History Node

0.14.5

History Node

0.14.4

History Node

0.14.3

History Node

0.14.2

History Node

0.14.1

History Node

0.14.0

History Node

0.13.21

History Node

0.13.20

History Node

0.13.19

History Node

0.13.18

History Node

0.13.17

History Node

0.13.16

History Node

0.13.15

History Node

0.13.14

History Node

0.13.13

History Node

0.13.12

History Node

0.13.11

History Node

0.13.10

History Node

0.13.9

History Node

0.13.8

History Node

0.13.7

History Node

0.13.6

History Node

0.13.5

History Node

0.13.4

History Node

0.13.3

History Node

0.13.2

History Node

0.13.1

History Node

0.13.0

History Node

0.12.6

History Node

0.12.5

History Node

0.12.4

History Node

0.12.3

History Node

0.12.2

History Node

0.12.1

History Node

0.12.0

History Node

0.11.3

History Node

0.11.2

History Node

0.11.1

History Node

0.11.0

History Node

0.10.14

History Node

0.10.13

History Node

0.10.12

History Node

0.10.11

History Node

0.10.10

History Node

0.10.9

History Node

0.10.8

History Node

0.10.7

History Node

0.10.6

History Node

0.10.5

History Node

0.10.4

History Node

0.10.3

History Node

0.10.2

History Node

0.10.1

History Node

0.10.0

History Node

0.9.2

History Node

0.9.1

History Node

0.9.0

History Node

0.8.27

History Node

0.8.26

History Node

0.8.25

History Node

0.8.24

History Node

0.8.23

History Node

0.8.22

History Node

0.8.21

History Node

0.8.20

History Node

0.8.19

History Node

0.8.18

History Node

0.8.17

History Node

0.8.16

History Node

0.8.15

History Node

0.8.14

History Node

0.8.13

History Node

0.8.12

History Node

0.8.11

History Node

0.8.10

History Node

0.8.9

History Node

0.8.8

History Node

0.8.7

History Node

0.8.6

History Node

0.8.5

History Node

0.8.4

History Node

0.8.3

History Node

0.8.2

History Node

0.8.1

History Node

0.8.0

History Node

0.7.10

History Node

0.7.9

History Node

0.7.8

History Node

0.7.7

History Node

0.7.6

History Node

0.7.5

History Node

0.7.4

History Node

0.7.3

History Node

0.7.2

History Node

0.7.1

History Node

0.7.0

History Node

0.6.17

History Node

0.6.3

History Node

0.6.2

History Node

0.6.1

History Node

0.6.0

History Node

0.5.10

History Node

0.5.9

History Node

0.5.7

History Node

0.5.6

History Node

0.5.5

History Node

0.5.4

History Node

0.5.3

History Node

0.5.2

History Node

0.5.1

History Node

0.5.0

History Node

0.4.4

History Node

0.4.3

History Node

0.4.2

History Node

0.4.1

History Node

0.3.15

History Node

0.3.14

History Node

0.3.13

History Node

0.3.12

History Node

0.3.11

History Node

0.3.10

History Node

0.3.9

History Node

0.3.8

History Node

0.3.7

History Node

0.3.6

History Node

0.3.5

History Node

0.3.4

History Node

0.3.3

History Node

0.3.2

History Node

0.3.1

History Node

0.3.0

History Node

0.2.11

History Node

0.2.10

History Node

0.2.9

History Node

0.2.8

History Node

0.2.7

History Node

0.2.6

History Node

0.2.5

History Node

0.2.4

History Node

0.2.3

History Node

0.2.2

History Node

0.2.1

History Node

0.2.0

History Node

0.1.6

History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
mythril-0.18.9.tar.gz (58.5 kB) Copy SHA256 hash SHA256 Source None Jul 19, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page