Beginner FriendlyFoundryDeFiOracle
100 EXP
View results
Submission Details
Severity: low
Invalid

Comparison Order issue in the `updateExchangeRate` function

Summary

In the updateExchangeRate function of the AssetToken contract, there's a comparison that checks if newExchangeRate is less than or equal to s_exchangeRate. This comparison allows updates where the new rate is equal to the old rate, which may not align with the intended behavior. To ensure that updates only result in an increase in the exchange rate, it is recommended to change the comparison to if (newExchangeRate < s_exchangeRate).

Vulnerability Details

In the provided code, the updateExchangeRate function checks if newExchangeRate is less than or equal to the current s_exchangeRate. The intention here seems to be to allow updates that increase the rate. However, the current comparison allows updates where the new rate is equal to the old rate, which may not be the desired behavior.

function updateExchangeRate(uint256 fee) external onlyThunderLoan {
uint256 newExchangeRate = s_exchangeRate * (totalSupply() + fee) / totalSupply();
// Vulnerable: Allows an update if newExchangeRate is equal to s_exchangeRate
if (newExchangeRate <= s_exchangeRate) {
revert AssetToken__ExhangeRateCanOnlyIncrease(s_exchangeRate, newExchangeRate);
}
s_exchangeRate = newExchangeRate;
emit ExchangeRateUpdated(s_exchangeRate);
}

if newExchangeRate is equal to s_exchangeRate, the condition is met, which may not align with the intended security requirements.

Impact

Allowing updates that result in the exchange rate being the same as the previous rate can be exploited by attackers to manipulate the rate without a real increase, potentially leading to financial losses or instability.

Tools Used

No specific tools were used for this analysis.

Recommendations

To ensure that updates to the exchange rate only occur when there is a real increase, the comparison should be adjusted as follows:
updates will only be allowed when the new rate is greater than the old rate, providing the intended security and preventing rate manipulation without a real increase

if (newExchangeRate < s_exchangeRate) {
revert AssetToken__ExhangeRateCanOnlyIncrease(s_exchangeRate, newExchangeRate);
}
Updates

Lead Judging Commences

0xnevi Lead Judge
over 1 year ago
0xnevi Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Other

Support

FAQs

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