[L-4] Not checking for success of transfer function in Snow::collectFee()
Description
-
The collectFee() function is calling WETH token's transfer function to transfer all fees to the collector
-
However, there are no checks to ensure that that the transfer is a success
function collectFee() external onlyCollector {
uint256 collection = i_weth.balanceOf(address(this));
@> i_weth.transfer(s_collector, collection);
(bool collected,) = payable(s_collector).call{value: address(this).balance}("");
require(collected, "Fee collection failed!!!");
}
Risk
Likelihood:
Impact:
Proof of Concept
Add the following testcase to the test suite of Snow
function test_falseTransfer() public {
TestWETH test_weth = new TestWETH();
uint256 fee = 1;
Snow newSnow = new Snow(address(test_weth), fee, collector);
vm.startPrank(collector);
newSnow.collectFee();
}
Also add the following contract to the import list. This contract is just to replicate a situation where the token transfer has failed.
pragma solidity 0.8.24;
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {Snow} from "../../src/Snow.sol";
contract TestWETH is ERC20 {
uint256 public counter;
address public immutable owner;
address public snow_addr;
constructor() ERC20("MockWETH", "mWETH") {
owner = msg.sender;
}
function transfer(address, uint256) public pure override returns (bool) {
return false;
}
}
Recommended Mitigation
Add checks to ensure that the transfer function is a success
- i_weth.transfer(s_collector, collection);
+ bool res = i_weth.transfer(s_collector, collection);
+ assert(res == true);