I just saw something like this:
function sub(
uint a,
uint b
)
internal
pure
returns (uint)
{
require(b <= a, "SUB_UNDERFLOW");
return a - b;
}
function withdraw(uint amount) public {
msg.sender.call.value(amount).gas(gasleft())("");
balance[msg.sender]=balance[msg.sender].sub(amount);
}
Is there a possible reentrancy attack here, or does balance[msg.sender] is reloaded after the call making the subtraction based on the value after the call?
Can compiler optimizations affect the behavior through caching on the stack in order to have a single SLOAD operation in terms of gas cost?