8

Compilation back to the original source code from just the bytecode is impossible because all variable names, type names and even function names are removed. (source)

It's possible to call functions on a contract by using a bytes4 hash of that functions name, so that means that the contract stores that hash of the name.

If a de-compiler had access to the ABI, could it reverse a contract, or parts of a contract, to Solidity?

3to
  • 401
  • 3
  • 9

1 Answers1

3

The ABI gives you a list of all members functions and events in the contract (parameter types, parameter names, return types, etc.).

You can revert these members, but this is useless, as you already have all their details in the ABI.

You won't be able to revert the implementation of these members, however.

Nicolas Massart
  • 6,783
  • 2
  • 29
  • 63
  • Is it theoretically possible to revert the implementation from bytecode + ABI? This post mentions that "Machine code can be disassembled to assembly language. And through pattern recognition machine code could be compiled back to some programming language. "

    And http://ilspy.net seems to do decompile from assembly to human-level language, http://community.sharpdevelop.net/blogs/danielgrunwald/archive/2011/04/26/ilspy-decompiler-architecture-overview.aspx

    – 3to Feb 02 '17 at 05:42
  • http://filipekberg.se/2013/02/14/decompiling-dotnet-applications – 3to Feb 02 '17 at 06:25
  • lack of variable names seems like main problem for a decompiler, http://ethereum.stackexchange.com/questions/4077/is-there-a-solidity-decompiler

    if ABIs are stored to be easily fetched over swarm using ENS https://www.reddit.com/r/ethereum/comments/50zej1/small_thought_contracts_serving_up_their_own_abi/ then variable names would also be easy to look up for a decompiler

    – 3to Feb 02 '17 at 06:40