1

If I deploy a smart contract (for private use) on the Ethereum blockchain, can other people see the names of the functions it contains? Assuming the abi.json file is not published.

If not, how does calling a specific external function work? How is the function distinguished from other functions in the same contract?

If yes, does the name length impacts the gas price?

1
  • name length does not impact the gas price, but if you write your contract for the LLL compiler, you are going to write a code very compact and close to assembly. This will make it very small in size and low in gas consumption. Contract functions are encoded into 4 byte strings, but you can use just 2 bits in assembly to make a call to 4 different functions – Nulik Jan 25 at 18:36
0

Every thing is accessible in blockchain once it gets deployed in the network. even data saved in your private variables can be read by other users, But they cannot call them nor modify them. If you make them public, they can call it as well.

3
  • Your answer does not address the question. -- Everything that wasn't destroyed by the compiler is visible indeed. But are function names mangled by the solidity compiler ? Are the names visible as string in the generated bytecode ? – Julien__ Jan 25 at 11:41
  • 1
    @Julien__ , no. names are not visible. Names are converted to so called 'signatures', which is a keccak hash on function name and its parameters. This standard is called the ABI. The first thing a contract does when it is called, is to check wether the input cointains the signature of the function to be executed and executes it. This is how Call()s are made – Nulik Jan 25 at 18:33
  • You can see the function names after they get called in your contract. Check out this tx hash in rinkeby ether scan and see the input data "0x2b386d42f989b826150a149fd4d6e431d9ebaa860669f12debc5d59cfecd5213" – Amin Ghasemi Jan 26 at 8:20
0

No, functions' names are not visible. Functions are identified by something called the "function selector" which is made by taking the first 4 bytes of the Keccak (SHA-3) hash of the signature of the function.

The string representation of the name is not retrievable from the function selector.

See https://docs.soliditylang.org/en/v0.4.24/abi-spec.html#function-selector

1
  • 1
    I would add the caveat that some explorers (e.g. bloxy) have a dictionary of known/frequently used signatures (e.g. execute(), withdraw(uint256), transferOwnership(address) etc.) that it knows how to recognize. – SimonR Jan 27 at 14:41

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.