2

Is it possible to distinguish a functions bytecode out of an entire contracts bytecode? For example, when I pull the bytecode from a contract address, I get something like:

0x6060604052361561003d576000357c01000000000000000000000000000000000000000000000000000000009004806347966bc21461004e5761003d565b61004c5b61004961005d565b5b565b005b61005b600480505061005d565b005b739e0b9ddba97dd4f7addab0b5f67036...

Is it a fact that a functions bytecode representation is in this output? For example, would a function be within this bytecode (shown in grey):

0x6060604052361561003d576000357c01000000000000000000000000000000000000000000000000000000009004806347966bc21461004e5761003d565b61004c5b61004961005d565b5b565b005b61005b600480505061005d565b005b739e0b9ddba97dd4f7addab0b5f67036?

1
  • 2
    Yes, but you need to know the function's name and the types of its input arguments in order to find it in the bytecode. Commented Dec 18, 2019 at 5:09

1 Answer 1

3

Compiler does not have to put function body into contract bytecode as a consequent range. Actually, optimizing compiler could decide to inline small functions used only in few places, i.e. copy their bytecode into every place the function is actually used.

However, I believe, current versions of Solidity does not do this. The body of the unction usually starts with JUMPDEST opcode (0x5b) and ends with JUMP opcode (0x56).

You may try to compile your smart contract with --asm option and review produced assembly file to find out exactly what bytecode your function was translated into.

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.