First Flight #21: KittyFi

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

Reentrancy

Summary

  • Functions like depawsitMeowllateral, whiskdrawMeowllateral, and purrgeBadPawsition interact with external contracts (vaults). Ensure that these interactions are safe from reentrancy attacks, especially if they call external contracts that could re-enter the KittyPool contract.

Vulnerability Details

Reentrancy is a vulnerability where an attacker repeatedly calls a function before the previous execution is complete, potentially draining funds or causing inconsistent states.

Impact

  1. Fund Drain: Attackers can repeatedly withdraw funds, draining the contract.

  2. State Inconsistency: Reentrant calls can lead to incorrect balances or states.

  3. Security Breach: Compromises the integrity and security of the contract.

Reentrancy attacks can have severe financial and operational impacts on smart contracts. Implementing reentrancy guards and best practices is essential for security.

Tools Used

  • Audit Wizard

  • Reading the code

Recommendations

  • Reentrancy Guards: Use nonReentrant modifier from OpenZeppelin's ReentrancyGuard to prevent reentrancy attacks.

  • Checks-Effects-Interactions Pattern: Update state variables before making external calls.

Example using nonReentrant.

Reasoning for the meowint function:

  • State Update: The function updates the kittyCoinMeownted mapping.

  • External Call: The function calls the mint method on the KittyCoin contract.

  • Reentrancy Risk: Without nonReentrant, an attacker could exploit the external call to re-enter the function and manipulate state updates.

// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
contract KittyPool is ReentrancyGuard {
function depawsitMeowllateral(address _token, uint256 _ameownt) external tokenExists(_token) nonReentrant {
IKittyVault(tokenToVault[_token]).executeDepawsit(msg.sender, _ameownt);
}
function whiskdrawMeowllateral(address _token, uint256 _ameownt) external tokenExists(_token) nonReentrant {
IKittyVault(tokenToVault[_token]).executeWhiskdrawal(msg.sender, _ameownt);
require(_hasEnoughMeowllateral(msg.sender), KittyPool__NotEnoughMeowllateralPurrrr());
}
function meowintKittyCoin(uint256 _ameownt) external nonReentrant {
kittyCoinMeownted[msg.sender] += _ameownt;
i_kittyCoin.mint(msg.sender, _ameownt);
require(_hasEnoughMeowllateral(msg.sender), KittyPool__NotEnoughMeowllateralPurrrr());
}
}

Risk Assessment

Medium to High Risk: Given the critical nature of minting a stablecoin and the involvement of external contract calls, the function is susceptible to reentrancy attacks. An attacker could potentially exploit this to mint more KittyCoin than they are entitled to or bypass collateral checks.

Updates

Lead Judging Commences

shikhar229169 Lead Judge 11 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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