Challenge Overview
Mythril has an exploration feature for searching and analyzing smart contracts on the Ethereum blockchain:
https://github.com/ConsenSys/mythril#blockchain-exploration
To enable this feature, Mythril builds its own smart contract database. The contract data is received from an Ethereum node over IPC or RPC (--sync-db command). This is however slow and inefficient. A much better way would be to directly access the LevelDB database of a locally installed go-ethereum node.
In this challenge, your task is to add a local geth leveldb interface to Mythril. This should be accomplished by writing a Python class capable of doing the following:
$ myth -d/-x/-g -a [address] # disassemble / analyze / create CFG of contract at address
[address]
$ myth —search # search all smart contracts for opcode and function patterns
$ myth --storage 0,1 # read account storage contents
https://github.com/ethereum/goethereum/blob/55599ee95d4151a2502465e0afc7c47bd1acba77/core/state/database.g
o
Article about the Trie:
https://easythereentropy.wordpress.com/2014/06/04/understanding-the-ethereum-trie/
Related issue on the Mytrhil Github repo:
https://github.com/ConsenSys/mythril/issues/15
A few stack overflow posts (unfortunately not very helpful):
https://ethereum.stackexchange.com/questions/1635/how-to-parse-blocks-withpython
https://ethereum.stackexchange.com/questions/5999/format-of-leveldb-files-in-nodesdirectory-trouble-pulling-contents-with-python
https://github.com/ConsenSys/mythril#blockchain-exploration
To enable this feature, Mythril builds its own smart contract database. The contract data is received from an Ethereum node over IPC or RPC (--sync-db command). This is however slow and inefficient. A much better way would be to directly access the LevelDB database of a locally installed go-ethereum node.
In this challenge, your task is to add a local geth leveldb interface to Mythril. This should be accomplished by writing a Python class capable of doing the following:
- Obtain the runtime bytecode and balance of a contract account by address;
- Access the storage of any account by address;
- Iterate through all existing contract accounts;
- Iterate through a subset of contract accounts, such as those with non-zero balance.
$ myth -d/-x/-g -a [address] # disassemble / analyze / create CFG of contract at address
[address]
$ myth —search # search all smart contracts for opcode and function patterns
$ myth --storage 0,1 # read account storage contents
Notes:
States in the leveldb are represented as a Merkle patricia tree (the “trie"). The goethereum implementation can be found here:https://github.com/ethereum/goethereum/blob/55599ee95d4151a2502465e0afc7c47bd1acba77/core/state/database.g
o
Article about the Trie:
https://easythereentropy.wordpress.com/2014/06/04/understanding-the-ethereum-trie/
Related issue on the Mytrhil Github repo:
https://github.com/ConsenSys/mythril/issues/15
A few stack overflow posts (unfortunately not very helpful):
https://ethereum.stackexchange.com/questions/1635/how-to-parse-blocks-withpython
https://ethereum.stackexchange.com/questions/5999/format-of-leveldb-files-in-nodesdirectory-trouble-pulling-contents-with-python