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
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)