This repository has been archived by the owner on Nov 26, 2023. It is now read-only.
Diana - Approve function is subject to front-run attack #376
Labels
Non-Reward
This issue will not receive a payout
Diana
medium
Approve function is subject to front-run attack
Summary
Approve function in FootiumEscrow is subject to front-run attack because the approve method overwrites the current allowance regardless of whether the spender already used it or not. In case the spender spent the amount, the approve function will approve a new amount.
Vulnerability Detail
The approve method overwrites the current allowance regardless of whether the spender has already used it or not. It allows the spender to front-run and spend the amount before the new allowance is set.
Scenario:
erc20Contract.approve
method, passing Bob's address and N as the method argumentserc20Contract.approve
method again, this time passing Bob's address and M as the method argumentserc20Contract.transfer
method to transfer N Alice's tokens somewhereerc20Contract.transfer
method again, this time to transfer M Alice's tokens.Impact
The user whose address is passed as the
to
parameter inerc20Contract.approve(to, amount)
while callingsetApprovalForERC20
can abuse this by monitoring the mem-pool and spend more amount of tokens than allowed.Code Snippet
https://github.com/sherlock-audit/2023-04-footium/blob/main/footium-eth-shareable/contracts/FootiumEscrow.sol#L80
Tool used
Manual Review
Recommendation
Use
increaseAllowance
anddecreaseAllowance
instead of approve as OpenZeppelin ERC20 implementation. Please see the details here:https://forum.openzeppelin.com/t/explain-the-practical-use-of-increaseallowance-and-decreaseallowance-functions-on-erc20/15103/4
Duplicate of #8
The text was updated successfully, but these errors were encountered: