7

EIP-712 talks about function signatures being bytes4. I understand that the new version of the ABI format will contain a pre-defined set of keccak256 hashes of function names, as per the work done on clef, but it's not clear to me what their role is, in details.

What if there's a function not defined in that list? Will developers need to retrofit it for their apps?

Paul Razvan Berg
  • 17,902
  • 6
  • 73
  • 143

1 Answers1

4

The function signature (which is a 4 bytes code) is used internally in solidity to call the function. However for a user interface to show the user some readable information it is useful to lookup the function name, which can be done via https://www.4byte.directory.
Clef integrates the entire 4bytes database to provide the same information.

Developers can add new functions via https://www.4byte.directory/import-solidity
Clef also has the option: --4bytedb-custom value to add new functions


Suppose you have function:

function setA(uint256 _a) { a = _a; }

Then the function signature is calculated with:

keccak("setA(uint256)")

Using https://emn178.github.io/online-tools/keccak_256.html, this calculates to: ee919d50445cd9f463621849366a537968fe1ce096894b0d0c001528383d4769

Taking the first 8 characters (=4 bytes), this results in (hex): 0xee919d50.
This is stored in a 4 byte-database, as can be seen here:

https://www.4byte.directory/signatures/?bytes4_signature=0xee919d50
ID      Text Signature  Bytes Signature
90738   setA(uint256)   0xee919d50

Also see:

Gerard Persoon
  • 326
  • 1
  • 6