I was looking at the implementation of transferFrom
in ERC20.sol. I noticed that the _transfer
function is called before allowance check: require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
. Shouldn’t we check the allowance before calling the _transfer function. How does the execution order work?
_transfer(sender, recipient, amount);
uint256 currentAllowance = _allowances[sender][_msgSender()];
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
_approve(sender, _msgSender(), currentAllowance - amount);
return true;
}