0

Suppose I have a function with arguments (address _to, uint256 number) The function selector is found using

let signature = "name(address,uint256)";
let selector = Keccack256(signature) ;

I want to find a name for my function that will generate a specific selector say for example, 0x19284901. How would I do this ?

1 Answer 1

0

You cannot retro engineer the byte selectors, those are made from the keccack256 hashing as you shown it.

Though, you can use 4 bytes selectors database that are free to use, here is the example of one: https://www.4byte.directory/docs/

If you cannot find the selector that you need, you can brute force (creating a random function name, until getting the correct function selector)

4
  • How would you do that
    – qubitz
    Jun 21 at 19:56
  • The function selector that you need is not in the db ?
    – Franfran
    Jun 21 at 20:18
  • No I really need to generate an arbitrary function selector from the arguements
    – qubitz
    Jun 21 at 20:29
  • So you can run a loop until you find the correct 4 bytes selector. For this, just alter the function name until that the condition is met, e.g. ``` let selector while selector !== "0x19284901" { const random_name = some_random_name(); const full_name = random_name + "(address,uint256)"; const selector = keccak256(full_name); } print(selector); ``` Please note that it's pseudo-code, for you to understand easily.
    – Franfran
    Jun 22 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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