High: All contract tokens transfered to Owner when burning any amount
Description
When burnFaucetTokens is called with any amount the _transfer function sends all tokens from the contract to the owner
function burnFaucetTokens(uint256 amountToBurn) public onlyOwner {
require(amountToBurn <= balanceOf(address(this)), "Faucet Token Balance: Insufficient");
_transfer(address(this), msg.sender, balanceOf(address(this))); <@ All tokens are transfered to Owner
_burn(msg.sender, amountToBurn); <@ Burning only the amount supposed to be burned
}
Risk
Likelihood: High
Impact: High
Proof of Concept
Scenario:
Owner burns whatevet amount, for the purpose of the test - 1 token.
Result: The token is burned, but all the tokens from the contract are now in the Owner.
function testBurnFaucetTokens() public {
uint256 amountToBurn = 1e18;
assertEq(raiseBoxFaucet.getFaucetTotalSupply(), INITIAL_SUPPLY_MINTED);
vm.prank(owner);
raiseBoxFaucet.burnFaucetTokens(amountToBurn);
assertEq(raiseBoxFaucet.getFaucetTotalSupply(), 0);
assertEq(raiseBoxFaucet.getBalance(owner),INITIAL_SUPPLY_MINTED - amountToBurn);
}
Recommended Mitigation
Replace the balanceOf(address(this) in the _transfer call with amountToBurn
function burnFaucetTokens(uint256 amountToBurn) public onlyOwner {
require(amountToBurn <= balanceOf(address(this)), "Faucet Token Balance: Insufficient");
// transfer faucet balance to owner first before burning
// ensures owner has a balance before _burn (owner only function) can be called successfully
- _transfer(address(this), msg.sender, balanceOf(address(this)));
+ _transfer(address(this), msg.sender, amountToBurn);
_burn(msg.sender, amountToBurn);
}