3

I understand what a function selector is and how it is computed:

The first four bytes of the call data for a function call specifies the function to be called. It is the first (left, high-order in big-endian) four bytes of the Keccak-256 (SHA-3) hash of the signature of the function.

However, I fail to see why knowing the selector is important as far as calling the function is concerned. For a loadable dynamic library (.so on Linux, .dll on Windows), a list of callable symbols are imported which serves as the entry points to external clients. Isn't there anything like that in EVM bytecode? If not, how does the EVM locate the method given the function selector? Don't the functions exist as separate entities in the compiled bytecode?

2
  • 1
    Welcome to the Ethereum Stack Exchange! Functions do not exist as separate entities in the compiled EVM bytecode. This may be a duplicate of some other ABI related questions, please check them out, and if not duplicate, feel free to reopen or edit. Thanks
    – eth
    Oct 14, 2019 at 10:43
  • tldr: functions names aren't stored in compiled evm bytecode. a solidity compilter turns your function "signature" (function name, plug argument types in order) into a selector (by hashing that signature and taking the first four bytes), and treats that signature as the function name within the bytecode. So, to call that function, you have to have the selector, because the selector is all that is stored on the blockchain.
    – Kyle Baker
    Feb 14, 2022 at 11:07

0