Check a function selector against the contract ABI

A transaction decoder that guesses names from a four-byte database can attach the wrong function to a call. Recompute the selector using the contract’s exact ABI.

Canonicalize the function signature

For an ERC-20-style transfer, hash the UTF-8 text below using Keccak-256 and take the first four bytes. Exclude parameter names, spaces and return types. Write the canonical integer type uint256 even when the Solidity source used uint.

transfer(address,uint256) → 0xa9059cbb

Compare 0xa9059cbb with the first four bytes of transaction input. Then decode the remaining bytes using the two declared argument types. An ABI word representing an address contains the address in its low 20 bytes.

Resolve an ambiguous match

Different signatures can share four bytes. Confirm the target’s implementation and ABI at the execution block, especially for proxy addresses. A fallback can accept arbitrary calldata, so matching a selector alone cannot prove which code path ran. docs.soliditylang.org Solidity ABI