First Flight #21: KittyFi

First Flight #21
Beginner FriendlyDeFiFoundry
100 EXP
View results
Submission Details
Severity: low
Invalid

Missing checks in `KittyCoin` lead to unexpected errors and reverts

Summary

These functions are called by users when they want to mint and burn their KittyCoin. The stablecoin of the KittyFi protocol is pegged to EUR and can be minted by supplying collateral and minting via KittyPool. However, some checks are missing leading to potentially compromising the functionality and security smart contract.

Vulnerability Details

  1. In the KittyCoin::burn function without the Check for the burn amount exceeding the balance, it could lead to unexpected errors and reverts deeper in the call stack, which is harder to debug and handle.

function burn(address _from, uint256 _amount) external onlyKittyPool {
_burn(_from, _amount);
}
modifier userDepositsCollateral() {
// Deposit the collateral
uint256 depositAmount = 5 ether;
vm.startPrank(user);
IERC20(weth).approve(address(wethVault), depositAmount);
kittyPool.depawsitMeowllateral(weth, depositAmount);
vm.stopPrank();
_;
}
function test_UserBurnAmountExceedsBalance() public userDepositsCollateral {
uint256 depositAmount = 5 ether;
uint256 amountToMint = 20e18;
uint256 amountToBurn = 30e18;
address user2 = makeAddr("user2");
deal(weth, user2, AMOUNT);
vm.startPrank(user);
kittyPool.meowintKittyCoin(amountToMint);
assertEq(kittyPool.getKittyCoinMeownted(user), amountToMint);
vm.stopPrank();
vm.startPrank(user2);
// Deposit the collateral
IERC20(weth).approve(address(wethVault), depositAmount);
kittyPool.depawsitMeowllateral(weth, depositAmount);
assertEq(wethVault.getUserMeowllateral(user2), depositAmount);
// mint the kittyCoin
kittyPool.meowintKittyCoin(amountToMint);
assertEq(kittyPool.getKittyCoinMeownted(user2), amountToMint);
vm.stopPrank();
// After someTime user want to burn some kittyCoin
vm.startPrank(user);
kittyPool.burnKittyCoin(user2, amountToBurn);
vm.stopPrank();
}

Result:

[FAIL. Reason: panic: arithmetic underflow or overflow (0x11)]
  1. In the KittyCoin::mint function allowing operations with _amount = 0 wastes gas and clutters the blockchain with unnecessary transactions.

function mint(address _to, uint256 _amount) external onlyKittyPool {
_mint(_to, _amount);
}

Tools Used

Manually
foundry

Recommendations

To ensure robust and secure smart contract development, it is essential to include thorough checks for input validation. This not only prevents potential security vulnerabilities but also improves the overall reliability and user experience of the contract.

Updates

Lead Judging Commences

shikhar229169 Lead Judge 11 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.