I was building a withdrawal function for a contract that was using msg.sender.call{value: balance}
, after checking that the given msg.sender
was registered in the contract and had the given balance; however, I then read a couple of threads
msg.sender 'spoofing' when function is public or external
that made me wonder whether this is safe. The answers to both of those questions indicate that msg.sender
will only be validated for on-chain transactions — but how do I know if a given function will result in an on-chain transaction?
My understanding (see, e.g., the response here) was that no withdrawal functions are executed on-chain. So then how do we authorize users trying to withdraw from a contract?
Here is the relevant portion of my withdrawal function:
function withdraw() public {
Person storage personData = _people[msg.sender];
require(personData.personAddress == msg.sender, "Not a person in hash map");
uint256 balance = personData.balance;
personData.balance = 0;
(bool success, ) = msg.sender.call{value: balance}("");
require(success, "Withdrawal failed");
}