The Pot.sol
contract is vulnerable to failing transfers due to the unchecked return values of ERC20 token transfers in Pot::closePot
and Pot:_transferReward
. Specifically, the functions does not verify whether the token transfers to the manager and claimants are successful. This oversight can be exploited by using a custom ERC20 token that always returns true for transfers without actually transferring any tokens, thereby preventing the manager or claimers from receiving their cut.
Affected code - https://github.com/Cyfrin/2024-08-MyCut/blob/946231db0fe717039429a11706717be568d03b54/src/Pot.sol#L55-L66
The vulnerability is located in the closePot
and _transferReward
function, where the return value of the transfer function is not checked:
The function attempts to transfer a portion of the remaining rewards to the manager. However, if the token used does not actually perform the transfer but still returns true, the manager will not receive their cut. This can be exploited by deploying a custom ERC20 token that simulates this behavior, effectively blocking the manager's transfer or claimants to receive their rewards.
The primary impact of this vulnerability is that it allows an attacker to prevent the manager from receiving their cut of the rewards or for claimants to receive their rewards. This could lead to financial losses for the manager and undermine the intended functionality of the contract.
Attacker creates an exploit token
Attacker initiates a pot
Owner tries to close down pot
Exploit token contains this transfer
function
Manual Review
Always check the return value of ERC20 transfer
and transferFrom
functions. Revert the transaction if the transfer fails:
Or use SafeERC20 which automatically handles return value checks and reverts on failure:
By implementing these recommendations, you can mitigate the risk of transfer failures and ensure secure and reliable token transfers in your contract.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.