I'm pretty sure there're similar questions here, but I just couldn't find them with the correct keywords.
I found the following code in the Uniswap V2 core contracts, and I'm not sure why both functions couldn't just have been combined together under approve()
. Is it for security reasons? If it is, how does it prevent attackers from exploiting its vulnerability?
function approve(address spender, uint value) external returns (bool) {
_approve(msg.sender, spender, value); // executes the function below
return true;
}
function _approve(address owner, address spender, uint value) private {
allowance[owner][spender] = value;
emit Approval(owner, spender, value);
}