1

I was reading the github version of the upcoming book Mastering Ethereum, where the author defines the function selector as The first 4 bytes of the Keccak256 hash of the function’s prototype. This allows the contract to unambiguously identify which function you wish to invoke. So, my question is, in case the first 4 bytes of two functions, and their argument(s) number/type in the same contract are same (I know, the chance is pretty small), then what is the behavior of the function invocation? Does it throw any error or it randomly picks up a function matching the hash and executes that?

1 Answer 1

2

The compiler will throw Error: Function signature hash collision.

pragma solidity ^0.4.24;

contract Test {

  function withdraw(uint256) public {

  }

  function OwnerTransferV7b711143(uint256) public {

  }

}

(functions sourced from reddit)

0

Your Answer

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

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