0

This is the below code

 cast sig "workMyDirefulOwner(uint256,uint256)"                                      
  0xa9059cbb                                                                                                    
 cast sig "transfer(address,uint256)"                 
  0xa9059cbb

2 Answers 2

0

The function signature is just the beginning of a hash of the function name and its parameters - as you can see.

If you perform the hashing manually, the actual hash is a lot longer. The hashes would then not be the same. But Ethereum uses only the first 8 characters of the full hash. That means that (hash) collisions are a lot more probable. This is also why your two function signatures result in the same signature hash.

0

Function signatures are deterministically calculated in the context of Solidity contracts. They are nothing but a keccak256 hash of the function name along with the parameter types.

For ex, if you function is transfer(address _recipient, uint256 amount), the signature would be keccak256 of transfer(address,uint256) which would result in the following hash:

a9059cbb2ab09eb219583f4a59a5d0623ade346d962bcd4e46b11da047c9049b

Whereas, during run time the EVM uses function selectors to invoke a function call to a specific method. Function selectors are first 4 bytes (0xa9059cbb from the above example) of the function signature. So the can be function selectors can collide, but function signatures can never be the same for 2 functions.

Some useful resources:

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.