Ethereum Asked by Bob5421 on January 29, 2021
I am writing a fallback function this way:
fallback() external {
(param1, param2) = abi.decode(msg.data[4:], (uint256, uint256));
}
I know this is not a good practice but let’s suppose i call an "azerty" function on my contract with 2 uint256. And of course, azerty function does not exists. So fallback function will be called.
I have 2 questions inside this fallback function:
Thanks
It is not possible to recover the function name from the transaction alone since only 4 bytes from the function identifier are include. Those 4 bytes are also accessible through msg.sig
.
It should be possible to store a mapping in the contract so they can be recovered from the identifier: mapping (bytes4 => string) public signatures
. Store them signatures[bytes4(0x70a08231)] = "balanceOf(address)"
, using it signatures[msg.sig]
.
Recent solidity version validate a function has enough data and revert if they have less than expected.
Using fallback skips any validation but abi.decode
fails when there's not enough data to decode all of its parameters.
Answered by Ismael on January 29, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP