I would like to search the code (binary grep) of all deployed contracts. The goal is to search for vulnerabilities and other research.
How can I do this with geth, Parity or the like? And is this feasible, like will it take years to do a search?
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.Sign up to join this community
You can query contract bytecode in this public BigQuery dataset https://medium.com/@medvedev1088/more-blockchain-analysis-on-bigquery-92a863137f01
It's not possible via JSON RPC or web3 API. Scanning the Patricia trie wouldn't work either because the addresses are hashed there.
To list all contracts you'd need to do:
0x0- these are contract-creating transactions
CREATEopcodes - opcode for creating a contact
For each address collected above then
eth_getCodeor the corresponding web3 API to get the bytecode.
An alternative is to try to scrape contract code from Etherscan. I've scraped some using this Scrapy script https://github.com/medvedev1088/ethereum-scraper
About 7k contracts with bytecode and Solidity code can be found here http://ipfs.io/ipfs/QmU7pxFykAwemy8vGcAp78pUnHuye4gjjCiBsDsqV1raeF https://drive.google.com/open?id=1YWMUhXd97OEC24gyG_kKvo6xfwZ3K8xB