23

I need to find out the public contract code i.e. solidity code for a contract address.

For eample, here it has a tab for contract code but it's in assembly and byte code only, which is not useful.

I need to find out method signatures so that I can form topics.

0

1 Answer 1

25

Mainly due to optimizations carried out when the source code is compiled it's not feasible to get the source code from the bytecode/opcode itself. Refer this question.

Compilation back to the original source code is impossible because all variable names, type names and even function names are removed. It might be technically possible to arrive at some source code that is similar to the original source code but that is very complicated, especially when the optimizer was used during compilation. I don't know of any tools that do more than converting bytecode to opcodes

So if the contract code is closed-source then it's not possible to find the source code. But if the contract is public there might be chance of finding the source code. You may refer this question.

There is no general solution for this because the solidity code is not published on the blockchain. On the blockchain only the resulting byte code is published. There are different block explorers like ether.camp that offer the option to upload the solidity code. They can use the solidity code to verify that it indeed matches with the byte code on the address.

There is one project that aims to do this automatically by scraping github repositories for source code that fits to published byte code

AFAIK, there is no obligation to publish the contract source code. It's upto the user to have it verified before using. So if a smart contract developer wants the attraction of the most people, it's upto him to reveal the code so the other can trust it. Given the solidity code and it's address, then anyone can verify the deployed contract using this method.

2
  • 1
    isn't there a consensus to publish it on github for auditing?
    – garg10may
    Commented Sep 18, 2017 at 15:00
  • 2
    Actually, now a "contract" is just some coded logic. I think that in the beginning, the meaning was more limited to the normal meaning of "contract" - i.e. an agreement between two parties, which implies that both parties have seen what the agreement is and signed on. In the current sense of coded logic, a "contract" is not really a contract if the developer has not revealed the source code. If only one party knows about the contents, it is not a contract, in the real sense of the word. Commented Feb 9, 2018 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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