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?

  • Do you mean search in bytecode or in Solidity code? Feb 22 '18 at 19:13
  • Search all bytecode Feb 22 '18 at 21:36

You can query contract bytecode in this public BigQuery dataset https://medium.com/@medvedev1088/more-blockchain-analysis-on-bigquery-92a863137f01

Previous answer

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:

  • list all transactions where to address is 0x0 - these are contract-creating transactions
  • execute all transactions and intercept CREATE opcodes - opcode for creating a contact

For each address collected above then

  • call eth_getCode or 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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.