First Flight #21: KittyFi

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

The `latestRoundData()` function might return stale or incorrect results

Summary

The KittyVault contract relies on Chainlink’s latestRoundData() for price information in its getUserVaultMeowllateralInEuros and getTotalMeowllateralInAave functions. However, the current implementation does not include checks to verify the freshness and validity of the price data returned by Chainlink. This can lead to issues if the price feed provides stale or incorrect data, potentially affecting the contract’s behavior and financial operations.

Vulnerability Details

In the KittyVault contract, the following issues are present:

  1. Negative Value Casting: Chainlink’s latestRoundData() returns an answer that could be negative. When this value is cast to uint256, it will convert to an unexpectedly large number. There is no validation to handle such cases properly.

  2. Stale Data: There are no checks to ensure that the price data retrieved from Chainlink is up-to-date. This could lead to using outdated prices which might impact the contract’s functionality.

Impact

  • Incorrect Pricing: Using stale or incorrect price data can lead to miscalculations in collateral valuations and financial operations, potentially resulting in incorrect liquidation or reward distributions.

  • Data Integrity Issues: Without proper checks, negative values improperly cast to uint256 can lead to erroneous computations and unintended behavior.

Tools Used

Manual Code Review

Recommendations

Add Stale Data Checks: Implement checks to ensure that the price data is fresh and valid. For example:

(uint80 roundID, int256 answer, , uint256 timestamp, uint80 answeredInRound) = i_priceFeed.latestRoundData();
require(answer > 0, "Chainlink price <= 0");
require(answeredInRound >= roundID, "Stale price");
require(timestamp != 0, "Round not complete");

This ensures that:

  • The price (answer) is positive.

  • The round data is not stale by comparing answeredInRound with roundID.

  • The round is complete by checking if timestamp is non-zero.

Updates

Lead Judging Commences

shikhar229169 Lead Judge 10 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Stale Price from Chainlink Datafeed

Support

FAQs

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