1

I am aware that solidity variables and functions are the first 4 bytes of the some hashed string. I want to be able to retrieve a list of these 4 byte functions/variables from a already deployed contract. I have the contract addresses, transaction hash, and can get the bytecode but I don't know what to do with it?

If I need to go learn some assembly please give me some pointers on where to start because I only know basic boolean algebra, adders, multipliers etc. etc.

2
  • 1
    If the source code is verified, import the contract in Remix and click "Compilations Details". There's a "function hashes" section there. Nov 10, 2021 at 17:01
  • @PaulRazvanBerg excellent practicle answer. A lot easier than attempting to decompile bytecode. Nov 11, 2021 at 11:30

1 Answer 1

0

The short answer is that it's not possible in the general case.

The longer answer is that you can attempt to disassemble the jump table that the contract begins with if the contracts follows the Ethereum ABI, contracts don't have to follow it to be accepted by miners, but all smart contracts in use will follow this ABI.

So you attempt to locate the jump table in the beginning of the code, and then you compare the four bytes you refer to in your question with a lookup table of known function signatures.

Then you have to start building this lookup table by scouring through contract standard definitions, like ERC20, ERC721 etc. So if you find a the four bytes a9059cbb in the lookup table, the contract most likely has a method called transfer which takes an address and a uint256 argument since keccak256("transfer(address,uint256)") = 0xa9059cbb.

Be aware that the hashed function signature is so small that it's possible to make collisions if you would want to.

For more context, see Why does compiled solidity code do this check on the argument with which it was called?

1
  • I don't think he has access to source codes of the contract.
    – ofarukcaki
    Jun 27, 2022 at 18:54

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.